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;
}
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;
}
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()]);
}
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);
}
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;
}
Aggregations