Search in sources :

Example 1 with Realm

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

the class JPAUserDAO method countByRealm.

@Override
public Map<String, Integer> countByRealm() {
    Query query = entityManager().createQuery("SELECT e.realm, COUNT(e) FROM  " + JPAUser.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 : AccountRule(org.apache.syncope.core.persistence.api.dao.AccountRule) Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) NoResultException(javax.persistence.NoResultException) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AnyDeletedEvent(org.apache.syncope.core.provisioning.api.event.AnyDeletedEvent) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AnyCreatedUpdatedEvent(org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) JPAUser(org.apache.syncope.core.persistence.jpa.entity.user.JPAUser) Repository(org.springframework.stereotype.Repository) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType) Role(org.apache.syncope.core.persistence.api.entity.Role) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) Resource(javax.annotation.Resource) Set(java.util.Set) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) AccountPolicyException(org.apache.syncope.core.provisioning.api.utils.policy.AccountPolicyException) Collectors(java.util.stream.Collectors) ImplementationManager(org.apache.syncope.core.spring.ImplementationManager) List(java.util.List) Query(javax.persistence.Query) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) PasswordPolicyException(org.apache.syncope.core.provisioning.api.utils.policy.PasswordPolicyException) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) TypedQuery(javax.persistence.TypedQuery) JPAAnyUtilsFactory(org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) Propagation(org.springframework.transaction.annotation.Propagation) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) User(org.apache.syncope.core.persistence.api.entity.user.User) AccessTokenDAO(org.apache.syncope.core.persistence.api.dao.AccessTokenDAO) PasswordRule(org.apache.syncope.core.persistence.api.dao.PasswordRule) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) Transactional(org.springframework.transaction.annotation.Transactional) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) JPAUser(org.apache.syncope.core.persistence.jpa.entity.user.JPAUser) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 2 with Realm

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

the class JPARealmDAO method findSamePolicyChildren.

private <T extends Policy> List<Realm> findSamePolicyChildren(final Realm realm, final T policy) {
    List<Realm> result = new ArrayList<>();
    for (Realm child : findChildren(realm)) {
        if ((policy instanceof AccountPolicy && child.getAccountPolicy() == null || policy.equals(child.getAccountPolicy())) || (policy instanceof PasswordPolicy && child.getPasswordPolicy() == null || policy.equals(child.getPasswordPolicy()))) {
            result.add(child);
            result.addAll(findSamePolicyChildren(child, policy));
        }
    }
    return result;
}
Also used : AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) ArrayList(java.util.ArrayList) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Realm(org.apache.syncope.core.persistence.api.entity.Realm) JPARealm(org.apache.syncope.core.persistence.jpa.entity.JPARealm)

Example 3 with Realm

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

the class JPARealmDAO method delete.

@Override
public void delete(final String key) {
    Realm realm = find(key);
    if (realm == null) {
        return;
    }
    delete(realm);
}
Also used : Realm(org.apache.syncope.core.persistence.api.entity.Realm) JPARealm(org.apache.syncope.core.persistence.jpa.entity.JPARealm)

Example 4 with Realm

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

the class JPARealmDAO method findByFullPath.

@Transactional(readOnly = true)
@Override
public Realm findByFullPath(final String fullPath) {
    if (SyncopeConstants.ROOT_REALM.equals(fullPath)) {
        return getRoot();
    }
    if (StringUtils.isBlank(fullPath) || !PATH_PATTERN.matcher(fullPath).matches()) {
        throw new MalformedPathException(fullPath);
    }
    Realm root = getRoot();
    if (root == null) {
        return null;
    }
    Realm current = root;
    for (final String pathElement : fullPath.substring(1).split("/")) {
        Optional<Realm> first = findChildren(current).stream().filter(realm -> pathElement.equals(realm.getName())).findFirst();
        if (first.isPresent()) {
            current = first.get();
        } else {
            return null;
        }
    }
    return current;
}
Also used : SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) Realm(org.apache.syncope.core.persistence.api.entity.Realm) Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) NoResultException(javax.persistence.NoResultException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Autowired(org.springframework.beans.factory.annotation.Autowired) JPARealm(org.apache.syncope.core.persistence.jpa.entity.JPARealm) TypedQuery(javax.persistence.TypedQuery) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) ArrayList(java.util.ArrayList) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) MalformedPathException(org.apache.syncope.core.persistence.api.dao.MalformedPathException) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) Optional(java.util.Optional) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) Repository(org.springframework.stereotype.Repository) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) MalformedPathException(org.apache.syncope.core.persistence.api.dao.MalformedPathException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) JPARealm(org.apache.syncope.core.persistence.jpa.entity.JPARealm) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Realm

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

the class JPARealmDAO method findDescendants.

private void findDescendants(final List<Realm> result, final Realm realm) {
    result.add(realm);
    List<Realm> children = findChildren(realm);
    if (children != null) {
        for (Realm child : children) {
            findDescendants(result, child);
        }
    }
}
Also used : Realm(org.apache.syncope.core.persistence.api.entity.Realm) JPARealm(org.apache.syncope.core.persistence.jpa.entity.JPARealm)

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