Search in sources :

Example 6 with DynRealm

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

the class DynRealmLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.DYNREALM_DELETE + "')")
public DynRealmTO delete(final String key) {
    DynRealm dynRealm = dynRealmDAO.find(key);
    if (dynRealm == null) {
        LOG.error("Could not find dynamic realm '" + key + "'");
        throw new NotFoundException(key);
    }
    DynRealmTO deleted = binder.getDynRealmTO(dynRealm);
    dynRealmDAO.delete(key);
    return deleted;
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with DynRealm

use of org.apache.syncope.core.persistence.api.entity.DynRealm 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 8 with DynRealm

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

the class AbstractAnyDAO method findDynRealms.

@Transactional(readOnly = true)
@Override
@SuppressWarnings("unchecked")
public List<String> findDynRealms(final String key) {
    Query query = entityManager().createNativeQuery("SELECT dynRealm_id FROM " + JPADynRealmDAO.DYNMEMB_TABLE + " WHERE any_id=?");
    query.setParameter(1, key);
    List<String> result = new ArrayList<>();
    query.getResultList().stream().map(resultKey -> resultKey instanceof Object[] ? (String) ((Object[]) resultKey)[0] : ((String) resultKey)).forEachOrdered((actualKey) -> {
        DynRealm dynRealm = dynRealmDAO().find(actualKey.toString());
        if (dynRealm == null) {
            LOG.error("Could not find dynRealm with id {}, even though returned by the native query", actualKey);
        } else if (!result.contains(actualKey.toString())) {
            result.add(actualKey.toString());
        }
    });
    return result;
}
Also used : Date(java.util.Date) NoResultException(javax.persistence.NoResultException) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Schema(org.apache.syncope.core.persistence.api.entity.Schema) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) AllowedSchemas(org.apache.syncope.core.persistence.api.dao.AllowedSchemas) HashSet(java.util.HashSet) ParserConstants(org.apache.commons.jexl3.parser.ParserConstants) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) Propagation(org.springframework.transaction.annotation.Propagation) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) JPAUser(org.apache.syncope.core.persistence.jpa.entity.user.JPAUser) AbstractPlainAttrValue(org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttrValue) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) DynRealmDAO(org.apache.syncope.core.persistence.api.dao.DynRealmDAO) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) TemporalType(javax.persistence.TemporalType) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Collection(java.util.Collection) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Query(javax.persistence.Query) DerSchemaDAO(org.apache.syncope.core.persistence.api.dao.DerSchemaDAO) StringReader(java.io.StringReader) AnyDAO(org.apache.syncope.core.persistence.api.dao.AnyDAO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Pattern(java.util.regex.Pattern) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) Token(org.apache.commons.jexl3.parser.Token) 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) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm) Parser(org.apache.commons.jexl3.parser.Parser) Transactional(org.springframework.transaction.annotation.Transactional) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with DynRealm

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

the class JPADynRealmDAO method delete.

@Override
public void delete(final String key) {
    DynRealm dynRealm = find(key);
    if (dynRealm == null) {
        return;
    }
    clearDynMembers(dynRealm);
    entityManager().remove(dynRealm);
}
Also used : JPADynRealm(org.apache.syncope.core.persistence.jpa.entity.JPADynRealm) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm)

Aggregations

DynRealm (org.apache.syncope.core.persistence.api.entity.DynRealm)9 HashSet (java.util.HashSet)3 DynRealmMembership (org.apache.syncope.core.persistence.api.entity.DynRealmMembership)3 Realm (org.apache.syncope.core.persistence.api.entity.Realm)3 List (java.util.List)2 Query (javax.persistence.Query)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 DynRealmDAO (org.apache.syncope.core.persistence.api.dao.DynRealmDAO)2 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)2 Any (org.apache.syncope.core.persistence.api.entity.Any)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1