Search in sources :

Example 1 with Member

use of org.apache.syncope.ext.scimv2.api.data.Member 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 2 with Member

use of org.apache.syncope.ext.scimv2.api.data.Member 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)

Example 3 with Member

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

the class GroupServiceImpl method create.

@Override
public Response create(final SCIMGroup group) {
    // first create group, no members assigned
    ProvisioningResult<GroupTO> result = groupLogic().create(binder().toGroupTO(group), false);
    // then assign members
    for (Member member : group.getMembers()) {
        UserPatch patch = new UserPatch();
        patch.setKey(member.getValue());
        patch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(result.getEntity().getKey()).build());
        try {
            userLogic().update(patch, false);
        } catch (Exception e) {
            LOG.error("While setting membership of {} to {}", result.getEntity().getKey(), member.getValue(), e);
        }
    }
    return createResponse(result.getEntity().getKey(), binder().toSCIMGroup(result.getEntity(), uriInfo.getAbsolutePathBuilder().path(result.getEntity().getKey()).build().toASCIIString(), Collections.<String>emptyList(), Collections.<String>emptyList()));
}
Also used : ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Member(org.apache.syncope.ext.scimv2.api.data.Member) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 4 with Member

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

the class GroupServiceImpl method replace.

@Override
public Response replace(final String id, final SCIMGroup group) {
    if (!id.equals(group.getId())) {
        throw new BadRequestException(ErrorType.invalidPath, "Expected " + id + ", found " + group.getId());
    }
    ResponseBuilder builder = checkETag(Resource.Group, id);
    if (builder != null) {
        return builder.build();
    }
    // save current group members
    Set<String> beforeMembers = new HashSet<>();
    MembershipCond membCond = new MembershipCond();
    membCond.setGroup(id);
    SearchCond searchCond = SearchCond.getLeafCond(membCond);
    int count = userLogic().search(searchCond, 1, 1, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getLeft();
    for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
        beforeMembers.addAll(userLogic().search(searchCond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getRight().stream().map(EntityTO::getKey).collect(Collectors.toSet()));
    }
    // update group, don't change members
    ProvisioningResult<GroupTO> result = groupLogic().update(AnyOperations.diff(binder().toGroupTO(group), groupLogic().read(id), false), false);
    // assign new members
    Set<String> afterMembers = new HashSet<>();
    group.getMembers().forEach(member -> {
        afterMembers.add(member.getValue());
        if (!beforeMembers.contains(member.getValue())) {
            UserPatch patch = new UserPatch();
            patch.setKey(member.getValue());
            patch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(result.getEntity().getKey()).build());
            try {
                userLogic().update(patch, false);
            } catch (Exception e) {
                LOG.error("While setting membership of {} to {}", result.getEntity().getKey(), member.getValue(), e);
            }
        }
    });
    // remove unconfirmed members
    beforeMembers.stream().filter(member -> !afterMembers.contains(member)).forEach(user -> {
        UserPatch patch = new UserPatch();
        patch.setKey(user);
        patch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.DELETE).group(result.getEntity().getKey()).build());
        try {
            userLogic().update(patch, false);
        } catch (Exception e) {
            LOG.error("While removing membership of {} from {}", result.getEntity().getKey(), user, e);
        }
    });
    return updateResponse(result.getEntity().getKey(), binder().toSCIMGroup(result.getEntity(), uriInfo.getAbsolutePathBuilder().path(result.getEntity().getKey()).build().toASCIIString(), Collections.<String>emptyList(), Collections.<String>emptyList()));
}
Also used : Arrays(java.util.Arrays) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) ErrorType(org.apache.syncope.ext.scimv2.api.type.ErrorType) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) ArrayUtils(org.apache.commons.lang3.ArrayUtils) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) EntityTO(org.apache.syncope.common.lib.to.EntityTO) SortOrder(org.apache.syncope.ext.scimv2.api.type.SortOrder) ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) Resource(org.apache.syncope.ext.scimv2.api.type.Resource) Response(javax.ws.rs.core.Response) AnyDAO(org.apache.syncope.core.persistence.api.dao.AnyDAO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) SCIMSearchRequest(org.apache.syncope.ext.scimv2.api.data.SCIMSearchRequest) Member(org.apache.syncope.ext.scimv2.api.data.Member) GroupService(org.apache.syncope.ext.scimv2.api.service.GroupService) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) Collections(java.util.Collections) AnyOperations(org.apache.syncope.common.lib.AnyOperations) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) EntityTO(org.apache.syncope.common.lib.to.EntityTO) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) HashSet(java.util.HashSet)

Example 5 with Member

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

the class SCIMDataBinder method toSCIMGroup.

public SCIMGroup toSCIMGroup(final GroupTO groupTO, final String location, final List<String> attributes, final List<String> excludedAttributes) {
    SCIMGroup group = new SCIMGroup(groupTO.getKey(), new Meta(Resource.Group, groupTO.getCreationDate(), groupTO.getLastChangeDate() == null ? groupTO.getCreationDate() : groupTO.getLastChangeDate(), groupTO.getETagValue(), location), output(attributes, excludedAttributes, "displayName", groupTO.getName()));
    MembershipCond membCond = new MembershipCond();
    membCond.setGroup(groupTO.getKey());
    SearchCond searchCond = SearchCond.getLeafCond(membCond);
    if (output(attributes, excludedAttributes, "members")) {
        int count = userLogic.search(searchCond, 1, 1, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getLeft();
        for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
            List<UserTO> users = userLogic.search(searchCond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getRight();
            users.forEach(userTO -> {
                group.getMembers().add(new Member(userTO.getKey(), StringUtils.substringBefore(location, "/Groups") + "/Users/" + userTO.getKey(), userTO.getUsername()));
            });
        }
    }
    return group;
}
Also used : Meta(org.apache.syncope.ext.scimv2.api.data.Meta) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Member(org.apache.syncope.ext.scimv2.api.data.Member)

Aggregations

Member (org.apache.syncope.ext.scimv2.api.data.Member)5 SCIMGroup (org.apache.syncope.ext.scimv2.api.data.SCIMGroup)4 Response (javax.ws.rs.core.Response)3 ListResponse (org.apache.syncope.ext.scimv2.api.data.ListResponse)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)2 GroupTO (org.apache.syncope.common.lib.to.GroupTO)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 BadRequestException (org.apache.syncope.ext.scimv2.api.BadRequestException)2 Test (org.junit.jupiter.api.Test)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AnyOperations (org.apache.syncope.common.lib.AnyOperations)1