Search in sources :

Example 1 with UserRoleKey

use of io.joynr.accesscontrol.primarykey.UserRoleKey in project joynr by bmwcarit.

the class DomainAccessControlStoreEhCache method updateDomainRole.

@Override
public Boolean updateDomainRole(@Nonnull DomainRoleEntry updatedEntry) {
    boolean updateSuccess = false;
    Cache cache = getCache(CacheId.DOMAIN_ROLES);
    UserRoleKey dreKey = new UserRoleKey(updatedEntry.getUid(), updatedEntry.getRole());
    try {
        cache.put(new Element(dreKey, updatedEntry));
        updateSuccess = true;
    } catch (IllegalArgumentException | IllegalStateException | CacheException e) {
        logger.error("updateDomainRole failed.", e);
    }
    return updateSuccess;
}
Also used : UserRoleKey(io.joynr.accesscontrol.primarykey.UserRoleKey) CacheException(net.sf.ehcache.CacheException) Element(net.sf.ehcache.Element) Cache(net.sf.ehcache.Cache)

Example 2 with UserRoleKey

use of io.joynr.accesscontrol.primarykey.UserRoleKey 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)

Aggregations

UserRoleKey (io.joynr.accesscontrol.primarykey.UserRoleKey)2 Cache (net.sf.ehcache.Cache)2 ArrayList (java.util.ArrayList)1 DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)1 CacheException (net.sf.ehcache.CacheException)1 Element (net.sf.ehcache.Element)1 Query (net.sf.ehcache.search.Query)1 Result (net.sf.ehcache.search.Result)1 Results (net.sf.ehcache.search.Results)1