use of org.apache.syncope.core.persistence.api.entity.PlainSchema 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.PlainSchema in project syncope by apache.
the class ElasticsearchAnySearchDAO method addSort.
private void addSort(final SearchRequestBuilder builder, final AnyTypeKind kind, final List<OrderByClause> orderBy) {
AnyUtils attrUtils = anyUtilsFactory.getInstance(kind);
orderBy.forEach(clause -> {
String sortName = null;
// Manage difference among external key attribute and internal JPA @Id
String fieldName = "key".equals(clause.getField()) ? "id" : clause.getField();
Field anyField = ReflectionUtils.findField(attrUtils.anyClass(), fieldName);
if (anyField == null) {
PlainSchema schema = schemaDAO.find(fieldName);
if (schema != null) {
sortName = fieldName;
}
} else {
sortName = fieldName;
}
if (sortName == null) {
LOG.warn("Cannot build any valid clause from {}", clause);
} else {
builder.addSort(sortName, SortOrder.valueOf(clause.getDirection().name()));
}
});
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class GoogleAppsPropagationActions method after.
@Transactional
@Override
public void after(final PropagationTask task, final TaskExec execution, final ConnectorObject afterObj) {
if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
return;
}
if (AnyTypeKind.USER != task.getAnyTypeKind()) {
return;
}
User user = userDAO.find(task.getEntityKey());
if (user == null) {
LOG.error("Could not find user {}, skipping", task.getEntityKey());
} else {
boolean modified = false;
AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
if (googleAppsId == null) {
LOG.error("Could not find schema {}, skipping", getGoogleAppsIdSchema());
} else {
// set back the __UID__ received by Google
UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
if (attr == null) {
attr = entityFactory.newEntity(UPlainAttr.class);
attr.setSchema(googleAppsId);
attr.setOwner(user);
user.add(attr);
try {
attr.add(afterObj.getUid().getUidValue(), anyUtils);
modified = true;
} catch (InvalidPlainAttrValueException e) {
LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), afterObj.getUid().getUidValue(), e);
}
} else {
LOG.debug("User {} has already {} assigned: {}", user, googleAppsId.getKey(), attr.getValuesAsStrings());
}
}
if (modified) {
userDAO.save(user);
}
}
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class ConfigurationDataBinderImpl method getAttr.
@Override
public CPlainAttr getAttr(final AttrTO attrTO) {
PlainSchema schema = getPlainSchema(attrTO.getSchema());
if (schema == null) {
throw new NotFoundException("Conf schema " + attrTO.getSchema());
} else {
SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
CPlainAttr attr = entityFactory.newEntity(CPlainAttr.class);
attr.setSchema(schema);
fillAttr(attrTO.getValues(), schema, attr, invalidValues);
if (!invalidValues.isEmpty()) {
throw invalidValues;
}
return attr;
}
}
use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.
the class AnyTypeClassDataBinderImpl method update.
@Override
public void update(final AnyTypeClass anyTypeClass, final AnyTypeClassTO anyTypeClassTO) {
if (anyTypeClass.getKey() == null) {
anyTypeClass.setKey(anyTypeClassTO.getKey());
}
plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
schema.setAnyTypeClass(null);
});
anyTypeClass.getPlainSchemas().clear();
anyTypeClassTO.getPlainSchemas().forEach(schemaName -> {
PlainSchema schema = plainSchemaDAO.find(schemaName);
if (schema == null || schema.getAnyTypeClass() != null) {
LOG.debug("Invalid or already in use" + PlainSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
} else {
anyTypeClass.add(schema);
}
});
derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach((schema) -> {
schema.setAnyTypeClass(null);
});
anyTypeClass.getDerSchemas().clear();
anyTypeClassTO.getDerSchemas().forEach(schemaName -> {
DerSchema schema = derSchemaDAO.find(schemaName);
if (schema == null || schema.getAnyTypeClass() != null) {
LOG.debug("Invalid or already in use" + DerSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
} else {
anyTypeClass.add(schema);
}
});
virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
schema.setAnyTypeClass(null);
});
anyTypeClass.getVirSchemas().clear();
anyTypeClassTO.getVirSchemas().forEach(schemaName -> {
VirSchema schema = virSchemaDAO.find(schemaName);
if (schema == null || schema.getAnyTypeClass() != null) {
LOG.debug("Invalid or already in use" + VirSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
} else {
anyTypeClass.add(schema);
}
});
}
Aggregations