use of org.apache.syncope.ext.scimv2.api.data.Value 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;
}
use of org.apache.syncope.ext.scimv2.api.data.Value in project syncope by apache.
the class SearchCondVisitor method addresses.
private SearchCond addresses(final String operator, final String left, final String right, final List<SCIMUserAddressConf> items) {
if (left.endsWith(".type") && "eq".equals(operator)) {
Optional<SCIMUserAddressConf> item = items.stream().filter(object -> object.getType().name().equals(StringUtils.strip(right, "\""))).findFirst();
if (item.isPresent()) {
AttributeCond attributeCond = new AttributeCond();
attributeCond.setSchema(item.get().getFormatted());
attributeCond.setType(AttributeCond.Type.ISNOTNULL);
return SearchCond.getLeafCond(attributeCond);
}
} else if (!conf.getUserConf().getEmails().isEmpty() && (MULTIVALUE.contains(left) || left.endsWith(".value"))) {
List<SearchCond> orConds = new ArrayList<>();
items.forEach(item -> {
AttributeCond cond = new AttributeCond();
cond.setSchema(item.getFormatted());
cond.setExpression(StringUtils.strip(right, "\""));
orConds.add(setOperator(cond, operator));
});
if (!orConds.isEmpty()) {
return SearchCond.getOrCond(orConds);
}
}
return null;
}
use of org.apache.syncope.ext.scimv2.api.data.Value 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());
}
use of org.apache.syncope.ext.scimv2.api.data.Value in project syncope by apache.
the class SCIMITCase method createUser.
@Test
public void createUser() throws JsonProcessingException {
assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
scimConfService.set(CONF);
SCIMUser user = getSampleUser(UUID.randomUUID().toString());
user.getRoles().add(new Value("User reviewer"));
user.getGroups().add(new Group("37d15e4c-cdc1-460b-a591-8505c8133806", null, null, null));
Response response = webClient().path("Users").post(user);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
user = response.readEntity(SCIMUser.class);
assertNotNull(user.getId());
assertTrue(response.getLocation().toASCIIString().endsWith(user.getId()));
UserTO userTO = userService.read(user.getId());
assertEquals(user.getUserName(), userTO.getUsername());
assertTrue(user.isActive());
assertEquals(user.getDisplayName(), userTO.getDerAttr("cn").get().getValues().get(0));
assertEquals(user.getName().getGivenName(), userTO.getPlainAttr("firstname").get().getValues().get(0));
assertEquals(user.getName().getFamilyName(), userTO.getPlainAttr("surname").get().getValues().get(0));
assertEquals(user.getName().getFormatted(), userTO.getPlainAttr("fullname").get().getValues().get(0));
assertEquals(user.getEmails().get(0).getValue(), userTO.getPlainAttr("userId").get().getValues().get(0));
assertEquals(user.getEmails().get(1).getValue(), userTO.getPlainAttr("email").get().getValues().get(0));
assertEquals(user.getRoles().get(0).getValue(), userTO.getRoles().get(0));
assertEquals(user.getGroups().get(0).getValue(), userTO.getMemberships().get(0).getGroupKey());
}
use of org.apache.syncope.ext.scimv2.api.data.Value in project syncope by apache.
the class SearchCondVisitor method complex.
private <E extends Enum<?>> SearchCond complex(final String operator, final String left, final String right, final List<SCIMComplexConf<E>> items) {
if (left.endsWith(".type")) {
Optional<SCIMComplexConf<E>> item = items.stream().filter(object -> object.getType().name().equals(StringUtils.strip(right, "\""))).findFirst();
if (item.isPresent()) {
AttributeCond attributeCond = new AttributeCond();
attributeCond.setSchema(item.get().getValue());
attributeCond.setType(AttributeCond.Type.ISNOTNULL);
return SearchCond.getLeafCond(attributeCond);
}
} else if (!conf.getUserConf().getEmails().isEmpty() && (MULTIVALUE.contains(left) || left.endsWith(".value"))) {
List<SearchCond> orConds = new ArrayList<>();
items.forEach(item -> {
AttributeCond cond = new AttributeCond();
cond.setSchema(item.getValue());
cond.setExpression(StringUtils.strip(right, "\""));
orConds.add(setOperator(cond, operator));
});
if (!orConds.isEmpty()) {
return SearchCond.getOrCond(orConds);
}
}
return null;
}
Aggregations