use of org.apache.syncope.common.lib.to.RealmTO 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.common.lib.to.RealmTO in project syncope by apache.
the class RealmServiceImpl method create.
@Override
public Response create(final String parentPath, final RealmTO realmTO) {
ProvisioningResult<RealmTO> created = logic.create(StringUtils.prependIfMissing(parentPath, SyncopeConstants.ROOT_REALM), realmTO);
URI location = uriInfo.getAbsolutePathBuilder().path(created.getEntity().getName()).build();
Response.ResponseBuilder builder = Response.created(location).header(RESTHeaders.RESOURCE_KEY, created.getEntity().getFullPath());
return applyPreference(created, builder).build();
}
use of org.apache.syncope.common.lib.to.RealmTO in project syncope by apache.
the class JexlUtils method addFieldsToContext.
public static void addFieldsToContext(final Object object, final JexlContext jexlContext) {
Set<PropertyDescriptor> cached = FIELD_CACHE.get(object.getClass());
if (cached == null) {
cached = new HashSet<>();
FIELD_CACHE.put(object.getClass(), cached);
try {
for (PropertyDescriptor desc : Introspector.getBeanInfo(object.getClass()).getPropertyDescriptors()) {
if ((!desc.getName().startsWith("pc")) && (!ArrayUtils.contains(IGNORE_FIELDS, desc.getName())) && (!Iterable.class.isAssignableFrom(desc.getPropertyType())) && (!desc.getPropertyType().isArray())) {
cached.add(desc);
}
}
} catch (IntrospectionException ie) {
LOG.error("Reading class attributes error", ie);
}
}
for (PropertyDescriptor desc : cached) {
String fieldName = desc.getName();
Class<?> fieldType = desc.getPropertyType();
try {
Object fieldValue;
if (desc.getReadMethod() == null) {
final Field field = object.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
fieldValue = field.get(object);
} else {
fieldValue = desc.getReadMethod().invoke(object);
}
fieldValue = fieldValue == null ? StringUtils.EMPTY : (fieldType.equals(Date.class) ? FormatUtils.format((Date) fieldValue, false) : fieldValue);
jexlContext.set(fieldName, fieldValue);
LOG.debug("Add field {} with value {}", fieldName, fieldValue);
} catch (Exception iae) {
LOG.error("Reading '{}' value error", fieldName, iae);
}
}
if (object instanceof Any && ((Any<?>) object).getRealm() != null) {
jexlContext.set("realm", ((Any<?>) object).getRealm().getFullPath());
} else if (object instanceof AnyTO && ((AnyTO) object).getRealm() != null) {
jexlContext.set("realm", ((AnyTO) object).getRealm());
} else if (object instanceof Realm) {
jexlContext.set("fullPath", ((Realm) object).getFullPath());
} else if (object instanceof RealmTO) {
jexlContext.set("fullPath", ((RealmTO) object).getFullPath());
}
}
use of org.apache.syncope.common.lib.to.RealmTO in project syncope by apache.
the class RealmDataBinderImpl method getRealmTO.
@Override
public RealmTO getRealmTO(final Realm realm, final boolean admin) {
RealmTO realmTO = new RealmTO();
realmTO.setKey(realm.getKey());
realmTO.setName(realm.getName());
realmTO.setParent(realm.getParent() == null ? null : realm.getParent().getKey());
realmTO.setFullPath(realm.getFullPath());
if (admin) {
realmTO.setAccountPolicy(realm.getAccountPolicy() == null ? null : realm.getAccountPolicy().getKey());
realmTO.setPasswordPolicy(realm.getPasswordPolicy() == null ? null : realm.getPasswordPolicy().getKey());
realm.getActions().forEach(action -> {
realmTO.getActions().add(action.getKey());
});
realm.getTemplates().forEach(template -> {
realmTO.getTemplates().put(template.getAnyType().getKey(), template.get());
});
realm.getResources().forEach(resource -> {
realmTO.getResources().add(resource.getKey());
});
}
return realmTO;
}
use of org.apache.syncope.common.lib.to.RealmTO in project syncope by apache.
the class RealmLogic method list.
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public List<RealmTO> list(final String fullPath) {
Realm realm = realmDAO.findByFullPath(fullPath);
if (realm == null) {
LOG.error("Could not find realm '" + fullPath + "'");
throw new NotFoundException(fullPath);
}
final boolean admin = AuthContextUtils.getAuthorizations().keySet().contains(StandardEntitlement.REALM_LIST);
return realmDAO.findDescendants(realm).stream().map(descendant -> binder.getRealmTO(descendant, admin)).collect(Collectors.toList());
}
Aggregations