}
final List<AbstractAttrValue> values = MappingUtil.getIntValues(resource, mapItem, attributables,
vAttrsToBeRemoved, vAttrsToBeUpdated);
AbstractSchema schema = null;
AttributeSchemaType schemaType;
switch (mapItem.getIntMappingType()) {
case UserSchema:
case RoleSchema:
case MembershipSchema:
final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
final SchemaDAO schemaDAO = context.getBean(SchemaDAO.class);
schema = schemaDAO.find(mapItem.getIntAttrName(),
MappingUtil.getIntMappingTypeClass(mapItem.getIntMappingType()));
schemaType = schema == null ? AttributeSchemaType.String : schema.getType();
break;
default:
schemaType = AttributeSchemaType.String;
}
final String extAttrName = mapItem.getExtAttrName();
LOG.debug("Define mapping for: "
+ "\n* ExtAttrName " + extAttrName
+ "\n* is accountId " + mapItem.isAccountid()
+ "\n* is password " + (mapItem.isPassword() || mapItem.getIntMappingType() == IntMappingType.Password)
+ "\n* mandatory condition " + mapItem.getMandatoryCondition()
+ "\n* Schema " + mapItem.getIntAttrName()
+ "\n* IntMappingType " + mapItem.getIntMappingType().toString()
+ "\n* ClassType " + schemaType.getType().getName()
+ "\n* Values " + values);
List<Object> objValues = new ArrayList<Object>();
for (AbstractAttrValue value : values) {
if (FrameworkUtil.isSupportedAttributeType(schemaType.getType())) {
objValues.add(value.getValue());
} else {
objValues.add(value.getValueAsString());
}
}
Map.Entry<String, Attribute> result;
if (mapItem.isAccountid()) {
result = new AbstractMap.SimpleEntry<String, Attribute>(objValues.iterator().next().toString(), null);
} else if (mapItem.isPassword() && subject instanceof SyncopeUser) {
String passwordAttrValue = password;
if (StringUtils.isBlank(passwordAttrValue)) {
SyncopeUser user = (SyncopeUser) subject;
if (user.canDecodePassword()) {
try {
passwordAttrValue = PasswordEncoder.decode(user.getPassword(), user.getCipherAlgorithm());
} catch (Exception e) {
LOG.error("Could not decode password for {}", user, e);
}
} else if (resource.isRandomPwdIfNotProvided()) {
try {
passwordAttrValue = passwordGenerator.generate(user);
} catch (InvalidPasswordPolicySpecException e) {
LOG.error("Could not generate policy-compliant random password for {}", user, e);
passwordAttrValue = RandomStringUtils.randomAlphanumeric(16);
}
}
}
result = new AbstractMap.SimpleEntry<String, Attribute>(null,
AttributeBuilder.buildPassword(passwordAttrValue.toCharArray()));
} else {
if (schema != null && schema.isMultivalue()) {
result = new AbstractMap.SimpleEntry<String, Attribute>(null, AttributeBuilder.build(extAttrName,
objValues));
} else {
result = new AbstractMap.SimpleEntry<String, Attribute>(null, objValues.isEmpty()
? AttributeBuilder.build(extAttrName)