Search in sources :

Example 6 with RealmTO

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;
}
Also used : PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) RealmTO(org.apache.syncope.common.lib.to.RealmTO) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) Realm(org.apache.syncope.core.persistence.api.entity.Realm) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Example 7 with RealmTO

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();
}
Also used : Response(javax.ws.rs.core.Response) RealmTO(org.apache.syncope.common.lib.to.RealmTO) URI(java.net.URI)

Example 8 with RealmTO

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());
    }
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) RealmTO(org.apache.syncope.common.lib.to.RealmTO) Any(org.apache.syncope.core.persistence.api.entity.Any) JexlException(org.apache.commons.jexl3.JexlException) IntrospectionException(java.beans.IntrospectionException) Field(java.lang.reflect.Field) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 9 with RealmTO

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;
}
Also used : RealmTO(org.apache.syncope.common.lib.to.RealmTO)

Example 10 with 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());
}
Also used : StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) PropagationManager(org.apache.syncope.core.provisioning.api.propagation.PropagationManager) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RealmTO(org.apache.syncope.common.lib.to.RealmTO) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) RealmDataBinder(org.apache.syncope.core.provisioning.api.data.RealmDataBinder) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Method(java.lang.reflect.Method) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Set(java.util.Set) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) List(java.util.List) Component(org.springframework.stereotype.Component) PropagationTaskExecutor(org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RealmTO (org.apache.syncope.common.lib.to.RealmTO)30 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)12 Realm (org.apache.syncope.core.persistence.api.entity.Realm)10 ArrayList (java.util.ArrayList)7 Response (javax.ws.rs.core.Response)7 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)7 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)7 Test (org.junit.jupiter.api.Test)7 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)6 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)6 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)4 Result (org.apache.syncope.common.lib.types.AuditElements.Result)4 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)4 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)4 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)4 JobExecutionException (org.quartz.JobExecutionException)4 UserTO (org.apache.syncope.common.lib.to.UserTO)3 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 PropagationReporter (org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)3