Search in sources :

Example 21 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class GroupDataBinderImpl method create.

@Override
public void create(final Group group, final GroupTO groupTO) {
    SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
    // name
    SyncopeClientException invalidGroups = SyncopeClientException.build(ClientExceptionType.InvalidGroup);
    if (groupTO.getName() == null) {
        LOG.error("No name specified for this group");
        invalidGroups.getElements().add("No name specified for this group");
    } else {
        group.setName(groupTO.getName());
    }
    // realm
    Realm realm = realmDAO.findByFullPath(groupTO.getRealm());
    if (realm == null) {
        SyncopeClientException noRealm = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
        noRealm.getElements().add("Invalid or null realm specified: " + groupTO.getRealm());
        scce.addException(noRealm);
    }
    group.setRealm(realm);
    // attributes and resources
    fill(group, groupTO, anyUtilsFactory.getInstance(AnyTypeKind.GROUP), scce);
    // owner
    if (groupTO.getUserOwner() != null) {
        User owner = userDAO.find(groupTO.getUserOwner());
        if (owner == null) {
            LOG.warn("Ignoring invalid user specified as owner: {}", groupTO.getUserOwner());
        } else {
            group.setUserOwner(owner);
        }
    }
    if (groupTO.getGroupOwner() != null) {
        Group owner = groupDAO.find(groupTO.getGroupOwner());
        if (owner == null) {
            LOG.warn("Ignoring invalid group specified as owner: {}", groupTO.getGroupOwner());
        } else {
            group.setGroupOwner(owner);
        }
    }
    // dynamic membership
    if (groupTO.getUDynMembershipCond() != null) {
        setDynMembership(group, anyTypeDAO.findUser(), groupTO.getUDynMembershipCond());
    }
    groupTO.getADynMembershipConds().forEach((type, fiql) -> {
        AnyType anyType = anyTypeDAO.find(type);
        if (anyType == null) {
            LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), type);
        } else {
            setDynMembership(group, anyType, fiql);
        }
    });
    // type extensions
    groupTO.getTypeExtensions().forEach(typeExtTO -> {
        AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
        if (anyType == null) {
            LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
        } else {
            TypeExtension typeExt = entityFactory.newEntity(TypeExtension.class);
            typeExt.setAnyType(anyType);
            typeExt.setGroup(group);
            group.add(typeExt);
            typeExtTO.getAuxClasses().forEach(name -> {
                AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
                if (anyTypeClass == null) {
                    LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
                } else {
                    typeExt.add(anyTypeClass);
                }
            });
            if (typeExt.getAuxClasses().isEmpty()) {
                group.getTypeExtensions().remove(typeExt);
                typeExt.setGroup(null);
            }
        }
    });
    // Throw composite exception if there is at least one element set in the composing exceptions
    if (scce.hasExceptions()) {
        throw scce;
    }
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) User(org.apache.syncope.core.persistence.api.entity.user.User) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass)

Example 22 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class GroupDataBinderImpl method findUsersWithTransitiveResources.

@Transactional(readOnly = true)
@Override
public Map<String, PropagationByResource> findUsersWithTransitiveResources(final String groupKey) {
    Group group = groupDAO.authFind(groupKey);
    Map<String, PropagationByResource> result = new HashMap<>();
    groupDAO.findUMemberships(group).forEach((membership) -> {
        populateTransitiveResources(group, membership.getLeftEnd(), result);
    });
    return result;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) HashMap(java.util.HashMap) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class GroupDataBinderImpl method findAnyObjectsWithTransitiveResources.

@Transactional(readOnly = true)
@Override
public Map<String, PropagationByResource> findAnyObjectsWithTransitiveResources(final String groupKey) {
    Group group = groupDAO.authFind(groupKey);
    Map<String, PropagationByResource> result = new HashMap<>();
    groupDAO.findAMemberships(group).forEach((membership) -> {
        populateTransitiveResources(group, membership.getLeftEnd(), result);
    });
    return result;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) HashMap(java.util.HashMap) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class SyncopeLogic method searchAssignableGroups.

@PreAuthorize("isAuthenticated()")
public Pair<Integer, List<GroupTO>> searchAssignableGroups(final String realm, final String term, final int page, final int size) {
    AssignableCond assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath(realm);
    SearchCond searchCond;
    if (StringUtils.isNotBlank(term)) {
        AnyCond termCond = new AnyCond(AttributeCond.Type.ILIKE);
        termCond.setSchema("name");
        String termSearchableValue = (term.startsWith("*") && !term.endsWith("*")) ? term + "%" : (!term.startsWith("*") && term.endsWith("*")) ? "%" + term : (term.startsWith("*") && term.endsWith("*") ? term : "%" + term + "%");
        termCond.setExpression(termSearchableValue);
        searchCond = SearchCond.getAndCond(SearchCond.getLeafCond(assignableCond), SearchCond.getLeafCond(termCond));
    } else {
        searchCond = SearchCond.getLeafCond(assignableCond);
    }
    int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, AnyTypeKind.GROUP);
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("name");
    orderByClause.setDirection(OrderByClause.Direction.ASC);
    List<Group> matching = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, page, size, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
    List<GroupTO> result = matching.stream().map(group -> groupDataBinder.getGroupTO(group, false)).collect(Collectors.toList());
    return Pair.of(count, result);
}
Also used : Arrays(java.util.Arrays) SecurityQuestionDAO(org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO) AopUtils(org.springframework.aop.support.AopUtils) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) GroupProvisioningManager(org.apache.syncope.core.provisioning.api.GroupProvisioningManager) PlatformInfo(org.apache.syncope.common.lib.info.PlatformInfo) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) InetAddress(java.net.InetAddress) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) 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) URI(java.net.URI) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Method(java.lang.reflect.Method) PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) RuntimeMXBean(java.lang.management.RuntimeMXBean) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) GroupWorkflowAdapter(org.apache.syncope.core.workflow.api.GroupWorkflowAdapter) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) NotificationDAO(org.apache.syncope.core.persistence.api.dao.NotificationDAO) EntitlementsHolder(org.apache.syncope.core.provisioning.api.EntitlementsHolder) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SystemInfo(org.apache.syncope.common.lib.info.SystemInfo) List(java.util.List) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) ConnIdBundleManager(org.apache.syncope.core.provisioning.api.ConnIdBundleManager) PropagationTaskExecutor(org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) VirAttrCache(org.apache.syncope.core.provisioning.api.cache.VirAttrCache) AbstractBaseBean(org.apache.syncope.common.lib.AbstractBaseBean) NumbersInfo(org.apache.syncope.common.lib.info.NumbersInfo) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) PasswordGenerator(org.apache.syncope.core.spring.security.PasswordGenerator) GroupDataBinder(org.apache.syncope.core.provisioning.api.data.GroupDataBinder) UserWorkflowAdapter(org.apache.syncope.core.workflow.api.UserWorkflowAdapter) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) AnyObjectProvisioningManager(org.apache.syncope.core.provisioning.api.AnyObjectProvisioningManager) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Iterator(java.util.Iterator) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) UnknownHostException(java.net.UnknownHostException) ImplementationLookup(org.apache.syncope.core.persistence.api.ImplementationLookup) Component(org.springframework.stereotype.Component) UserProvisioningManager(org.apache.syncope.core.provisioning.api.UserProvisioningManager) JavaImplInfo(org.apache.syncope.common.lib.info.JavaImplInfo) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) AnyObjectWorkflowAdapter(org.apache.syncope.core.workflow.api.AnyObjectWorkflowAdapter) TaskType(org.apache.syncope.common.lib.types.TaskType) Transactional(org.springframework.transaction.annotation.Transactional) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) Group(org.apache.syncope.core.persistence.api.entity.group.Group) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 25 with Group

use of org.apache.syncope.core.persistence.api.entity.group.Group in project syncope by apache.

the class JPAAnyObjectDAO method countByRealm.

@Override
public Map<String, Integer> countByRealm(final AnyType anyType) {
    Query query = entityManager().createQuery("SELECT e.realm, COUNT(e) FROM  " + JPAAnyObject.class.getSimpleName() + " e " + "WHERE e.type=:type GROUP BY e.realm");
    query.setParameter("type", anyType);
    @SuppressWarnings("unchecked") List<Object[]> results = query.getResultList();
    return results.stream().collect(Collectors.toMap(result -> ((Realm) result[0]).getFullPath(), result -> ((Number) result[1]).intValue()));
}
Also used : 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) JPAAnyObject(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) TypedQuery(javax.persistence.TypedQuery) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) 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) Propagation(org.springframework.transaction.annotation.Propagation) Map(java.util.Map) AnyEntitlement(org.apache.syncope.common.lib.types.AnyEntitlement) JPAARelationship(org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Repository(org.springframework.stereotype.Repository) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Collection(java.util.Collection) Set(java.util.Set) JPAURelationship(org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship) Collectors(java.util.stream.Collectors) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Query(javax.persistence.Query) ARelationship(org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship) Relationship(org.apache.syncope.core.persistence.api.entity.Relationship) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Aggregations

Group (org.apache.syncope.core.persistence.api.entity.group.Group)65 User (org.apache.syncope.core.persistence.api.entity.user.User)32 Transactional (org.springframework.transaction.annotation.Transactional)28 List (java.util.List)24 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)24 ArrayList (java.util.ArrayList)20 HashSet (java.util.HashSet)20 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)20 Test (org.junit.jupiter.api.Test)20 Collectors (java.util.stream.Collectors)19 Autowired (org.springframework.beans.factory.annotation.Autowired)19 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)17 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)17 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)17 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)17 Collections (java.util.Collections)16 Set (java.util.Set)16 Map (java.util.Map)15 Pair (org.apache.commons.lang3.tuple.Pair)15