Search in sources :

Example 6 with ProvisioningResult

use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.

the class AbstractAnyLogic method afterUpdate.

protected ProvisioningResult<TO> afterUpdate(final TO input, final List<PropagationStatus> statuses, final List<LogicActions> actions, final boolean authDynRealms, final Set<String> dynRealmsBefore) {
    Set<String> dynRealmsAfter = new HashSet<>(input.getDynRealms());
    if (authDynRealms && !dynRealmsBefore.equals(dynRealmsAfter)) {
        throw new DelegatedAdministrationException(this instanceof UserLogic ? AnyTypeKind.USER : this instanceof GroupLogic ? AnyTypeKind.GROUP : AnyTypeKind.ANY_OBJECT, input.getKey());
    }
    TO any = input;
    for (LogicActions action : actions) {
        any = action.afterUpdate(any);
    }
    ProvisioningResult<TO> result = new ProvisioningResult<>();
    result.setEntity(any);
    result.getPropagationStatuses().addAll(statuses);
    return result;
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) AnyTO(org.apache.syncope.common.lib.to.AnyTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) UserTO(org.apache.syncope.common.lib.to.UserTO) LogicActions(org.apache.syncope.core.provisioning.api.LogicActions) HashSet(java.util.HashSet)

Example 7 with ProvisioningResult

use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.

the class AnyObjectLogic method deprovision.

@Override
public ProvisioningResult<AnyObjectTO> deprovision(final String key, final Collection<String> resources, final boolean nullPriorityAsync) {
    // security checks
    AnyObjectTO anyObjectTO = binder.getAnyObjectTO(key);
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.UPDATE.getFor(anyObjectTO.getType())), anyObjectTO.getRealm());
    securityChecks(effectiveRealms, anyObjectTO.getRealm(), anyObjectTO.getKey());
    List<PropagationStatus> statuses = provisioningManager.deprovision(key, resources, nullPriorityAsync);
    ProvisioningResult<AnyObjectTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getAnyObjectTO(key));
    result.getPropagationStatuses().addAll(statuses);
    return result;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus)

Example 8 with ProvisioningResult

use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.

the class AnyObjectLogic method provision.

@Override
public ProvisioningResult<AnyObjectTO> provision(final String key, final Collection<String> resources, final boolean changePwd, final String password, final boolean nullPriorityAsync) {
    // security checks
    AnyObjectTO anyObjectTO = binder.getAnyObjectTO(key);
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.UPDATE.getFor(anyObjectTO.getType())), anyObjectTO.getRealm());
    securityChecks(effectiveRealms, anyObjectTO.getRealm(), anyObjectTO.getKey());
    List<PropagationStatus> statuses = provisioningManager.provision(key, resources, nullPriorityAsync);
    ProvisioningResult<AnyObjectTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getAnyObjectTO(key));
    result.getPropagationStatuses().addAll(statuses);
    return result;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus)

Example 9 with ProvisioningResult

use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.

the class NotificationManagerImpl method createTasks.

@Override
public List<NotificationTask> createTasks(final AuditElements.EventCategoryType type, final String category, final String subcategory, final String event, final Result condition, final Object before, final Object output, final Object... input) {
    Any<?> any = null;
    if (before instanceof UserTO) {
        any = userDAO.find(((UserTO) before).getKey());
    } else if (output instanceof UserTO) {
        any = userDAO.find(((UserTO) output).getKey());
    } else if (output instanceof Pair && ((Pair) output).getRight() instanceof UserTO) {
        any = userDAO.find(((UserTO) ((Pair) output).getRight()).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof UserTO) {
        any = userDAO.find(((ProvisioningResult) output).getEntity().getKey());
    } else if (before instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((AnyObjectTO) before).getKey());
    } else if (output instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((AnyObjectTO) output).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((ProvisioningResult) output).getEntity().getKey());
    } else if (before instanceof GroupTO) {
        any = groupDAO.find(((GroupTO) before).getKey());
    } else if (output instanceof GroupTO) {
        any = groupDAO.find(((GroupTO) output).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof GroupTO) {
        any = groupDAO.find(((ProvisioningResult) output).getEntity().getKey());
    }
    AnyType anyType = any == null ? null : any.getType();
    LOG.debug("Search notification for [{}]{}", anyType, any);
    List<NotificationTask> notifications = new ArrayList<>();
    for (Notification notification : notificationDAO.findAll()) {
        if (LOG.isDebugEnabled()) {
            notification.getAbouts().forEach(about -> {
                LOG.debug("Notification about {} defined: {}", about.getAnyType(), about.get());
            });
        }
        if (notification.isActive()) {
            String currentEvent = AuditLoggerName.buildEvent(type, category, subcategory, event, condition);
            if (!notification.getEvents().contains(currentEvent)) {
                LOG.debug("No events found about {}", any);
            } else if (anyType == null || any == null || !notification.getAbout(anyType).isPresent() || searchDAO.matches(any, SearchCondConverter.convert(notification.getAbout(anyType).get().get()))) {
                LOG.debug("Creating notification task for event {} about {}", currentEvent, any);
                final Map<String, Object> model = new HashMap<>();
                model.put("type", type);
                model.put("category", category);
                model.put("subcategory", subcategory);
                model.put("event", event);
                model.put("condition", condition);
                model.put("before", before);
                model.put("output", output);
                model.put("input", input);
                if (any instanceof User) {
                    model.put("user", userDataBinder.getUserTO((User) any, true));
                } else if (any instanceof Group) {
                    model.put("group", groupDataBinder.getGroupTO((Group) any, true));
                } else if (any instanceof AnyObject) {
                    model.put("group", anyObjectDataBinder.getAnyObjectTO((AnyObject) any, true));
                }
                NotificationTask notificationTask = getNotificationTask(notification, any, model);
                notificationTask = taskDAO.save(notificationTask);
                notifications.add(notificationTask);
            }
        } else {
            LOG.debug("Notification {} is not active, task will not be created", notification.getKey());
        }
    }
    return notifications;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) User(org.apache.syncope.core.persistence.api.entity.user.User) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ArrayList(java.util.ArrayList) Notification(org.apache.syncope.core.persistence.api.entity.Notification) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.commons.lang3.tuple.Pair)

Example 10 with ProvisioningResult

use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.

the class UserRestClient method suspend.

public BulkActionResult suspend(final String etag, final String userKey, final List<StatusBean> statuses) {
    StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses, false);
    statusPatch.setKey(userKey);
    statusPatch.setType(StatusPatchType.SUSPEND);
    BulkActionResult result;
    synchronized (this) {
        result = new BulkActionResult();
        Map<String, BulkActionResult.Status> res = result.getResults();
        UserService service = getService(etag, UserService.class);
        @SuppressWarnings("unchecked") ProvisioningResult<UserTO> provisions = (ProvisioningResult<UserTO>) service.status(statusPatch).readEntity(ProvisioningResult.class);
        if (statusPatch.isOnSyncope()) {
            res.put(StringUtils.capitalize(Constants.SYNCOPE), "suspended".equalsIgnoreCase(provisions.getEntity().getStatus()) ? BulkActionResult.Status.SUCCESS : BulkActionResult.Status.FAILURE);
        }
        for (PropagationStatus status : provisions.getPropagationStatuses()) {
            res.put(status.getResource(), BulkActionResult.Status.valueOf(status.getStatus().name()));
        }
        resetClient(UserService.class);
    }
    return result;
}
Also used : PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserService(org.apache.syncope.common.rest.api.service.UserService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult)

Aggregations

ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)39 UserTO (org.apache.syncope.common.lib.to.UserTO)24 Test (org.junit.jupiter.api.Test)21 GroupTO (org.apache.syncope.common.lib.to.GroupTO)14 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 Response (javax.ws.rs.core.Response)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)8 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)8 UserService (org.apache.syncope.common.rest.api.service.UserService)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 GenericType (javax.ws.rs.core.GenericType)6 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)6 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)5 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)4 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)4