Search in sources :

Example 1 with Results

use of net.sf.ehcache.search.Results in project joynr by bmwcarit.

the class DomainAccessControlStoreEhCache method getAce.

private <T extends ControlEntry> T getAce(CacheId cacheId, String uid, String domain, String interfaceName, String operation) {
    Cache cache = getCache(cacheId);
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.USER_ID);
    Attribute<String> domainAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.DOMAIN);
    Attribute<String> interfaceAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.INTERFACE);
    Attribute<String> operationAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.OPERATION);
    Query queryAllOperations = cache.createQuery().addCriteria(uidAttribute.eq(uid).or(uidAttribute.eq(WILDCARD))).addCriteria(domainAttribute.eq(domain)).addCriteria(interfaceAttribute.eq(interfaceName)).addCriteria(operationAttribute.eq(operation)).addOrderBy(uidAttribute, Direction.DESCENDING).includeKeys().end();
    Results results = queryAllOperations.execute();
    T ace = null;
    if (!results.all().isEmpty()) {
        ace = DomainAccessControlStoreEhCache.<T>getElementValue(cache.get(results.all().get(0).getKey()));
    }
    return ace;
}
Also used : Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) Cache(net.sf.ehcache.Cache)

Example 2 with Results

use of net.sf.ehcache.search.Results in project joynr by bmwcarit.

the class DomainAccessControlStoreEhCache method getDomainRole.

@Override
public DomainRoleEntry getDomainRole(String uid, Role role) {
    Cache cache = getCache(CacheId.DOMAIN_ROLES);
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserRoleKey.USER_ID);
    Attribute<Role> roleAttribute = cache.getSearchAttribute(UserRoleKey.ROLE);
    // query is the fastest if you search for keys and if you need value then call Cache.get(key)
    Query queryRequestedUid = cache.createQuery().addCriteria(uidAttribute.eq(uid)).addCriteria(roleAttribute.eq(role)).includeKeys().end();
    Results results = queryRequestedUid.execute();
    DomainRoleEntry domainRole = null;
    if (!results.all().isEmpty()) {
        // results is either empty or contains exactly one entry
        assert (results.all().size() == 1);
        domainRole = (DomainAccessControlStoreEhCache.<DomainRoleEntry>getElementValue(cache.get(results.all().get(0).getKey())));
    }
    return domainRole;
}
Also used : Role(joynr.infrastructure.DacTypes.Role) Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Cache(net.sf.ehcache.Cache)

Example 3 with Results

use of net.sf.ehcache.search.Results in project directory-fortress-core by apache.

the class SDUtil method getDsdCache.

/**
 * Given a Set of authorized Roles, return the set of DSD's that have matching members.
 *
 * @param authorizedRoleSet contains an un-order Set of authorized Roles.
 * @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
 * @return un-ordered set of matching DSD's.
 * @throws SecurityException in the event of system or rule violation.
 */
Set<SDSet> getDsdCache(Set<String> authorizedRoleSet, String contextId) throws SecurityException {
    contextId = getContextId(contextId);
    Set<SDSet> dsdRetSets = new HashSet<>();
    // Need to proceed?
    if (!CollectionUtils.isNotEmpty(authorizedRoleSet)) {
        return dsdRetSets;
    }
    // Was the DSD Cache switched off?
    boolean isCacheDisabled = Config.getInstance().getBoolean(IS_DSD_CACHE_DISABLED_PARM, false);
    // If so, get DSD's from LDAP:
    if (isCacheDisabled) {
        SDSet sdSet = new SDSet();
        sdSet.setType(SDSet.SDType.DYNAMIC);
        sdSet.setContextId(contextId);
        dsdRetSets = sp.search(authorizedRoleSet, sdSet);
    } else // Search the DSD cache for matching Role members:
    {
        // Search on roleName attribute which maps to 'member' attr on the cache record:
        Attribute<String> member = m_dsdCache.getSearchAttribute(SchemaConstants.MEMBER_AT);
        Attribute<String> context = m_dsdCache.getSearchAttribute(CONTEXT_ID);
        Query query = m_dsdCache.createQuery();
        query.includeKeys();
        query.includeValues();
        // Add the passed in authorized Role names to this cache query:
        Set<String> roles = new HashSet<>(authorizedRoleSet);
        query.addCriteria(member.in(roles).and(context.eq(contextId)));
        // Return all DSD cache entries that match roleName to the 'member' attribute in cache entry:
        Results results = query.execute();
        for (Result result : results.all()) {
            DsdCacheEntry entry = (DsdCacheEntry) result.getValue();
            // Do not add dummy DSD sets to the final list:
            if (!entry.isEmpty()) {
                dsdRetSets.add(entry.getSdSet());
            }
        // Remove role member from authorizedRoleSet to preclude from upcoming DSD search:
        // authorizedRoleSet.remove(entry.getMember());
        }
        // Authorized roles remaining in this set correspond to missed cache hits from above:
        if (authorizedRoleSet.size() > 0) {
            dsdRetSets = putDsdCache(authorizedRoleSet, contextId);
        }
    }
    return dsdRetSets;
}
Also used : Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) DsdCacheEntry(org.apache.directory.fortress.core.util.cache.DsdCacheEntry) HashSet(java.util.HashSet) Result(net.sf.ehcache.search.Result)

Example 4 with Results

use of net.sf.ehcache.search.Results in project joynr by bmwcarit.

the class DomainAccessControlStoreEhCache method getEditableAces.

private <T extends ControlEntry> List<T> getEditableAces(String uid, CacheId cacheId, Role role) {
    List<T> aces = new ArrayList<T>();
    // find out first on which domains uid has specified role
    Cache drtCache = getCache(CacheId.DOMAIN_ROLES);
    UserRoleKey dreKey = new UserRoleKey(uid, role);
    String[] uidDomains = null;
    // read domains from DRE
    if (drtCache.isKeyInCache(dreKey)) {
        DomainRoleEntry dre = DomainAccessControlStoreEhCache.<DomainRoleEntry>getElementValue(drtCache.get(dreKey));
        uidDomains = dre.getDomains();
    }
    // if uid has no domains with specified role return empty list
    if (uidDomains == null || uidDomains.length == 0) {
        return aces;
    }
    Cache cache = getCache(cacheId);
    // here should search on uid and domain take place
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.USER_ID);
    Attribute<String> domainAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.DOMAIN);
    for (String domain : uidDomains) {
        Query query = cache.createQuery().addCriteria(uidAttribute.eq(uid).and(domainAttribute.eq(domain))).includeKeys().end();
        Results results = query.execute();
        for (Result result : results.all()) {
            aces.add(DomainAccessControlStoreEhCache.<T>getElementValue(cache.get(result.getKey())));
        }
    }
    return aces;
}
Also used : UserRoleKey(io.joynr.accesscontrol.primarykey.UserRoleKey) Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) ArrayList(java.util.ArrayList) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Cache(net.sf.ehcache.Cache) Result(net.sf.ehcache.search.Result)

Example 5 with Results

use of net.sf.ehcache.search.Results in project joynr by bmwcarit.

the class DomainAccessControlStoreEhCache method getAces.

private <T extends ControlEntry> List<T> getAces(String uid, CacheId cacheId) {
    Cache cache = getCache(cacheId);
    List<T> aces = new ArrayList<T>();
    // here search on uid take place
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.USER_ID);
    // query is the fastest if you search for keys and if you need value then call Cache.get(key)
    Query queryRequestedUid = cache.createQuery().addCriteria(uidAttribute.eq(uid).or(uidAttribute.eq(WILDCARD))).addOrderBy(uidAttribute, Direction.DESCENDING).includeKeys().end();
    Results results = queryRequestedUid.execute();
    for (Result result : results.all()) {
        aces.add(DomainAccessControlStoreEhCache.<T>getElementValue(cache.get(result.getKey())));
    }
    return aces;
}
Also used : Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) ArrayList(java.util.ArrayList) Cache(net.sf.ehcache.Cache) Result(net.sf.ehcache.search.Result)

Aggregations

Query (net.sf.ehcache.search.Query)9 Results (net.sf.ehcache.search.Results)9 Result (net.sf.ehcache.search.Result)7 Cache (net.sf.ehcache.Cache)5 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)3 DsdCacheEntry (org.apache.directory.fortress.core.util.cache.DsdCacheEntry)2 UserRoleKey (io.joynr.accesscontrol.primarykey.UserRoleKey)1 Role (joynr.infrastructure.DacTypes.Role)1 SDSet (org.apache.directory.fortress.core.model.SDSet)1