use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class AbstractAnyLogic method beforeUpdate.
protected Pair<P, List<LogicActions>> beforeUpdate(final P input, final String realmPath) {
Realm realm = realmDAO.findByFullPath(realmPath);
if (realm == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
sce.getElements().add(realmPath);
throw sce;
}
P mod = input;
List<LogicActions> actions = getActions(realm);
for (LogicActions action : actions) {
mod = action.beforeUpdate(mod);
}
LOG.debug("Input: {}\nOutput: {}\n", input, mod);
return ImmutablePair.of(mod, actions);
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class AbstractAnyLogic method beforeCreate.
protected Pair<TO, List<LogicActions>> beforeCreate(final TO input) {
Realm realm = realmDAO.findByFullPath(input.getRealm());
if (realm == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
sce.getElements().add(input.getRealm());
throw sce;
}
AnyType anyType = input instanceof UserTO ? anyTypeDAO.findUser() : input instanceof GroupTO ? anyTypeDAO.findGroup() : anyTypeDAO.find(input.getType());
if (anyType == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
sce.getElements().add(input.getType());
throw sce;
}
TO any = input;
templateUtils.apply(any, realm.getTemplate(anyType));
List<LogicActions> actions = getActions(realm);
for (LogicActions action : actions) {
any = action.beforeCreate(any);
}
LOG.debug("Input: {}\nOutput: {}\n", input, any);
return ImmutablePair.of(any, actions);
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class DefaultRealmPullResultHandler method link.
private List<ProvisioningReport> link(final SyncDelta delta, final List<String> keys, final boolean unlink) throws JobExecutionException {
if (!profile.getTask().isPerformUpdate()) {
LOG.debug("PullTask not configured for update");
finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
LOG.debug("About to link {}", keys);
final List<ProvisioningReport> results = new ArrayList<>();
for (String key : keys) {
LOG.debug("About to unassign resource {}", key);
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.NONE);
result.setAnyType(REALM_TYPE);
result.setStatus(ProvisioningReport.Status.SUCCESS);
result.setKey(key);
Realm realm = realmDAO.find(key);
RealmTO before = binder.getRealmTO(realm, true);
if (before == null) {
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(String.format("Realm '%s' not found", key));
} else {
result.setName(before.getFullPath());
}
Object output;
Result resultStatus;
if (!profile.isDryRun()) {
if (before == null) {
resultStatus = Result.FAILURE;
output = null;
} else {
try {
if (unlink) {
for (PullActions action : profile.getActions()) {
action.beforeUnlink(profile, delta, before);
}
} else {
for (PullActions action : profile.getActions()) {
action.beforeLink(profile, delta, before);
}
}
if (unlink) {
realm.getResources().remove(profile.getTask().getResource());
} else {
realm.add(profile.getTask().getResource());
}
output = update(delta, Collections.singletonList(key));
for (PullActions action : profile.getActions()) {
action.after(profile, delta, RealmTO.class.cast(output), result);
}
resultStatus = Result.SUCCESS;
LOG.debug("{} successfully updated", realm);
} catch (PropagationException e) {
// A propagation failure doesn't imply a pull failure.
// The propagation exception status will be reported into the propagation task execution.
LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
} catch (Exception e) {
throwIgnoreProvisionException(delta, e);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
}
}
finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta);
}
results.add(result);
}
return results;
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class PullUtils method match.
/**
* Finds internal realms based on external attributes and mapping.
*
* @param connObj external attributes
* @param orgUnit mapping
* @return list of matching realms' keys.
*/
public List<String> match(final ConnectorObject connObj, final OrgUnit orgUnit) {
String connObjectKey = null;
Optional<? extends OrgUnitItem> connObjectKeyItem = orgUnit.getConnObjectKeyItem();
if (connObjectKeyItem != null) {
Attribute connObjectKeyAttr = connObj.getAttributeByName(connObjectKeyItem.get().getExtAttrName());
if (connObjectKeyAttr != null) {
connObjectKey = AttributeUtil.getStringValue(connObjectKeyAttr);
}
}
if (connObjectKey == null) {
return Collections.emptyList();
}
for (ItemTransformer transformer : MappingUtils.getItemTransformers(connObjectKeyItem.get())) {
List<Object> output = transformer.beforePull(connObjectKeyItem.get(), null, Collections.<Object>singletonList(connObjectKey));
if (output != null && !output.isEmpty()) {
connObjectKey = output.get(0).toString();
}
}
List<String> result = new ArrayList<>();
Realm realm;
switch(connObjectKeyItem.get().getIntAttrName()) {
case "key":
realm = realmDAO.find(connObjectKey);
if (realm != null) {
result.add(realm.getKey());
}
break;
case "name":
result.addAll(realmDAO.findByName(connObjectKey).stream().map(Entity::getKey).collect(Collectors.toList()));
break;
case "fullpath":
realm = realmDAO.findByFullPath(connObjectKey);
if (realm != null) {
result.add(realm.getKey());
}
break;
default:
}
return result;
}
use of org.apache.syncope.core.persistence.api.entity.Realm in project syncope by apache.
the class DefaultRealmPushResultHandler method handle.
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public boolean handle(final String realmKey) {
Realm realm = null;
try {
realm = realmDAO.find(realmKey);
doHandle(realm);
return true;
} catch (IgnoreProvisionException e) {
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.NONE);
result.setAnyType(realm == null ? null : REALM_TYPE);
result.setStatus(ProvisioningReport.Status.IGNORE);
result.setKey(realmKey);
profile.getResults().add(result);
LOG.warn("Ignoring during push", e);
return true;
} catch (JobExecutionException e) {
LOG.error("Push failed", e);
return false;
}
}
Aggregations