use of org.apache.syncope.core.provisioning.api.data.ItemTransformer in project syncope by apache.
the class SAML2UserManager method fill.
public void fill(final String idpKey, final SAML2LoginResponseTO responseTO, final UserTO userTO) {
SAML2IdP idp = idpDAO.find(idpKey);
if (idp == null) {
LOG.warn("Invalid IdP: {}", idpKey);
return;
}
idp.getItems().forEach(item -> {
List<String> values = Collections.emptyList();
Optional<AttrTO> samlAttr = responseTO.getAttr(item.getExtAttrName());
if (samlAttr.isPresent() && !samlAttr.get().getValues().isEmpty()) {
values = samlAttr.get().getValues();
List<Object> transformed = new ArrayList<>(values);
for (ItemTransformer transformer : MappingUtils.getItemTransformers(item)) {
transformed = transformer.beforePull(null, userTO, transformed);
}
values.clear();
for (Object value : transformed) {
values.add(value.toString());
}
}
IntAttrName intAttrName = null;
try {
intAttrName = intAttrNameParser.parse(item.getIntAttrName(), AnyTypeKind.USER);
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified, ignoring", item.getIntAttrName(), e);
}
if (intAttrName != null && intAttrName.getField() != null) {
switch(intAttrName.getField()) {
case "username":
if (!values.isEmpty()) {
userTO.setUsername(values.get(0));
}
break;
default:
LOG.warn("Unsupported: {}", intAttrName.getField());
}
} else if (intAttrName != null && intAttrName.getSchemaType() != null) {
switch(intAttrName.getSchemaType()) {
case PLAIN:
Optional<AttrTO> attr = userTO.getPlainAttr(intAttrName.getSchemaName());
if (!attr.isPresent()) {
attr = Optional.of(new AttrTO.Builder().schema(intAttrName.getSchemaName()).build());
userTO.getPlainAttrs().add(attr.get());
} else {
attr.get().getValues().clear();
}
attr.get().getValues().addAll(values);
break;
default:
LOG.warn("Unsupported: {} {}", intAttrName.getSchemaType(), intAttrName.getSchemaName());
}
}
});
}
use of org.apache.syncope.core.provisioning.api.data.ItemTransformer in project syncope by apache.
the class MappingManagerImpl method setIntValues.
@Override
public void setIntValues(final Item orgUnitItem, final Attribute attr, final RealmTO realmTO) {
List<Object> values = null;
if (attr != null) {
values = attr.getValue();
for (ItemTransformer transformer : MappingUtils.getItemTransformers(orgUnitItem)) {
values = transformer.beforePull(orgUnitItem, realmTO, values);
}
}
if (values != null && !values.isEmpty() && values.get(0) != null) {
switch(orgUnitItem.getIntAttrName()) {
case "name":
realmTO.setName(values.get(0).toString());
break;
case "fullpath":
String parentFullPath = StringUtils.substringBeforeLast(values.get(0).toString(), "/");
Realm parent = realmDAO.findByFullPath(parentFullPath);
if (parent == null) {
LOG.warn("Could not find Realm with path {}, ignoring", parentFullPath);
} else {
realmTO.setParent(parent.getFullPath());
}
break;
default:
}
}
}
use of org.apache.syncope.core.provisioning.api.data.ItemTransformer in project syncope by apache.
the class MappingUtils method getItemTransformers.
public static List<ItemTransformer> getItemTransformers(final Item item) {
List<ItemTransformer> result = new ArrayList<>();
// First consider the JEXL transformation expressions
if (StringUtils.isNotBlank(item.getPropagationJEXLTransformer()) || StringUtils.isNotBlank(item.getPullJEXLTransformer())) {
JEXLItemTransformer jexlTransformer = (JEXLItemTransformer) ApplicationContextProvider.getBeanFactory().createBean(JEXLItemTransformerImpl.class, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false);
jexlTransformer.setPropagationJEXL(item.getPropagationJEXLTransformer());
jexlTransformer.setPullJEXL(item.getPullJEXLTransformer());
result.add(jexlTransformer);
}
// Then other custom transformers
item.getTransformers().forEach(impl -> {
try {
result.add(ImplementationManager.build(impl));
} catch (Exception e) {
LOG.error("While building {}", impl, e);
}
});
return result;
}
Aggregations