Search in sources :

Example 1 with Group

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

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

the class SCIMDataBinder method toUserTO.

public UserTO toUserTO(final SCIMUser user) {
    if (!USER_SCHEMAS.equals(user.getSchemas()) && !ENTERPRISE_USER_SCHEMAS.equals(user.getSchemas())) {
        throw new BadRequestException(ErrorType.invalidValue);
    }
    UserTO userTO = new UserTO();
    userTO.setRealm(SyncopeConstants.ROOT_REALM);
    userTO.setKey(user.getId());
    userTO.setPassword(user.getPassword());
    userTO.setUsername(user.getUserName());
    SCIMConf conf = confManager.get();
    if (conf.getUserConf() != null) {
        if (conf.getUserConf().getName() != null && user.getName() != null) {
            if (conf.getUserConf().getName().getFamilyName() != null && user.getName().getFamilyName() != null) {
                userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getName().getFamilyName()).value(user.getName().getFamilyName()).build());
            }
            if (conf.getUserConf().getName().getFormatted() != null && user.getName().getFormatted() != null) {
                userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getName().getFormatted()).value(user.getName().getFormatted()).build());
            }
            if (conf.getUserConf().getName().getGivenName() != null && user.getName().getGivenName() != null) {
                userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getName().getGivenName()).value(user.getName().getGivenName()).build());
            }
            if (conf.getUserConf().getName().getHonorificPrefix() != null && user.getName().getHonorificPrefix() != null) {
                userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getName().getHonorificPrefix()).value(user.getName().getHonorificPrefix()).build());
            }
            if (conf.getUserConf().getName().getHonorificSuffix() != null && user.getName().getHonorificSuffix() != null) {
                userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getName().getHonorificSuffix()).value(user.getName().getHonorificSuffix()).build());
            }
            if (conf.getUserConf().getName().getMiddleName() != null && user.getName().getMiddleName() != null) {
                userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getName().getMiddleName()).value(user.getName().getMiddleName()).build());
            }
        }
        if (conf.getUserConf().getDisplayName() != null && user.getDisplayName() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getDisplayName()).value(user.getDisplayName()).build());
        }
        if (conf.getUserConf().getNickName() != null && user.getNickName() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getNickName()).value(user.getNickName()).build());
        }
        if (conf.getUserConf().getProfileUrl() != null && user.getProfileUrl() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getProfileUrl()).value(user.getProfileUrl()).build());
        }
        if (conf.getUserConf().getTitle() != null && user.getTitle() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getTitle()).value(user.getTitle()).build());
        }
        if (conf.getUserConf().getUserType() != null && user.getUserType() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getUserType()).value(user.getUserType()).build());
        }
        if (conf.getUserConf().getPreferredLanguage() != null && user.getPreferredLanguage() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getPreferredLanguage()).value(user.getPreferredLanguage()).build());
        }
        if (conf.getUserConf().getLocale() != null && user.getLocale() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getLocale()).value(user.getLocale()).build());
        }
        if (conf.getUserConf().getTimezone() != null && user.getTimezone() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getTimezone()).value(user.getTimezone()).build());
        }
        fill(userTO.getPlainAttrs(), conf.getUserConf().getEmails(), user.getEmails());
        fill(userTO.getPlainAttrs(), conf.getUserConf().getPhoneNumbers(), user.getPhoneNumbers());
        fill(userTO.getPlainAttrs(), conf.getUserConf().getIms(), user.getIms());
        fill(userTO.getPlainAttrs(), conf.getUserConf().getPhotos(), user.getPhotos());
        user.getAddresses().stream().filter(address -> address.getType() != null).forEach(address -> {
            Optional<SCIMUserAddressConf> addressConf = conf.getUserConf().getAddresses().stream().filter(object -> address.getType().equals(object.getType().name())).findFirst();
            if (addressConf.isPresent()) {
                if (addressConf.get().getFormatted() != null && address.getFormatted() != null) {
                    userTO.getPlainAttrs().add(new AttrTO.Builder().schema(addressConf.get().getFormatted()).value(address.getFormatted()).build());
                }
                if (addressConf.get().getStreetAddress() != null && address.getStreetAddress() != null) {
                    userTO.getPlainAttrs().add(new AttrTO.Builder().schema(addressConf.get().getStreetAddress()).value(address.getStreetAddress()).build());
                }
                if (addressConf.get().getLocality() != null && address.getLocality() != null) {
                    userTO.getPlainAttrs().add(new AttrTO.Builder().schema(addressConf.get().getLocality()).value(address.getLocality()).build());
                }
                if (addressConf.get().getRegion() != null && address.getFormatted() != null) {
                    userTO.getPlainAttrs().add(new AttrTO.Builder().schema(addressConf.get().getFormatted()).value(address.getFormatted()).build());
                }
                if (addressConf.get().getPostalCode() != null && address.getPostalCode() != null) {
                    userTO.getPlainAttrs().add(new AttrTO.Builder().schema(addressConf.get().getPostalCode()).value(address.getPostalCode()).build());
                }
                if (addressConf.get().getCountry() != null && address.getCountry() != null) {
                    userTO.getPlainAttrs().add(new AttrTO.Builder().schema(addressConf.get().getCountry()).value(address.getCountry()).build());
                }
            }
        });
        for (int i = 0; i < user.getX509Certificates().size(); i++) {
            Value certificate = user.getX509Certificates().get(i);
            if (conf.getUserConf().getX509Certificates().size() > i) {
                userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getUserConf().getX509Certificates().get(i)).value(certificate.getValue()).build());
            }
        }
    }
    if (conf.getEnterpriseUserConf() != null) {
        if (conf.getEnterpriseUserConf().getEmployeeNumber() != null && user.getEnterpriseInfo().getEmployeeNumber() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getEnterpriseUserConf().getEmployeeNumber()).value(user.getEnterpriseInfo().getEmployeeNumber()).build());
        }
        if (conf.getEnterpriseUserConf().getCostCenter() != null && user.getEnterpriseInfo().getCostCenter() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getEnterpriseUserConf().getCostCenter()).value(user.getEnterpriseInfo().getCostCenter()).build());
        }
        if (conf.getEnterpriseUserConf().getOrganization() != null && user.getEnterpriseInfo().getOrganization() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getEnterpriseUserConf().getOrganization()).value(user.getEnterpriseInfo().getOrganization()).build());
        }
        if (conf.getEnterpriseUserConf().getDivision() != null && user.getEnterpriseInfo().getDivision() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getEnterpriseUserConf().getDivision()).value(user.getEnterpriseInfo().getDivision()).build());
        }
        if (conf.getEnterpriseUserConf().getDepartment() != null && user.getEnterpriseInfo().getDepartment() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getEnterpriseUserConf().getDepartment()).value(user.getEnterpriseInfo().getDepartment()).build());
        }
        if (conf.getEnterpriseUserConf().getManager() != null && conf.getEnterpriseUserConf().getManager().getKey() != null && user.getEnterpriseInfo().getManager() != null && user.getEnterpriseInfo().getManager().getValue() != null) {
            userTO.getPlainAttrs().add(new AttrTO.Builder().schema(conf.getEnterpriseUserConf().getManager().getKey()).value(user.getEnterpriseInfo().getManager().getValue()).build());
        }
    }
    user.getGroups().forEach(group -> {
        userTO.getMemberships().add(new MembershipTO.Builder().group(group.getValue()).build());
    });
    user.getRoles().forEach(role -> {
        userTO.getRoles().add(role.getValue());
    });
    return userTO;
}
Also used : Arrays(java.util.Arrays) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) Group(org.apache.syncope.ext.scimv2.api.data.Group) AttrTO(org.apache.syncope.common.lib.to.AttrTO) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) ErrorType(org.apache.syncope.ext.scimv2.api.type.ErrorType) LoggerFactory(org.slf4j.LoggerFactory) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) SCIMUserAddress(org.apache.syncope.ext.scimv2.api.data.SCIMUserAddress) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Map(java.util.Map) SCIMUserManager(org.apache.syncope.ext.scimv2.api.data.SCIMUserManager) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) SCIMComplexValue(org.apache.syncope.ext.scimv2.api.data.SCIMComplexValue) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) Logger(org.slf4j.Logger) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Value(org.apache.syncope.ext.scimv2.api.data.Value) SCIMUserName(org.apache.syncope.ext.scimv2.api.data.SCIMUserName) SCIMEnterpriseInfo(org.apache.syncope.ext.scimv2.api.data.SCIMEnterpriseInfo) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AuthDataAccessor(org.apache.syncope.core.spring.security.AuthDataAccessor) Function(org.apache.syncope.ext.scimv2.api.type.Function) SCIMUser(org.apache.syncope.ext.scimv2.api.data.SCIMUser) List(java.util.List) Meta(org.apache.syncope.ext.scimv2.api.data.Meta) Component(org.springframework.stereotype.Component) Resource(org.apache.syncope.ext.scimv2.api.type.Resource) SCIMComplexConf(org.apache.syncope.common.lib.scim.SCIMComplexConf) SCIMConf(org.apache.syncope.common.lib.scim.SCIMConf) AnyDAO(org.apache.syncope.core.persistence.api.dao.AnyDAO) SCIMConfManager(org.apache.syncope.core.logic.scim.SCIMConfManager) Member(org.apache.syncope.ext.scimv2.api.data.Member) Optional(java.util.Optional) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) Collections(java.util.Collections) UserTO(org.apache.syncope.common.lib.to.UserTO) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) SCIMComplexValue(org.apache.syncope.ext.scimv2.api.data.SCIMComplexValue) Value(org.apache.syncope.ext.scimv2.api.data.Value) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) SCIMConf(org.apache.syncope.common.lib.scim.SCIMConf)

Example 3 with Group

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

the class SCIMLogic method resourceTypes.

@PreAuthorize("isAuthenticated()")
public List<ResourceType> resourceTypes(final UriBuilder uriBuilder) {
    synchronized (MONITOR) {
        if (USER == null) {
            USER = new ResourceType("User", "User", "/Users", "User Account", Resource.User.schema(), new Meta(Resource.ResourceType, null, null, null, uriBuilder.path("User").build().toASCIIString()));
            USER.getSchemaExtensions().add(new SchemaExtension(Resource.EnterpriseUser.schema(), true));
        }
        if (GROUP == null) {
            GROUP = new ResourceType("Group", "Group", "/Groups", "Group", Resource.Group.schema(), new Meta(Resource.ResourceType, null, null, null, uriBuilder.path("Group").build().toASCIIString()));
        }
    }
    return Arrays.asList(USER, GROUP);
}
Also used : Meta(org.apache.syncope.ext.scimv2.api.data.Meta) SchemaExtension(org.apache.syncope.ext.scimv2.api.data.SchemaExtension) ResourceType(org.apache.syncope.ext.scimv2.api.data.ResourceType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with Group

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

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

Aggregations

SCIMGroup (org.apache.syncope.ext.scimv2.api.data.SCIMGroup)9 Member (org.apache.syncope.ext.scimv2.api.data.Member)7 Response (javax.ws.rs.core.Response)6 ListResponse (org.apache.syncope.ext.scimv2.api.data.ListResponse)6 GroupTO (org.apache.syncope.common.lib.to.GroupTO)5 BadRequestException (org.apache.syncope.ext.scimv2.api.BadRequestException)5 UserTO (org.apache.syncope.common.lib.to.UserTO)4 MembershipCond (org.apache.syncope.core.persistence.api.dao.search.MembershipCond)4 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)4 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)4 Meta (org.apache.syncope.ext.scimv2.api.data.Meta)4 SCIMUser (org.apache.syncope.ext.scimv2.api.data.SCIMUser)4 Test (org.junit.jupiter.api.Test)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Set (java.util.Set)3 StringUtils (org.apache.commons.lang3.StringUtils)3 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)3 AnyDAO (org.apache.syncope.core.persistence.api.dao.AnyDAO)3 Group (org.apache.syncope.ext.scimv2.api.data.Group)3