Search in sources :

Example 11 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO 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 12 with AnyObjectTO

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

the class AnyObjectLogic method unlink.

@Override
public AnyObjectTO unlink(final String key, final Collection<String> resources) {
    // 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());
    AnyObjectPatch patch = new AnyObjectPatch();
    patch.setKey(key);
    patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(resource).build()).collect(Collectors.toList()));
    return binder.getAnyObjectTO(provisioningManager.unlink(patch));
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Example 13 with AnyObjectTO

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

the class AnyObjectLogic method assign.

@Override
public ProvisioningResult<AnyObjectTO> assign(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());
    AnyObjectPatch patch = new AnyObjectPatch();
    patch.setKey(key);
    patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build()).collect(Collectors.toList()));
    return update(patch, nullPriorityAsync);
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Example 14 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO 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 15 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO 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)

Aggregations

AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)45 Test (org.junit.jupiter.api.Test)19 GroupTO (org.apache.syncope.common.lib.to.GroupTO)14 UserTO (org.apache.syncope.common.lib.to.UserTO)14 AnyObjectPatch (org.apache.syncope.common.lib.patch.AnyObjectPatch)13 AttrTO (org.apache.syncope.common.lib.to.AttrTO)10 List (java.util.List)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)8 Map (java.util.Map)7 Pair (org.apache.commons.lang3.tuple.Pair)6 AnyTO (org.apache.syncope.common.lib.to.AnyTO)6 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)6 Optional (java.util.Optional)5 Set (java.util.Set)5 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)5 AnyQuery (org.apache.syncope.common.rest.api.beans.AnyQuery)5 User (org.apache.syncope.core.persistence.api.entity.user.User)5 ArrayList (java.util.ArrayList)4 Response (javax.ws.rs.core.Response)4