use of org.apache.syncope.core.persistence.api.entity.PlainAttrValue in project syncope by apache.
the class ConfigurationDataBinderImpl method fillAttr.
private void fillAttr(final List<String> values, final PlainSchema schema, final CPlainAttr attr, final SyncopeClientException invalidValues) {
// if schema is multivalue, all values are considered for addition;
// otherwise only the fist one - if provided - is considered
List<String> valuesProvided = schema.isMultivalue() ? values : (values.isEmpty() ? Collections.<String>emptyList() : Collections.singletonList(values.iterator().next()));
if (valuesProvided.isEmpty()) {
JexlContext jexlContext = new MapContext();
JexlUtils.addPlainAttrsToContext(confDAO.get().getPlainAttrs(), jexlContext);
if (!schema.isReadonly() && Boolean.parseBoolean(JexlUtils.evaluate(schema.getMandatoryCondition(), jexlContext))) {
LOG.error("Mandatory schema " + schema.getKey() + " not provided with values");
SyncopeClientException reqValMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
reqValMissing.getElements().add(schema.getKey());
throw reqValMissing;
}
}
for (String value : valuesProvided) {
if (value == null || value.isEmpty()) {
LOG.debug("Null value for {}, ignoring", schema.getKey());
} else {
try {
PlainAttrValue attrValue;
if (schema.isUniqueConstraint()) {
attrValue = entityFactory.newEntity(CPlainAttrUniqueValue.class);
((PlainAttrUniqueValue) attrValue).setSchema(schema);
} else {
attrValue = entityFactory.newEntity(CPlainAttrValue.class);
}
attr.add(value, attrValue);
} catch (InvalidPlainAttrValueException e) {
LOG.warn("Invalid value for attribute " + schema.getKey() + ": " + value, e);
invalidValues.getElements().add(schema.getKey() + ": " + value + " - " + e.getMessage());
}
}
}
}
use of org.apache.syncope.core.persistence.api.entity.PlainAttrValue in project syncope by apache.
the class AbstractAnySearchDAO method check.
protected Triple<PlainSchema, PlainAttrValue, AnyCond> check(final AnyCond cond, final AnyTypeKind kind) {
AnyCond condClone = SerializationUtils.clone(cond);
AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
// Keeps track of difference between entity's getKey() and JPA @Id fields
if ("key".equals(condClone.getSchema())) {
condClone.setSchema("id");
}
Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), condClone.getSchema());
if (anyField == null) {
LOG.warn("Ignoring invalid schema '{}'", condClone.getSchema());
throw new IllegalArgumentException();
}
PlainSchema schema = new JPAPlainSchema();
schema.setKey(anyField.getName());
for (AttrSchemaType attrSchemaType : AttrSchemaType.values()) {
if (anyField.getType().isAssignableFrom(attrSchemaType.getType())) {
schema.setType(attrSchemaType);
}
}
// Deal with any Integer fields logically mapping to boolean values
boolean foundBooleanMin = false;
boolean foundBooleanMax = false;
if (Integer.class.equals(anyField.getType())) {
for (Annotation annotation : anyField.getAnnotations()) {
if (Min.class.equals(annotation.annotationType())) {
foundBooleanMin = ((Min) annotation).value() == 0;
} else if (Max.class.equals(annotation.annotationType())) {
foundBooleanMax = ((Max) annotation).value() == 1;
}
}
}
if (foundBooleanMin && foundBooleanMax) {
schema.setType(AttrSchemaType.Boolean);
}
// Deal with any fields representing relationships to other entities
if (anyField.getType().getAnnotation(Entity.class) != null) {
Method relMethod = null;
try {
relMethod = ClassUtils.getPublicMethod(anyField.getType(), "getKey", new Class<?>[0]);
} catch (Exception e) {
LOG.error("Could not find {}#getKey", anyField.getType(), e);
}
if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType())) {
condClone.setSchema(condClone.getSchema() + "_id");
schema.setType(AttrSchemaType.String);
}
}
PlainAttrValue attrValue = attrUtils.newPlainAttrValue();
if (condClone.getType() != AttributeCond.Type.LIKE && condClone.getType() != AttributeCond.Type.ILIKE && condClone.getType() != AttributeCond.Type.ISNULL && condClone.getType() != AttributeCond.Type.ISNOTNULL) {
try {
((JPAPlainSchema) schema).validator().validate(condClone.getExpression(), attrValue);
} catch (ValidationException e) {
LOG.error("Could not validate expression '" + condClone.getExpression() + "'", e);
throw new IllegalArgumentException();
}
}
return Triple.of(schema, attrValue, condClone);
}
use of org.apache.syncope.core.persistence.api.entity.PlainAttrValue in project syncope by apache.
the class AbstractAnySearchDAO method check.
protected Pair<PlainSchema, PlainAttrValue> check(final AttributeCond cond, final AnyTypeKind kind) {
AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
PlainSchema schema = schemaDAO.find(cond.getSchema());
if (schema == null) {
LOG.warn("Ignoring invalid schema '{}'", cond.getSchema());
throw new IllegalArgumentException();
}
PlainAttrValue attrValue = attrUtils.newPlainAttrValue();
try {
if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ILIKE && cond.getType() != AttributeCond.Type.ISNULL && cond.getType() != AttributeCond.Type.ISNOTNULL) {
((JPAPlainSchema) schema).validator().validate(cond.getExpression(), attrValue);
}
} catch (ValidationException e) {
LOG.error("Could not validate expression '" + cond.getExpression() + "'", e);
throw new IllegalArgumentException();
}
return Pair.of(schema, attrValue);
}
use of org.apache.syncope.core.persistence.api.entity.PlainAttrValue in project syncope by apache.
the class SAML2UserManager method findMatchingUser.
@Transactional(readOnly = true)
public List<String> findMatchingUser(final String keyValue, final String idpKey) {
List<String> result = new ArrayList<>();
SAML2IdP idp = idpDAO.find(idpKey);
if (idp == null) {
LOG.warn("Invalid IdP: {}", idpKey);
return result;
}
String transformed = keyValue;
for (ItemTransformer transformer : MappingUtils.getItemTransformers(idp.getConnObjectKeyItem().get())) {
List<Object> output = transformer.beforePull(null, null, Collections.<Object>singletonList(transformed));
if (output != null && !output.isEmpty()) {
transformed = output.get(0).toString();
}
}
IntAttrName intAttrName;
try {
intAttrName = intAttrNameParser.parse(idp.getConnObjectKeyItem().get().getIntAttrName(), AnyTypeKind.USER);
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified, ignoring", idp.getConnObjectKeyItem().get().getIntAttrName(), e);
return result;
}
if (intAttrName.getField() != null) {
switch(intAttrName.getField()) {
case "key":
User byKey = userDAO.find(transformed);
if (byKey != null) {
result.add(byKey.getUsername());
}
break;
case "username":
User byUsername = userDAO.findByUsername(transformed);
if (byUsername != null) {
result.add(byUsername.getUsername());
}
break;
default:
}
} else if (intAttrName.getSchemaType() != null) {
switch(intAttrName.getSchemaType()) {
case PLAIN:
PlainAttrValue value = entityFactory.newEntity(UPlainAttrValue.class);
PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName());
if (schema == null) {
value.setStringValue(transformed);
} else {
try {
value.parseValue(schema, transformed);
} catch (ParsingValidationException e) {
LOG.error("While parsing provided key value {}", transformed, e);
value.setStringValue(transformed);
}
}
result.addAll(userDAO.findByPlainAttrValue(intAttrName.getSchemaName(), value).stream().map(user -> user.getUsername()).collect(Collectors.toList()));
break;
case DERIVED:
result.addAll(userDAO.findByDerAttrValue(intAttrName.getSchemaName(), transformed).stream().map(user -> user.getUsername()).collect(Collectors.toList()));
break;
default:
}
}
return result;
}
use of org.apache.syncope.core.persistence.api.entity.PlainAttrValue in project syncope by apache.
the class MappingManagerImpl method getConnObjectKeyValue.
@Transactional(readOnly = true)
@Override
public Optional<String> getConnObjectKeyValue(final Any<?> any, final Provision provision) {
MappingItem mapItem = provision.getMapping().getConnObjectKeyItem().get();
List<PlainAttrValue> values;
try {
values = getIntValues(provision, mapItem, intAttrNameParser.parse(mapItem.getIntAttrName(), provision.getAnyType().getKind()), any);
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified, ignoring", mapItem.getIntAttrName(), e);
values = Collections.emptyList();
}
return Optional.ofNullable(values.isEmpty() ? null : values.get(0).getValueAsString());
}
Aggregations