Search in sources :

Example 1 with SCIMGroup

use of org.apache.syncope.ext.scimv2.api.data.SCIMGroup in project syncope by apache.

the class SCIMITCase method list.

@Test
public void list() throws IOException {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    Response response = webClient().path("Groups").query("count", 1100000).get();
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    SCIMError error = response.readEntity(SCIMError.class);
    assertEquals(ErrorType.tooMany, error.getScimType());
    response = webClient().path("Groups").query("sortBy", "displayName").query("count", 11).get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    ListResponse<SCIMGroup> result = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
    });
    assertNotNull(result);
    assertTrue(result.getTotalResults() > 0);
    assertEquals(11, result.getItemsPerPage());
    assertFalse(result.getResources().isEmpty());
    result.getResources().forEach(group -> {
        assertNotNull(group.getId());
        assertNotNull(group.getDisplayName());
    });
}
Also used : ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) Test(org.junit.jupiter.api.Test)

Example 2 with SCIMGroup

use of org.apache.syncope.ext.scimv2.api.data.SCIMGroup in project syncope by apache.

the class SCIMITCase method createGroup.

@Test
public void createGroup() {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    String displayName = UUID.randomUUID().toString();
    SCIMGroup group = new SCIMGroup(null, null, displayName);
    group.getMembers().add(new Member("1417acbe-cbf6-4277-9372-e75e04f97000", null, null));
    assertNull(group.getId());
    assertEquals(displayName, group.getDisplayName());
    Response response = webClient().path("Groups").post(group);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    group = response.readEntity(SCIMGroup.class);
    assertNotNull(group.getId());
    assertTrue(response.getLocation().toASCIIString().endsWith(group.getId()));
    assertEquals(1, group.getMembers().size());
    assertEquals("1417acbe-cbf6-4277-9372-e75e04f97000", group.getMembers().get(0).getValue());
    response = webClient().path("Users").path("1417acbe-cbf6-4277-9372-e75e04f97000").get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    SCIMUser user = response.readEntity(SCIMUser.class);
    assertEquals("1417acbe-cbf6-4277-9372-e75e04f97000", user.getId());
    response = webClient().path("Groups").post(group);
    assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatus());
    SCIMError error = response.readEntity(SCIMError.class);
    assertEquals(Response.Status.CONFLICT.getStatusCode(), error.getStatus());
    assertEquals(ErrorType.uniqueness, error.getScimType());
}
Also used : ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) SCIMUser(org.apache.syncope.ext.scimv2.api.data.SCIMUser) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) Member(org.apache.syncope.ext.scimv2.api.data.Member) Test(org.junit.jupiter.api.Test)

Example 3 with SCIMGroup

use of org.apache.syncope.ext.scimv2.api.data.SCIMGroup in project syncope by apache.

the class SCIMITCase method deleteGroup.

@Test
public void deleteGroup() {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    SCIMGroup group = new SCIMGroup(null, null, UUID.randomUUID().toString());
    Response response = webClient().path("Groups").post(group);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    group = response.readEntity(SCIMGroup.class);
    assertNotNull(group.getId());
    response = webClient().path("Groups").path(group.getId()).get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = webClient().path("Groups").path(group.getId()).delete();
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    response = webClient().path("Groups").path(group.getId()).get();
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
Also used : ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) Test(org.junit.jupiter.api.Test)

Example 4 with SCIMGroup

use of org.apache.syncope.ext.scimv2.api.data.SCIMGroup in project syncope by apache.

the class SCIMITCase method search.

@Test
public void search() {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    // invalid filter
    Response response = webClient().path("Groups").query("filter", "invalid").get();
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    SCIMError error = response.readEntity(SCIMError.class);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), error.getStatus());
    assertEquals(ErrorType.invalidFilter, error.getScimType());
    // eq
    response = webClient().path("Groups").query("filter", "displayName eq \"additional\"").get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    ListResponse<SCIMGroup> groups = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
    });
    assertNotNull(groups);
    assertEquals(1, groups.getTotalResults());
    SCIMGroup additional = groups.getResources().get(0);
    assertEquals("additional", additional.getDisplayName());
    // eq via POST
    SCIMSearchRequest request = new SCIMSearchRequest("displayName eq \"additional\"", null, null, null, null);
    response = webClient().path("Groups").path("/.search").post(request);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    groups = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
    });
    assertNotNull(groups);
    assertEquals(1, groups.getTotalResults());
    additional = groups.getResources().get(0);
    assertEquals("additional", additional.getDisplayName());
    // gt
    UserTO newUser = userService.create(UserITCase.getUniqueSampleTO("scimsearch@syncope.apache.org"), true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    Date value = new Date(newUser.getCreationDate().getTime() - 1000);
    response = webClient().path("Users").query("filter", "meta.created gt \"" + DATE_FORMAT.get().format(value) + "\"").get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    ListResponse<SCIMUser> users = response.readEntity(new GenericType<ListResponse<SCIMUser>>() {
    });
    assertNotNull(users);
    assertEquals(1, users.getTotalResults());
    SCIMUser newSCIMUser = users.getResources().get(0);
    assertEquals(newUser.getUsername(), newSCIMUser.getUserName());
}
Also used : GenericType(javax.ws.rs.core.GenericType) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) SCIMUser(org.apache.syncope.ext.scimv2.api.data.SCIMUser) Date(java.util.Date) ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) UserTO(org.apache.syncope.common.lib.to.UserTO) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) SCIMSearchRequest(org.apache.syncope.ext.scimv2.api.data.SCIMSearchRequest) Test(org.junit.jupiter.api.Test)

Example 5 with SCIMGroup

use of org.apache.syncope.ext.scimv2.api.data.SCIMGroup in project syncope by apache.

the class SCIMITCase method replaceGroup.

@Test
public void replaceGroup() {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    SCIMGroup group = new SCIMGroup(null, null, UUID.randomUUID().toString());
    group.getMembers().add(new Member("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee", null, null));
    Response response = webClient().path("Groups").post(group);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    group = response.readEntity(SCIMGroup.class);
    assertNotNull(group.getId());
    assertEquals(1, group.getMembers().size());
    assertEquals("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee", group.getMembers().get(0).getValue());
    group.setDisplayName("other" + group.getId());
    group.getMembers().add(new Member("c9b2dec2-00a7-4855-97c0-d854842b4b24", null, null));
    response = webClient().path("Groups").path(group.getId()).put(group);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    group = response.readEntity(SCIMGroup.class);
    assertTrue(group.getDisplayName().startsWith("other"));
    assertEquals(2, group.getMembers().size());
    group.getMembers().clear();
    group.getMembers().add(new Member("c9b2dec2-00a7-4855-97c0-d854842b4b24", null, null));
    response = webClient().path("Groups").path(group.getId()).put(group);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    group = response.readEntity(SCIMGroup.class);
    assertEquals(1, group.getMembers().size());
    assertEquals("c9b2dec2-00a7-4855-97c0-d854842b4b24", group.getMembers().get(0).getValue());
}
Also used : ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) Member(org.apache.syncope.ext.scimv2.api.data.Member) Test(org.junit.jupiter.api.Test)

Aggregations

SCIMGroup (org.apache.syncope.ext.scimv2.api.data.SCIMGroup)7 Response (javax.ws.rs.core.Response)6 ListResponse (org.apache.syncope.ext.scimv2.api.data.ListResponse)6 Member (org.apache.syncope.ext.scimv2.api.data.Member)5 Test (org.junit.jupiter.api.Test)5 GroupTO (org.apache.syncope.common.lib.to.GroupTO)3 BadRequestException (org.apache.syncope.ext.scimv2.api.BadRequestException)3 SCIMError (org.apache.syncope.ext.scimv2.api.data.SCIMError)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 MembershipCond (org.apache.syncope.core.persistence.api.dao.search.MembershipCond)2 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)2 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)2 SCIMSearchRequest (org.apache.syncope.ext.scimv2.api.data.SCIMSearchRequest)2 SCIMUser (org.apache.syncope.ext.scimv2.api.data.SCIMUser)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1