use of org.apache.syncope.core.persistence.api.entity.AnyUtils 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.AnyUtils in project syncope by apache.
the class GoogleAppsPullActions method afterAll.
@Transactional
@Override
public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException {
googleAppsIds.forEach((key, value) -> {
User user = userDAO.find(key);
if (user == null) {
LOG.error("Could not find user {}, skipping", key);
} else {
AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
// 1. stores the __UID__ received by Google
PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
if (googleAppsId == null) {
LOG.error("Could not find schema googleAppsId, skipping");
} else {
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(value, anyUtils);
userDAO.save(user);
} catch (InvalidPlainAttrValueException e) {
LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), value, e);
}
} else {
LOG.debug("User {} has already a googleAppsId assigned: {}", user, attr.getValuesAsStrings());
}
}
}
});
}
use of org.apache.syncope.core.persistence.api.entity.AnyUtils 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.AnyUtils 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.AnyUtils in project syncope by apache.
the class AbstractPullResultHandler method doHandle.
/**
* Look into SyncDelta and take necessary profile.getActions() (create / update / delete) on any object(s).
*
* @param delta returned by the underlying profile.getConnector()
* @param provision provisioning info
* @throws JobExecutionException in case of pull failure.
*/
protected void doHandle(final SyncDelta delta, final Provision provision) throws JobExecutionException {
AnyUtils anyUtils = getAnyUtils();
LOG.debug("Process {} for {} as {}", delta.getDeltaType(), delta.getUid().getUidValue(), delta.getObject().getObjectClass());
SyncDelta processed = delta;
for (PullActions action : profile.getActions()) {
processed = action.preprocess(profile, processed);
}
LOG.debug("Transformed {} for {} as {}", processed.getDeltaType(), processed.getUid().getUidValue(), processed.getObject().getObjectClass());
try {
List<String> anyKeys = pullUtils.match(processed.getObject(), provision, anyUtils);
LOG.debug("Match(es) found for {} as {}: {}", processed.getUid().getUidValue(), processed.getObject().getObjectClass(), anyKeys);
if (anyKeys.size() > 1) {
switch(profile.getResAct()) {
case IGNORE:
throw new IllegalStateException("More than one match " + anyKeys);
case FIRSTMATCH:
anyKeys = anyKeys.subList(0, 1);
break;
case LASTMATCH:
anyKeys = anyKeys.subList(anyKeys.size() - 1, anyKeys.size());
break;
default:
}
}
if (SyncDeltaType.CREATE_OR_UPDATE == processed.getDeltaType()) {
if (anyKeys.isEmpty()) {
switch(profile.getTask().getUnmatchingRule()) {
case ASSIGN:
profile.getResults().addAll(assign(processed, provision, anyUtils));
break;
case PROVISION:
profile.getResults().addAll(provision(processed, provision, anyUtils));
break;
case IGNORE:
profile.getResults().addAll(ignore(processed, null, provision, false));
break;
default:
}
} else {
// update VirAttrCache
for (VirSchema virSchema : virSchemaDAO.findByProvision(provision)) {
Attribute attr = processed.getObject().getAttributeByName(virSchema.getExtAttrName());
for (String anyKey : anyKeys) {
if (attr == null) {
virAttrCache.expire(provision.getAnyType().getKey(), anyKey, virSchema.getKey());
} else {
VirAttrCacheValue cacheValue = new VirAttrCacheValue();
cacheValue.setValues(attr.getValue());
virAttrCache.put(provision.getAnyType().getKey(), anyKey, virSchema.getKey(), cacheValue);
}
}
}
switch(profile.getTask().getMatchingRule()) {
case UPDATE:
profile.getResults().addAll(update(processed, anyKeys, provision));
break;
case DEPROVISION:
profile.getResults().addAll(deprovision(processed, anyKeys, provision, false));
break;
case UNASSIGN:
profile.getResults().addAll(deprovision(processed, anyKeys, provision, true));
break;
case LINK:
profile.getResults().addAll(link(processed, anyKeys, provision, false));
break;
case UNLINK:
profile.getResults().addAll(link(processed, anyKeys, provision, true));
break;
case IGNORE:
profile.getResults().addAll(ignore(processed, anyKeys, provision, true));
break;
default:
}
}
} else if (SyncDeltaType.DELETE == processed.getDeltaType()) {
if (anyKeys.isEmpty()) {
finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, processed);
LOG.debug("No match found for deletion");
} else {
profile.getResults().addAll(delete(processed, anyKeys, provision));
}
}
} catch (IllegalStateException | IllegalArgumentException e) {
LOG.warn(e.getMessage());
}
}
Aggregations