Search in sources :

Example 1 with Result

use of net.sf.ehcache.search.Result in project uPortal by Jasig.

the class PagsMembershipCacheAuthenticationListener method userAuthenticated.

@Override
public void userAuthenticated(IPerson user) {
    /*
         * Used to log the time it takes to complete this operation;  the author
         * has some anxiety about running time with large numbers of elements in
         * the cache.
         */
    final long timestamp = System.currentTimeMillis();
    /*
         * Query the membershipCache (ehcache) for elements that
         * reference the specified user and remove them.
         */
    final Query query = membershipCache.createQuery().includeKeys().addCriteria(usernameSearchAttribute.eq(user.getEntityIdentifier().getKey())).end();
    final List<Result> queryResults = query.execute().all();
    for (Result r : queryResults) {
        membershipCache.remove(r.getKey());
    }
    logger.debug("Purged {} PAGS membership cache entries for authenticated user '{}' in {}ms", queryResults.size(), user.getUserName(), Long.toBinaryString(System.currentTimeMillis() - timestamp));
}
Also used : Query(net.sf.ehcache.search.Query) Result(net.sf.ehcache.search.Result)

Example 2 with Result

use of net.sf.ehcache.search.Result 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 3 with Result

use of net.sf.ehcache.search.Result 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 4 with Result

use of net.sf.ehcache.search.Result 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)

Example 5 with Result

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

the class DomainAccessControlStoreEhCache method getDomainRoles.

@Override
public List<DomainRoleEntry> getDomainRoles(String uid) {
    Cache cache = getCache(CacheId.DOMAIN_ROLES);
    List<DomainRoleEntry> domainRoles = new ArrayList<DomainRoleEntry>();
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserRoleKey.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)).includeKeys().end();
    Results results = queryRequestedUid.execute();
    for (Result result : results.all()) {
        domainRoles.add(DomainAccessControlStoreEhCache.<DomainRoleEntry>getElementValue(cache.get(result.getKey())));
    }
    return domainRoles;
}
Also used : Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) ArrayList(java.util.ArrayList) Cache(net.sf.ehcache.Cache) Result(net.sf.ehcache.search.Result)

Aggregations

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