Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scimono jakarta branch next dev #238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sap.scimono</groupId>
<artifactId>scimono-parent</artifactId>
<version>0.1.3-SNAPSHOT</version>
<version>0.1.5-SNAPSHOT</version>
<packaging>pom</packaging>

<name>SAP SCIMono Library</name>
Expand Down
2 changes: 1 addition & 1 deletion scimono-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>scimono-parent</artifactId>
<groupId>com.sap.scimono</groupId>
<version>0.1.3-SNAPSHOT</version>
<version>0.1.5-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion scimono-compliance-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>scimono-parent</artifactId>
<groupId>com.sap.scimono</groupId>
<version>0.1.3-SNAPSHOT</version>
<version>0.1.5-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion scimono-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>scimono-parent</artifactId>
<groupId>com.sap.scimono</groupId>
<version>0.1.3-SNAPSHOT</version>
<version>0.1.5-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion scimono-examples/simple-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>scimono-examples</artifactId>
<groupId>com.sap.scimono.examples</groupId>
<version>0.1.3-SNAPSHOT</version>
<version>0.1.5-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
12 changes: 11 additions & 1 deletion scimono-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>scimono-parent</artifactId>
<groupId>com.sap.scimono</groupId>
<version>0.1.3-SNAPSHOT</version>
<version>0.1.5-SNAPSHOT</version>
</parent>

<artifactId>scimono-server</artifactId>
Expand Down Expand Up @@ -84,18 +84,22 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Expand All @@ -108,6 +112,12 @@
<artifactId>jersey-test-framework-provider-external</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
3 changes: 2 additions & 1 deletion scimono-server/src/main/java/com/sap/scimono/api/Groups.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion scimono-server/src/main/java/com/sap/scimono/api/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
79 changes: 69 additions & 10 deletions scimono-server/src/test/java/com/sap/scimono/api/UsersTest.java
Original file line number Diff line number Diff line change
@@ -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<String> userIdCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<PatchBody> 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<String> 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;
}

}
Loading