Search in sources :

Example 16 with DomainRoleEntry

use of joynr.infrastructure.DacTypes.DomainRoleEntry 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 17 with DomainRoleEntry

use of joynr.infrastructure.DacTypes.DomainRoleEntry 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)

Example 18 with DomainRoleEntry

use of joynr.infrastructure.DacTypes.DomainRoleEntry in project joynr by bmwcarit.

the class DomainRoleEntryManager method findByUserId.

public DomainRoleEntry[] findByUserId(String userId) {
    Query query = entityManager.createQuery("select dre from DomainRoleEntryEntity dre where dre.userId = :userId", DomainRoleEntryEntity.class);
    query.setParameter("userId", userId);
    List<DomainRoleEntryEntity> entities = query.getResultList();
    Set<DomainRoleEntry> resultSet = entities.stream().map(this::mapEntityToJoynrType).collect(toSet());
    return resultSet.toArray(new DomainRoleEntry[resultSet.size()]);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) Query(javax.persistence.Query) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry)

Example 19 with DomainRoleEntry

use of joynr.infrastructure.DacTypes.DomainRoleEntry in project joynr by bmwcarit.

the class LocalDomainAccessControllerTest method setup.

@SuppressWarnings("unchecked")
@Before
public void setup() {
    cacheManager = CacheManager.create();
    domainAccessControlStore = new DomainAccessControlStoreEhCache(cacheManager, new DefaultDomainAccessControlProvisioning());
    when(proxyInvocationHandlerFactoryMock.create(any(Set.class), any(String.class), any(String.class), any(DiscoveryQos.class), any(MessagingQos.class))).thenReturn(proxyInvocationHandlerMock);
    GlobalDiscoveryEntry accessControlDomain = mock(GlobalDiscoveryEntry.class);
    when(accessControlDomain.getDomain()).thenReturn("accessControlDomain");
    localDomainAccessController = new LocalDomainAccessControllerImpl(accessControlDomain, domainAccessControlStore, new ProxyBuilderFactoryImpl(localDiscoveryAggregator, proxyInvocationHandlerFactoryMock, MAX_TTL, DISCOVERY_TIMEOUT_MS, RETRY_INTERVAL_MS), "systemServiceDomain");
    // instantiate some template objects
    userDre = new DomainRoleEntry(UID1, new String[] { DOMAIN1 }, Role.OWNER);
    masterAce = new MasterAccessControlEntry(UID1, DOMAIN1, INTERFACE1, TrustLevel.LOW, new TrustLevel[] { TrustLevel.MID, TrustLevel.LOW }, TrustLevel.LOW, new TrustLevel[] { TrustLevel.MID, TrustLevel.LOW }, OPEARATION1, Permission.NO, new Permission[] { Permission.ASK, Permission.NO });
    ownerAce = new OwnerAccessControlEntry(UID1, DOMAIN1, INTERFACE1, TrustLevel.LOW, TrustLevel.LOW, OPEARATION1, Permission.YES);
}
Also used : Set(java.util.Set) ProxyBuilderFactoryImpl(io.joynr.proxy.ProxyBuilderFactoryImpl) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) MessagingQos(io.joynr.messaging.MessagingQos) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) TrustLevel(joynr.infrastructure.DacTypes.TrustLevel) OwnerAccessControlEntry(joynr.infrastructure.DacTypes.OwnerAccessControlEntry) Permission(joynr.infrastructure.DacTypes.Permission) Before(org.junit.Before)

Example 20 with DomainRoleEntry

use of joynr.infrastructure.DacTypes.DomainRoleEntry in project joynr by bmwcarit.

the class LocalDomainAccessControllerImpl method hasRole.

@Override
public boolean hasRole(String userId, String domain, Role role) {
    boolean hasRole = false;
    DomainRoleEntry dre;
    synchronized (localDomainAccessStore) {
        dre = localDomainAccessStore.getDomainRole(userId, role);
    }
    if (dre != null) {
        List<String> domains = Arrays.asList(dre.getDomains());
        if (domains.contains(domain)) {
            hasRole = true;
        }
    }
    if (!hasRole) {
        subscribeForDreChange(userId);
    }
    return hasRole;
}
Also used : DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry)

Aggregations

DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)21 Test (org.junit.Test)8 MasterAccessControlEntry (joynr.infrastructure.DacTypes.MasterAccessControlEntry)7 OwnerAccessControlEntry (joynr.infrastructure.DacTypes.OwnerAccessControlEntry)6 Permission (joynr.infrastructure.DacTypes.Permission)4 TrustLevel (joynr.infrastructure.DacTypes.TrustLevel)4 Cache (net.sf.ehcache.Cache)4 Before (org.junit.Before)4 ArrayList (java.util.ArrayList)3 Query (net.sf.ehcache.search.Query)3 Results (net.sf.ehcache.search.Results)3 DomainRoleEntryEntity (io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)2 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 MessagingQos (io.joynr.messaging.MessagingQos)2 Result (net.sf.ehcache.search.Result)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DomainAccessControlStoreEhCache (io.joynr.accesscontrol.DomainAccessControlStoreEhCache)1 UserRoleKey (io.joynr.accesscontrol.primarykey.UserRoleKey)1 Promise (io.joynr.provider.Promise)1 ProxyBuilderFactoryImpl (io.joynr.proxy.ProxyBuilderFactoryImpl)1