use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.
the class NotificationManagerImpl method getRecipientEmail.
private String getRecipientEmail(final String recipientAttrName, final User user) {
String email = null;
IntAttrName intAttrName;
try {
intAttrName = intAttrNameParser.parse(recipientAttrName, AnyTypeKind.USER);
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified as recipient, ignoring", recipientAttrName, e);
return email;
}
if ("username".equals(intAttrName.getField())) {
email = user.getUsername();
} else if (intAttrName.getSchemaType() != null) {
UMembership membership = null;
if (intAttrName.getMembershipOfGroup() != null) {
Group group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
if (group != null) {
membership = user.getMembership(group.getKey()).orElse(null);
}
}
switch(intAttrName.getSchemaType()) {
case PLAIN:
Optional<? extends UPlainAttr> attr = membership == null ? user.getPlainAttr(recipientAttrName) : user.getPlainAttr(recipientAttrName, membership);
if (attr.isPresent()) {
email = attr.get().getValuesAsStrings().isEmpty() ? null : attr.get().getValuesAsStrings().get(0);
}
break;
case DERIVED:
DerSchema schema = derSchemaDAO.find(recipientAttrName);
if (schema == null) {
LOG.warn("Ignoring non existing {} {}", DerSchema.class.getSimpleName(), recipientAttrName);
} else {
email = membership == null ? derAttrHander.getValue(user, schema) : derAttrHander.getValue(user, membership, schema);
}
break;
case VIRTUAL:
VirSchema virSchema = virSchemaDAO.find(recipientAttrName);
if (virSchema == null) {
LOG.warn("Ignoring non existing {} {}", VirSchema.class.getSimpleName(), recipientAttrName);
} else {
List<String> virAttrValues = membership == null ? virAttrHander.getValues(user, virSchema) : virAttrHander.getValues(user, membership, virSchema);
email = virAttrValues.isEmpty() ? null : virAttrValues.get(0);
}
break;
default:
}
}
return email;
}
use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.
the class IntAttrNameParser method parse.
@Transactional(readOnly = true)
public IntAttrName parse(final String intAttrName, final AnyTypeKind provisionAnyTypeKind) throws ParseException {
IntAttrName result = new IntAttrName();
Matcher matcher;
if (intAttrName.indexOf('.') == -1) {
matcher = PRIVILEGE_PATTERN.matcher(intAttrName);
if (matcher.matches()) {
result.setAnyTypeKind(AnyTypeKind.USER);
result.setPrivilegesOfApplication(matcher.group(1));
} else {
result.setAnyTypeKind(provisionAnyTypeKind);
setFieldOrSchemaName(intAttrName, result.getAnyTypeKind(), result);
}
} else {
matcher = ENCLOSING_GROUP_PATTERN.matcher(intAttrName);
if (matcher.matches()) {
result.setAnyTypeKind(AnyTypeKind.GROUP);
result.setEnclosingGroup(matcher.group(1));
setFieldOrSchemaName(matcher.group(2), result.getAnyTypeKind(), result);
} else {
matcher = RELATED_ANY_OBJECT_PATTERN.matcher(intAttrName);
if (matcher.matches()) {
result.setAnyTypeKind(AnyTypeKind.ANY_OBJECT);
result.setRelatedAnyObject(matcher.group(1));
setFieldOrSchemaName(matcher.group(2), result.getAnyTypeKind(), result);
} else {
matcher = MEMBERSHIP_PATTERN.matcher(intAttrName);
if (matcher.matches()) {
result.setAnyTypeKind(AnyTypeKind.USER);
result.setMembershipOfGroup(matcher.group(1));
setFieldOrSchemaName(matcher.group(2), result.getAnyTypeKind(), result);
} else {
throw new ParseException("Unparsable expression: " + intAttrName, 0);
}
}
}
}
return result;
}
use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.
the class AbstractAnyDataBinder method evaluateMandatoryCondition.
private List<String> evaluateMandatoryCondition(final Provision provision, final Any<?> any) {
List<String> missingAttrNames = new ArrayList<>();
MappingUtils.getPropagationItems(provision.getMapping().getItems()).forEach(mapItem -> {
IntAttrName intAttrName = null;
try {
intAttrName = intAttrNameParser.parse(mapItem.getIntAttrName(), provision.getAnyType().getKind());
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}', ignoring", mapItem.getIntAttrName(), e);
}
if (intAttrName != null && intAttrName.getSchemaType() != null) {
List<PlainAttrValue> values = mappingManager.getIntValues(provision, mapItem, intAttrName, any);
if (values.isEmpty() && JexlUtils.evaluateMandatoryCondition(mapItem.getMandatoryCondition(), any)) {
missingAttrNames.add(mapItem.getIntAttrName());
}
}
});
return missingAttrNames;
}
use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.
the class SAML2IdPDataBinderImpl method populateItems.
private void populateItems(final SAML2IdPTO idpTO, final SAML2IdP idp, final AnyTypeClassTO allowedSchemas) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
SyncopeClientException invalidMapping = SyncopeClientException.build(ClientExceptionType.InvalidMapping);
SyncopeClientException requiredValuesMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
for (ItemTO itemTO : idpTO.getItems()) {
if (itemTO == null) {
LOG.error("Null {}", ItemTO.class.getSimpleName());
invalidMapping.getElements().add("Null " + ItemTO.class.getSimpleName());
} else if (itemTO.getIntAttrName() == null) {
requiredValuesMissing.getElements().add("intAttrName");
scce.addException(requiredValuesMissing);
} else {
IntAttrName intAttrName = null;
try {
intAttrName = intAttrNameParser.parse(itemTO.getIntAttrName(), AnyTypeKind.USER);
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified, ignoring", itemTO.getIntAttrName(), e);
}
if (intAttrName == null || intAttrName.getSchemaType() == null && intAttrName.getField() == null) {
LOG.error("'{}' not existing", itemTO.getIntAttrName());
invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not existing");
} else {
boolean allowed = true;
if (intAttrName.getSchemaType() != null && intAttrName.getEnclosingGroup() == null && intAttrName.getRelatedAnyObject() == null) {
switch(intAttrName.getSchemaType()) {
case PLAIN:
allowed = allowedSchemas.getPlainSchemas().contains(intAttrName.getSchemaName());
break;
case DERIVED:
allowed = allowedSchemas.getDerSchemas().contains(intAttrName.getSchemaName());
break;
case VIRTUAL:
allowed = allowedSchemas.getVirSchemas().contains(intAttrName.getSchemaName());
break;
default:
}
}
if (allowed) {
// no mandatory condition implies mandatory condition false
if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null ? "false" : itemTO.getMandatoryCondition())) {
SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(ClientExceptionType.InvalidValues);
invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
scce.addException(invalidMandatoryCondition);
}
SAML2IdPItem item = entityFactory.newEntity(SAML2IdPItem.class);
BeanUtils.copyProperties(itemTO, item, ITEM_IGNORE_PROPERTIES);
item.setIdP(idp);
item.setPurpose(MappingPurpose.NONE);
if (item.isConnObjectKey()) {
if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
invalidMapping.getElements().add("Virtual attributes cannot be set as ConnObjectKey");
}
if ("password".equals(intAttrName.getField())) {
invalidMapping.getElements().add("Password attributes cannot be set as ConnObjectKey");
}
idp.setConnObjectKeyItem(item);
} else {
idp.add(item);
}
} else {
LOG.error("'{}' not allowed", itemTO.getIntAttrName());
invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not allowed");
}
}
}
}
if (!invalidMapping.getElements().isEmpty()) {
scce.addException(invalidMapping);
}
if (scce.hasExceptions()) {
throw scce;
}
}
use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.
the class IntAttrNameParserTest method privileges.
@Test
public void privileges() throws ParseException {
IntAttrName intAttrName = intAttrNameParser.parse("privileges[mightyApp]", AnyTypeKind.USER);
assertNotNull(intAttrName);
assertEquals(AnyTypeKind.USER, intAttrName.getAnyTypeKind());
assertNull(intAttrName.getField());
assertNull(intAttrName.getSchemaName());
assertNull(intAttrName.getSchemaType());
assertNull(intAttrName.getEnclosingGroup());
assertNull(intAttrName.getRelatedAnyObject());
assertEquals("mightyApp", intAttrName.getPrivilegesOfApplication());
}
Aggregations