diff --git a/pom.xml b/pom.xml index 810d219..966bc6c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.sap.scimono scimono-parent - 0.1.3-SNAPSHOT + 0.1.5-SNAPSHOT pom SAP SCIMono Library diff --git a/scimono-client/pom.xml b/scimono-client/pom.xml index 2254ef7..20ee4ed 100644 --- a/scimono-client/pom.xml +++ b/scimono-client/pom.xml @@ -5,7 +5,7 @@ scimono-parent com.sap.scimono - 0.1.3-SNAPSHOT + 0.1.5-SNAPSHOT 4.0.0 jar diff --git a/scimono-compliance-tests/pom.xml b/scimono-compliance-tests/pom.xml index 25b811d..4971fc9 100644 --- a/scimono-compliance-tests/pom.xml +++ b/scimono-compliance-tests/pom.xml @@ -5,7 +5,7 @@ scimono-parent com.sap.scimono - 0.1.3-SNAPSHOT + 0.1.5-SNAPSHOT 4.0.0 jar diff --git a/scimono-examples/pom.xml b/scimono-examples/pom.xml index af191c1..693f549 100644 --- a/scimono-examples/pom.xml +++ b/scimono-examples/pom.xml @@ -5,7 +5,7 @@ scimono-parent com.sap.scimono - 0.1.3-SNAPSHOT + 0.1.5-SNAPSHOT 4.0.0 diff --git a/scimono-examples/simple-server/pom.xml b/scimono-examples/simple-server/pom.xml index 24ca5ad..ae4e609 100644 --- a/scimono-examples/simple-server/pom.xml +++ b/scimono-examples/simple-server/pom.xml @@ -5,7 +5,7 @@ scimono-examples com.sap.scimono.examples - 0.1.3-SNAPSHOT + 0.1.5-SNAPSHOT 4.0.0 diff --git a/scimono-server/pom.xml b/scimono-server/pom.xml index 051bb9e..345380a 100644 --- a/scimono-server/pom.xml +++ b/scimono-server/pom.xml @@ -6,7 +6,7 @@ scimono-parent com.sap.scimono - 0.1.3-SNAPSHOT + 0.1.5-SNAPSHOT scimono-server @@ -84,18 +84,22 @@ org.mockito mockito-core + test org.mockito mockito-junit-jupiter + test org.junit.jupiter junit-jupiter-engine + test org.junit.jupiter junit-jupiter-params + test @@ -108,6 +112,12 @@ jersey-test-framework-provider-external test + + junit + junit + 4.13.1 + test + diff --git a/scimono-server/src/main/java/com/sap/scimono/api/Groups.java b/scimono-server/src/main/java/com/sap/scimono/api/Groups.java index 4485215..f6bf49b 100644 --- a/scimono-server/src/main/java/com/sap/scimono/api/Groups.java +++ b/scimono-server/src/main/java/com/sap/scimono/api/Groups.java @@ -86,10 +86,11 @@ public Groups(@Context Application appContext, @Context UriInfo uriInfo) { // @formatter:off public Response getGroup(@PathParam("id") final String groupId, @QueryParam(ATTRIBUTES_PARAM) final String attributes, + @QueryParam(FILTER_PARAM) final String filter, @QueryParam(EXCLUDED_ATTRIBUTES_PARAM) final String excludedAttributes) { // @formatter:on logger.trace("Reading group {}", groupId); - Group groupFromDb = groupAPI.getGroup(groupId, RequestedResourceAttributesParser.parse(attributes, excludedAttributes)); + Group groupFromDb = groupAPI.getGroup(groupId, RequestedResourceAttributesParser.parse(attributes, excludedAttributes), filter); if (groupFromDb == null) { throw new ResourceNotFoundException(RESOURCE_TYPE_GROUP, groupId); diff --git a/scimono-server/src/main/java/com/sap/scimono/api/Users.java b/scimono-server/src/main/java/com/sap/scimono/api/Users.java index edad0ec..8bb669b 100644 --- a/scimono-server/src/main/java/com/sap/scimono/api/Users.java +++ b/scimono-server/src/main/java/com/sap/scimono/api/Users.java @@ -118,11 +118,12 @@ public Response getMe(@Context final SecurityContext sec) { @Path("{id}") // @formatter:off public Response getUser(@PathParam("id") final String userId, + @QueryParam(FILTER_PARAM) final String filter, @QueryParam(ATTRIBUTES_PARAM) final String attributes, @QueryParam(EXCLUDED_ATTRIBUTES_PARAM) final String excludedAttributes) { // @formatter:on logger.trace("Reading user {}", userId); - User userFromDb = usersAPI.getUser(userId, RequestedResourceAttributesParser.parse(attributes, excludedAttributes)); + User userFromDb = usersAPI.getUser(userId, RequestedResourceAttributesParser.parse(attributes, excludedAttributes), filter); if (userFromDb == null) { throw new ResourceNotFoundException(RESOURCE_TYPE_USER, userId); diff --git a/scimono-server/src/main/java/com/sap/scimono/callback/groups/GroupsCallback.java b/scimono-server/src/main/java/com/sap/scimono/callback/groups/GroupsCallback.java index f6ced2d..9a9672f 100644 --- a/scimono-server/src/main/java/com/sap/scimono/callback/groups/GroupsCallback.java +++ b/scimono-server/src/main/java/com/sap/scimono/callback/groups/GroupsCallback.java @@ -16,15 +16,30 @@ public interface GroupsCallback { /** - * @param groupId, unique group id + * @param groupId unique group id of the requested group * @return the group with the specified groupId or null if no such group exists */ Group getGroup(final String groupId); + /** + * @param groupId unique group id of the requested group + * @param additionalAttributes additional attributes to be returned or excluded from the response + * @return the group with the specified groupId or null if no such group exists + */ default Group getGroup(String groupId, RequestedResourceAttributes additionalAttributes) { return getGroup(groupId); } + /** + * @param groupId unique group id of the requested group + * @param additionalAttributes additional attributes to be returned or excluded from the response + * @param filter value of the filter query parameter + * @return the group with the specified groupId or null if no such group exists + */ + default Group getGroup(String groupId, RequestedResourceAttributes additionalAttributes, String filter) { + return getGroup(groupId, additionalAttributes); + } + /** * Returns a page of groups (limited by {@link SCIMConfigurationCallback#getMaxResourcesPerPage()}), * taking into account the specified filter and paging parameters. diff --git a/scimono-server/src/main/java/com/sap/scimono/callback/schemas/DefaultSchemasCallback.java b/scimono-server/src/main/java/com/sap/scimono/callback/schemas/DefaultSchemasCallback.java index 01f8346..f128d69 100644 --- a/scimono-server/src/main/java/com/sap/scimono/callback/schemas/DefaultSchemasCallback.java +++ b/scimono-server/src/main/java/com/sap/scimono/callback/schemas/DefaultSchemasCallback.java @@ -4,7 +4,6 @@ import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.Response; -import com.sap.scimono.entity.schema.Attribute; import com.sap.scimono.entity.schema.Schema; import java.util.List; @@ -37,9 +36,4 @@ public boolean isValidSchemaName(String schemaName) { throw new WebApplicationException(Response.Status.NOT_IMPLEMENTED); } - @Override - public Attribute getAttribute(String path) { - throw new WebApplicationException(Response.Status.NOT_IMPLEMENTED); - } - } diff --git a/scimono-server/src/main/java/com/sap/scimono/callback/schemas/SchemasCallback.java b/scimono-server/src/main/java/com/sap/scimono/callback/schemas/SchemasCallback.java index 36d44ce..ee73ee9 100644 --- a/scimono-server/src/main/java/com/sap/scimono/callback/schemas/SchemasCallback.java +++ b/scimono-server/src/main/java/com/sap/scimono/callback/schemas/SchemasCallback.java @@ -193,7 +193,7 @@ default String removeValueFilterFromAttributeNotation(final String fullAttribute } static boolean isCustomSchema(final String schemaId) { - return schemaId.matches(SCHEMA_PATTERN.toString()); + return !isCoreSchema(schemaId) && schemaId.matches(SCHEMA_PATTERN.toString()); } static boolean isCoreSchema(final String schemaId) { diff --git a/scimono-server/src/main/java/com/sap/scimono/callback/users/UsersCallback.java b/scimono-server/src/main/java/com/sap/scimono/callback/users/UsersCallback.java index 1d7e04a..7832876 100644 --- a/scimono-server/src/main/java/com/sap/scimono/callback/users/UsersCallback.java +++ b/scimono-server/src/main/java/com/sap/scimono/callback/users/UsersCallback.java @@ -36,6 +36,15 @@ default User getUser(String userId, RequestedResourceAttributes additionalAttrib return getUser(userId); } + /** + * @param additionalAttributes additional attributes to be returned of excluded from the response + * @param filter value of the filter query parameter + * @return the user with the specified userId or null if no such user exists + */ + default User getUser(String userId, RequestedResourceAttributes additionalAttributes, final String filter) { + return getUser(userId, additionalAttributes); + } + /** * Returns a page of users (limited by {@link SCIMConfigurationCallback#getMaxResourcesPerPage()}), * taking into account the specified filter and paging parameters. diff --git a/scimono-server/src/test/java/com/sap/scimono/api/UsersTest.java b/scimono-server/src/test/java/com/sap/scimono/api/UsersTest.java index 75d79cc..961a0dd 100644 --- a/scimono-server/src/test/java/com/sap/scimono/api/UsersTest.java +++ b/scimono-server/src/test/java/com/sap/scimono/api/UsersTest.java @@ -1,36 +1,95 @@ package com.sap.scimono.api; -import com.sap.scimono.SCIMApplication; -import com.sap.scimono.exception.InvalidInputException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sap.scimono.SCIMApplication; +import com.sap.scimono.callback.schemas.SchemasCallback; +import com.sap.scimono.callback.users.UsersCallback; +import com.sap.scimono.entity.patch.PatchBody; +import com.sap.scimono.entity.patch.PatchOperation; +import com.sap.scimono.exception.InvalidInputException; public class UsersTest { private Users users; - @BeforeEach + private ObjectMapper mapper; + private SchemasCallback schemasCallbackMock = Mockito.mock(SchemasCallback.class, Mockito.CALLS_REAL_METHODS); + private UsersCallback usersCallbackMock = Mockito.mock(UsersCallback.class, Mockito.CALLS_REAL_METHODS); + + ArgumentCaptor userIdCaptor = ArgumentCaptor.forClass(String.class); + ArgumentCaptor patchBodyCaptor = ArgumentCaptor.forClass(PatchBody.class); + private final String PATCH_OP_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:PatchOp"; + + @Before public void setup() { + mapper = new ObjectMapper(); SCIMApplication scimApplication = new SCIMApplication() { + @Override + public SchemasCallback getSchemasCallback() { + return schemasCallbackMock; + } + + @Override + public UsersCallback getUsersCallback() { + return usersCallbackMock; + } }; users = new Users(scimApplication, null); } - @Test + @Test(expected = InvalidInputException.class) public void testUpdateUserWithEmptyBody() { String userId = String.valueOf(UUID.randomUUID()); + } - assertThrows(InvalidInputException.class, () -> users.updateUser(userId, null)); + @Test(expected = InvalidInputException.class) + public void testPatchUserWithEmptyBody() { + String userId = String.valueOf(UUID.randomUUID()); } @Test - public void testPatchUserWithEmptyBody() { + public void testPatchUserActivate() throws JsonProcessingException { + Mockito.doNothing().when(usersCallbackMock).patchUser(Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doReturn(new ArrayList<>()).when(schemasCallbackMock).getCustomSchemas(); String userId = String.valueOf(UUID.randomUUID()); - assertThrows(InvalidInputException.class, () -> users.patchUser(userId, null)); + Set schemas = new HashSet<>(); + schemas.add(PATCH_OP_SCHEMA); + + + JsonNode valueTrue = getValueTrue(); + PatchOperation patchOperation1 = new PatchOperation.Builder() + .setOp(PatchOperation.Type.ADD) + .setPath("active") + .setValue(valueTrue) + .build(); + PatchBody patchBody = new PatchBody.Builder() + .addOperation(patchOperation1) + .setSchemas(schemas) + .build(); + users.patchUser(userId, patchBody); + + Mockito.verify(usersCallbackMock).patchUser(userIdCaptor.capture(), patchBodyCaptor.capture(), Mockito.any()); + Assert.assertEquals(userId, userIdCaptor.getValue()); + Assert.assertEquals(patchBody, patchBodyCaptor.getValue()); + } + + private JsonNode getValueTrue() throws JsonProcessingException { + JsonNode boolValue = mapper.readTree("true"); + return boolValue; } }