Search in sources :

Example 1 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class JPAGroupDAO method save.

@Override
public Group save(final Group group) {
    Group merged = super.save(group);
    publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, merged, AuthContextUtils.getDomain()));
    // refresh dynamic memberships
    clearUDynMembers(merged);
    if (merged.getUDynMembership() != null) {
        SearchCond cond = buildDynMembershipCond(merged.getUDynMembership().getFIQLCond(), merged.getRealm());
        int count = searchDAO().count(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, AnyTypeKind.USER);
        for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
            List<User> matching = searchDAO().search(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.USER);
            matching.forEach(user -> {
                Query insert = entityManager().createNativeQuery("INSERT INTO " + UDYNMEMB_TABLE + " VALUES(?, ?)");
                insert.setParameter(1, user.getKey());
                insert.setParameter(2, merged.getKey());
                insert.executeUpdate();
                publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, user, AuthContextUtils.getDomain()));
            });
        }
    }
    clearADynMembers(merged);
    merged.getADynMemberships().stream().forEach(memb -> {
        SearchCond cond = buildDynMembershipCond(memb.getFIQLCond(), merged.getRealm());
        int count = searchDAO().count(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, AnyTypeKind.ANY_OBJECT);
        for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
            List<AnyObject> matching = searchDAO().search(Collections.<String>singleton(merged.getRealm().getFullPath()), cond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), AnyTypeKind.ANY_OBJECT);
            matching.forEach(anyObject -> {
                Query insert = entityManager().createNativeQuery("INSERT INTO " + ADYNMEMB_TABLE + " VALUES(?, ?, ?)");
                insert.setParameter(1, anyObject.getType().getKey());
                insert.setParameter(2, anyObject.getKey());
                insert.setParameter(3, merged.getKey());
                insert.executeUpdate();
                publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, anyObject, AuthContextUtils.getDomain()));
            });
        }
    });
    dynRealmDAO().refreshDynMemberships(merged);
    return merged;
}
Also used : JPAGroup(org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond)

Example 2 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class JPAGroupDAO method delete.

@Override
public void delete(final Group group) {
    dynRealmDAO().removeDynMemberships(group.getKey());
    findAMemberships(group).forEach(membership -> {
        AnyObject leftEnd = membership.getLeftEnd();
        leftEnd.getMemberships().remove(membership);
        membership.setRightEnd(null);
        leftEnd.getPlainAttrs(membership).stream().map(attr -> {
            leftEnd.remove(attr);
            attr.setOwner(null);
            attr.setMembership(null);
            return attr;
        }).forEachOrdered(attr -> plainAttrDAO.delete(attr));
        anyObjectDAO().save(leftEnd);
        publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, leftEnd, AuthContextUtils.getDomain()));
    });
    findUMemberships(group).forEach(membership -> {
        User leftEnd = membership.getLeftEnd();
        leftEnd.getMemberships().remove(membership);
        membership.setRightEnd(null);
        leftEnd.getPlainAttrs(membership).stream().map(attr -> {
            leftEnd.remove(attr);
            attr.setOwner(null);
            attr.setMembership(null);
            return attr;
        }).forEachOrdered(attr -> plainAttrDAO.delete(attr));
        userDAO().save(leftEnd);
        publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, leftEnd, AuthContextUtils.getDomain()));
    });
    clearUDynMembers(group);
    clearADynMembers(group);
    entityManager().remove(group);
    publisher.publishEvent(new AnyDeletedEvent(this, AnyTypeKind.GROUP, group.getKey(), AuthContextUtils.getDomain()));
}
Also used : AopUtils(org.springframework.aop.support.AopUtils) Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) NoResultException(javax.persistence.NoResultException) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) JPAGroup(org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) JPATypeExtension(org.apache.syncope.core.persistence.jpa.entity.group.JPATypeExtension) JPAUMembership(org.apache.syncope.core.persistence.jpa.entity.user.JPAUMembership) Repository(org.springframework.stereotype.Repository) JPAADynGroupMembership(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADynGroupMembership) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) JPAAMembership(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAMembership) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) Query(javax.persistence.Query) Group(org.apache.syncope.core.persistence.api.entity.group.Group) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) UDynGroupMembership(org.apache.syncope.core.persistence.api.entity.user.UDynGroupMembership) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) TypedQuery(javax.persistence.TypedQuery) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RealmUtils(org.apache.syncope.core.provisioning.api.utils.RealmUtils) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) SearchCondConverter(org.apache.syncope.core.persistence.api.search.SearchCondConverter) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) JPAUDynGroupMembership(org.apache.syncope.core.persistence.jpa.entity.user.JPAUDynGroupMembership) AnyDAO(org.apache.syncope.core.persistence.api.dao.AnyDAO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Collections(java.util.Collections) PlainAttrDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrDAO) Transactional(org.springframework.transaction.annotation.Transactional) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User)

Example 3 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject 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 4 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class AbstractPushResultHandler method update.

protected void update(final Any<?> any, final ProvisioningReport result) {
    boolean changepwd;
    Collection<String> resourceKeys;
    if (any instanceof User) {
        changepwd = true;
        resourceKeys = userDAO.findAllResourceKeys(any.getKey());
    } else if (any instanceof AnyObject) {
        changepwd = false;
        resourceKeys = anyObjectDAO.findAllResourceKeys(any.getKey());
    } else {
        changepwd = false;
        resourceKeys = groupDAO.findAllResourceKeys(any.getKey());
    }
    List<String> noPropResources = new ArrayList<>(resourceKeys);
    noPropResources.remove(profile.getTask().getResource().getKey());
    PropagationByResource propByRes = new PropagationByResource();
    propByRes.add(ResourceOperation.CREATE, profile.getTask().getResource().getKey());
    PropagationReporter reporter = taskExecutor.execute(propagationManager.getUpdateTasks(any.getType().getKind(), any.getKey(), changepwd, null, propByRes, null, noPropResources), false);
    reportPropagation(result, reporter);
}
Also used : AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) ArrayList(java.util.ArrayList) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)

Example 5 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class PullUtils method findByConnObjectKey.

private List<String> findByConnObjectKey(final ConnectorObject connObj, final Provision provision, final AnyUtils anyUtils) {
    String connObjectKey = null;
    Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
    if (connObjectKeyItem.isPresent()) {
        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<>();
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(connObjectKeyItem.get().getIntAttrName(), provision.getAnyType().getKind());
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified, ignoring", connObjectKeyItem.get().getIntAttrName(), e);
        return result;
    }
    if (intAttrName.getField() != null) {
        switch(intAttrName.getField()) {
            case "key":
                Any<?> any = getAnyDAO(provision.getAnyType().getKind()).find(connObjectKey);
                if (any != null) {
                    result.add(any.getKey());
                }
                break;
            case "username":
                User user = userDAO.findByUsername(connObjectKey);
                if (user != null) {
                    result.add(user.getKey());
                }
                break;
            case "name":
                Group group = groupDAO.findByName(connObjectKey);
                if (group != null) {
                    result.add(group.getKey());
                }
                AnyObject anyObject = anyObjectDAO.findByName(connObjectKey);
                if (anyObject != null) {
                    result.add(anyObject.getKey());
                }
                break;
            default:
        }
    } else if (intAttrName.getSchemaType() != null) {
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                PlainAttrValue value = anyUtils.newPlainAttrValue();
                PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName());
                if (schema == null) {
                    value.setStringValue(connObjectKey);
                } else {
                    try {
                        value.parseValue(schema, connObjectKey);
                    } catch (ParsingValidationException e) {
                        LOG.error("While parsing provided __UID__ {}", value, e);
                        value.setStringValue(connObjectKey);
                    }
                }
                result.addAll(getAnyDAO(provision.getAnyType().getKind()).findByPlainAttrValue(intAttrName.getSchemaName(), value).stream().map(Entity::getKey).collect(Collectors.toList()));
                break;
            case DERIVED:
                result.addAll(getAnyDAO(provision.getAnyType().getKind()).findByDerAttrValue(intAttrName.getSchemaName(), connObjectKey).stream().map(Entity::getKey).collect(Collectors.toList()));
                break;
            default:
        }
    }
    return result;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) User(org.apache.syncope.core.persistence.api.entity.user.User) Attribute(org.identityconnectors.framework.common.objects.Attribute) ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) ArrayList(java.util.ArrayList) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) ParseException(java.text.ParseException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Aggregations

AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)29 Group (org.apache.syncope.core.persistence.api.entity.group.Group)18 User (org.apache.syncope.core.persistence.api.entity.user.User)15 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)11 Test (org.junit.jupiter.api.Test)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Transactional (org.springframework.transaction.annotation.Transactional)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)7 AnyObjectDAO (org.apache.syncope.core.persistence.api.dao.AnyObjectDAO)7 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)7 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)7 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)7 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)7 Collections (java.util.Collections)6 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)6