Search in sources :

Example 41 with Realm

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

the class AbstractAnyLogic method beforeDelete.

protected Pair<TO, List<LogicActions>> beforeDelete(final TO input) {
    Realm realm = realmDAO.findByFullPath(input.getRealm());
    if (realm == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
        sce.getElements().add(input.getRealm());
        throw sce;
    }
    TO any = input;
    List<LogicActions> actions = getActions(realm);
    for (LogicActions action : actions) {
        any = action.beforeDelete(any);
    }
    LOG.debug("Input: {}\nOutput: {}\n", input, any);
    return ImmutablePair.of(any, actions);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTO(org.apache.syncope.common.lib.to.AnyTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) UserTO(org.apache.syncope.common.lib.to.UserTO) Realm(org.apache.syncope.core.persistence.api.entity.Realm) LogicActions(org.apache.syncope.core.provisioning.api.LogicActions)

Example 42 with Realm

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

the class JPAAnySearchDAO method getQuery.

private String getQuery(final AssignableCond cond, final List<Object> parameters, final SearchSupport svs) {
    Realm realm;
    try {
        realm = check(cond);
    } catch (IllegalArgumentException e) {
        return EMPTY_QUERY;
    }
    StringBuilder query = new StringBuilder("SELECT DISTINCT any_id FROM ").append(svs.field().name).append(" WHERE (");
    if (cond.isFromGroup()) {
        realmDAO.findDescendants(realm).forEach(current -> {
            query.append("realm_id=?").append(setParameter(parameters, current.getKey())).append(" OR ");
        });
        query.setLength(query.length() - 4);
    } else {
        for (Realm current = realm; current.getParent() != null; current = current.getParent()) {
            query.append("realm_id=?").append(setParameter(parameters, current.getKey())).append(" OR ");
        }
        query.append("realm_id=?").append(setParameter(parameters, realmDAO.getRoot().getKey()));
    }
    query.append(')');
    return query.toString();
}
Also used : Realm(org.apache.syncope.core.persistence.api.entity.Realm) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm)

Example 43 with Realm

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

the class JPAAnySearchDAO method getAdminRealmsFilter.

private Pair<String, Set<String>> getAdminRealmsFilter(final Set<String> adminRealms, final SearchSupport svs, final List<Object> parameters) {
    Set<String> realmKeys = new HashSet<>();
    Set<String> dynRealmKeys = new HashSet<>();
    RealmUtils.normalize(adminRealms).forEach(realmPath -> {
        if (realmPath.startsWith("/")) {
            Realm realm = realmDAO.findByFullPath(realmPath);
            if (realm == null) {
                SyncopeClientException noRealm = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
                noRealm.getElements().add("Invalid realm specified: " + realmPath);
                throw noRealm;
            } else {
                realmKeys.addAll(realmDAO.findDescendants(realm).stream().map(r -> r.getKey()).collect(Collectors.toSet()));
            }
        } else {
            DynRealm dynRealm = dynRealmDAO.find(realmPath);
            if (dynRealm == null) {
                LOG.warn("Ignoring invalid dynamic realm {}", realmPath);
            } else {
                dynRealmKeys.add(dynRealm.getKey());
            }
        }
    });
    if (!dynRealmKeys.isEmpty()) {
        realmKeys.addAll(realmDAO.findAll().stream().map(r -> r.getKey()).collect(Collectors.toSet()));
    }
    StringBuilder adminRealmFilter = new StringBuilder("u.any_id IN (").append("SELECT any_id FROM ").append(svs.field().name).append(" WHERE realm_id IN (SELECT id AS realm_id FROM Realm");
    boolean firstRealm = true;
    for (String realmKey : realmKeys) {
        if (firstRealm) {
            adminRealmFilter.append(" WHERE");
            firstRealm = false;
        } else {
            adminRealmFilter.append(" OR");
        }
        adminRealmFilter.append(" id=?").append(setParameter(parameters, realmKey));
    }
    adminRealmFilter.append("))");
    return Pair.of(adminRealmFilter.toString(), dynRealmKeys);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm) HashSet(java.util.HashSet) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm)

Example 44 with Realm

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

the class JPAGroupDAO method countByRealm.

@Override
public Map<String, Integer> countByRealm() {
    Query query = entityManager().createQuery("SELECT e.realm, COUNT(e) FROM  " + JPAGroup.class.getSimpleName() + " e GROUP BY e.realm");
    @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 : 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) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) JPAGroup(org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 45 with Realm

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

the class JPAUserDAO method getPasswordPolicies.

private List<PasswordPolicy> getPasswordPolicies(final User user) {
    List<PasswordPolicy> policies = new ArrayList<>();
    PasswordPolicy policy;
    // add resource policies
    for (ExternalResource resource : findAllResources(user)) {
        policy = resource.getPasswordPolicy();
        if (policy != null) {
            policies.add(policy);
        }
    }
    // add realm policies
    for (Realm realm : realmDAO().findAncestors(user.getRealm())) {
        policy = realm.getPasswordPolicy();
        if (policy != null) {
            policies.add(policy);
        }
    }
    return policies;
}
Also used : PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ArrayList(java.util.ArrayList) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Aggregations

Realm (org.apache.syncope.core.persistence.api.entity.Realm)51 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)21 ArrayList (java.util.ArrayList)14 RealmTO (org.apache.syncope.common.lib.to.RealmTO)12 Group (org.apache.syncope.core.persistence.api.entity.group.Group)11 Transactional (org.springframework.transaction.annotation.Transactional)11 List (java.util.List)10 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)10 Collections (java.util.Collections)9 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)7 StringUtils (org.apache.commons.lang3.StringUtils)7 Entity (org.apache.syncope.core.persistence.api.entity.Entity)7 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)7 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)7 User (org.apache.syncope.core.persistence.api.entity.user.User)7 Date (java.util.Date)6