in ext/scimv2/logic/src/main/java/org/apache/syncope/core/logic/SCIMDataBinder.java [510:711]
public UserTO toUserTO(final SCIMUser user, final boolean checkSchemas) {
SCIMConf conf = confManager.get();
Set<String> expectedSchemas = new HashSet<>();
expectedSchemas.add(Resource.User.schema());
if (conf.getEnterpriseUserConf() != null) {
expectedSchemas.add(Resource.EnterpriseUser.schema());
}
if (conf.getExtensionUserConf() != null) {
expectedSchemas.add(Resource.ExtensionUser.schema());
}
if (checkSchemas
&& (!user.getSchemas().containsAll(expectedSchemas)
|| !expectedSchemas.containsAll(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());
if (conf.getUserConf() != null) {
setAttribute(
userTO,
conf.getUserConf().getExternalId(),
user.getExternalId());
if (conf.getUserConf().getName() != null && user.getName() != null) {
setAttribute(
userTO,
conf.getUserConf().getName().getFamilyName(),
user.getName().getFamilyName());
setAttribute(
userTO,
conf.getUserConf().getName().getFormatted(),
user.getName().getFormatted());
setAttribute(
userTO,
conf.getUserConf().getName().getGivenName(),
user.getName().getGivenName());
setAttribute(
userTO,
conf.getUserConf().getName().getHonorificPrefix(),
user.getName().getHonorificPrefix());
setAttribute(
userTO,
conf.getUserConf().getName().getHonorificSuffix(),
user.getName().getHonorificSuffix());
setAttribute(
userTO,
conf.getUserConf().getName().getMiddleName(),
user.getName().getMiddleName());
}
setAttribute(
userTO,
conf.getUserConf().getDisplayName(),
user.getDisplayName());
setAttribute(
userTO,
conf.getUserConf().getNickName(),
user.getNickName());
setAttribute(
userTO,
conf.getUserConf().getProfileUrl(),
user.getProfileUrl());
setAttribute(
userTO,
conf.getUserConf().getTitle(),
user.getTitle());
setAttribute(
userTO,
conf.getUserConf().getUserType(),
user.getUserType());
setAttribute(
userTO,
conf.getUserConf().getPreferredLanguage(),
user.getPreferredLanguage());
setAttribute(
userTO,
conf.getUserConf().getLocale(),
user.getLocale());
setAttribute(
userTO,
conf.getUserConf().getTimezone(),
user.getTimezone());
setAttribute(userTO.getPlainAttrs(), conf.getUserConf().getEmails(), user.getEmails());
setAttribute(userTO.getPlainAttrs(), conf.getUserConf().getPhoneNumbers(), user.getPhoneNumbers());
setAttribute(userTO.getPlainAttrs(), conf.getUserConf().getIms(), user.getIms());
setAttribute(userTO.getPlainAttrs(), conf.getUserConf().getPhotos(), user.getPhotos());
user.getAddresses().stream().filter(address -> address.getType() != null).
forEach(address -> conf.getUserConf().getAddresses().stream().
filter(object -> address.getType().equals(object.getType().name())).findFirst().
ifPresent(addressConf -> {
setAttribute(
userTO,
addressConf.getFormatted(),
address.getFormatted());
setAttribute(
userTO,
addressConf.getStreetAddress(),
address.getStreetAddress());
setAttribute(
userTO,
addressConf.getLocality(),
address.getLocality());
setAttribute(
userTO,
addressConf.getRegion(),
address.getRegion());
setAttribute(
userTO,
addressConf.getPostalCode(),
address.getPostalCode());
setAttribute(
userTO,
addressConf.getCountry(),
address.getCountry());
}));
for (int i = 0; i < user.getX509Certificates().size(); i++) {
Value certificate = user.getX509Certificates().get(i);
if (conf.getUserConf().getX509Certificates().size() > i) {
setAttribute(
userTO,
conf.getUserConf().getX509Certificates().get(i),
certificate.getValue());
}
}
}
if (conf.getEnterpriseUserConf() != null && user.getEnterpriseInfo() != null) {
setAttribute(
userTO,
conf.getEnterpriseUserConf().getEmployeeNumber(),
user.getEnterpriseInfo().getEmployeeNumber());
setAttribute(
userTO,
conf.getEnterpriseUserConf().getCostCenter(),
user.getEnterpriseInfo().getCostCenter());
setAttribute(
userTO,
conf.getEnterpriseUserConf().getOrganization(),
user.getEnterpriseInfo().getOrganization());
setAttribute(
userTO,
conf.getEnterpriseUserConf().getDivision(),
user.getEnterpriseInfo().getDivision());
setAttribute(
userTO,
conf.getEnterpriseUserConf().getDepartment(),
user.getEnterpriseInfo().getDepartment());
setAttribute(
userTO,
Optional.ofNullable(conf.getEnterpriseUserConf().getManager()).
map(SCIMManagerConf::getKey).orElse(null),
Optional.ofNullable(user.getEnterpriseInfo().getManager()).
map(SCIMUserManager::getValue).orElse(null));
}
if (conf.getExtensionUserConf() != null && user.getExtensionInfo() != null) {
conf.getExtensionUserConf().asMap().forEach((scimAttr, syncopeAttr) -> setAttribute(
userTO, syncopeAttr, user.getExtensionInfo().getAttributes().get(scimAttr)));
}
userTO.getMemberships().addAll(user.getGroups().stream().
map(group -> new MembershipTO.Builder(group.getValue()).build()).
toList());
userTO.getRoles().addAll(user.getRoles().stream().
map(Value::getValue).
toList());
return userTO;
}