use of org.identityconnectors.framework.common.objects.Name in project syncope by apache.
the class MappingManagerImpl method prepareAttrs.
@Transactional(readOnly = true)
@Override
public Pair<String, Set<Attribute>> prepareAttrs(final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final Provision provision) {
LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision, any.getPlainAttrs());
Set<Attribute> attributes = new HashSet<>();
String connObjectKey = null;
for (Item mapItem : MappingUtils.getPropagationItems(provision.getMapping().getItems())) {
LOG.debug("Processing expression '{}'", mapItem.getIntAttrName());
try {
Pair<String, Attribute> preparedAttr = prepareAttr(provision, mapItem, any, password);
if (preparedAttr != null) {
if (preparedAttr.getLeft() != null) {
connObjectKey = preparedAttr.getLeft();
}
if (preparedAttr.getRight() != null) {
Attribute alreadyAdded = AttributeUtil.find(preparedAttr.getRight().getName(), attributes);
if (alreadyAdded == null) {
attributes.add(preparedAttr.getRight());
} else {
attributes.remove(alreadyAdded);
Set<Object> values = new HashSet<>();
if (alreadyAdded.getValue() != null && !alreadyAdded.getValue().isEmpty()) {
values.addAll(alreadyAdded.getValue());
}
if (preparedAttr.getRight().getValue() != null) {
values.addAll(preparedAttr.getRight().getValue());
}
attributes.add(AttributeBuilder.build(preparedAttr.getRight().getName(), values));
}
}
}
} catch (Exception e) {
LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e);
}
}
Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
if (connObjectKeyItem.isPresent()) {
Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.get().getExtAttrName(), attributes);
if (connObjectKeyExtAttr != null) {
attributes.remove(connObjectKeyExtAttr);
attributes.add(AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey));
}
Name name = MappingUtils.evaluateNAME(any, provision, connObjectKey);
attributes.add(name);
if (connObjectKey != null && !connObjectKey.equals(name.getNameValue()) && connObjectKeyExtAttr == null) {
attributes.add(AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey));
}
}
if (enable != null) {
attributes.add(AttributeBuilder.buildEnabled(enable));
}
if (!changePwd) {
Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes);
if (pwdAttr != null) {
attributes.remove(pwdAttr);
}
}
return Pair.of(connObjectKey, attributes);
}
use of org.identityconnectors.framework.common.objects.Name in project syncope by apache.
the class MappingTest method anyConnObjectLink.
@Test
public void anyConnObjectLink() {
ExternalResource ldap = resourceDAO.find("resource-ldap");
assertNotNull(ldap);
Provision provision = ldap.getProvision(anyTypeDAO.findUser()).get();
assertNotNull(provision);
assertNotNull(provision.getMapping());
assertNotNull(provision.getMapping().getConnObjectLink());
User user = userDAO.findByUsername("rossini");
assertNotNull(user);
Name name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
assertEquals("uid=rossini,ou=people,o=isp", name.getNameValue());
provision.getMapping().setConnObjectLink("'uid=' + username + realm.replaceAll('/', ',o=') + ',ou=people,o=isp'");
name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
assertEquals("uid=rossini,o=even,ou=people,o=isp", name.getNameValue());
}
Aggregations