use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class MasterAccessControlEntryManagerTest method testFindByUserIdAndIsEditable.
@Test
public void testFindByUserIdAndIsEditable() {
String userId = "user";
create(userId, "domain1", "interface1", TrustLevel.HIGH, new TrustLevel[] {}, TrustLevel.LOW, new TrustLevel[] {}, "operation1", Permission.YES, new Permission[] {});
create(userId, "domain2", "interface2", TrustLevel.HIGH, new TrustLevel[] {}, TrustLevel.LOW, new TrustLevel[] {}, "operation2", Permission.YES, new Permission[] {});
DomainRoleEntryEntity role1 = new DomainRoleEntryEntity();
role1.setUserId(userId);
role1.setRole(Role.MASTER);
role1.setDomains(Sets.newHashSet("domain1", "domain4", "domain5"));
entityManager.persist(role1);
flushAndClear();
MasterAccessControlEntry[] result = subject.findByUserIdThatAreEditable(userId, MASTER);
assertNotNull(result);
assertEquals(1, result.length);
assertEquals("domain1", result[0].getDomain());
assertEquals("interface1", result[0].getInterfaceName());
}
use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class OwnerRegistrationControlEntryManagerTest method testCreateNotAllowedWithoutOwnerRole.
@Test
public void testCreateNotAllowedWithoutOwnerRole() {
String userId = "user";
String domain = "domain";
String interfaceName = "interfaceName";
OwnerRegistrationControlEntry data = new OwnerRegistrationControlEntry(userId, domain, interfaceName, TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
domainRoleEntryEntity.setUserId(userId);
domainRoleEntryEntity.setRole(Role.MASTER);
domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
entityManager.persist(domainRoleEntryEntity);
flushAndClear();
CreateOrUpdateResult<OwnerRegistrationControlEntry> result = null;
JoynrJeeMessageContext.getInstance().activate();
try {
joynrCallingPrincipal.setUsername(userId);
result = subject.createOrUpdate(data);
} finally {
JoynrJeeMessageContext.getInstance().deactivate();
}
assertNull(result);
flushAndClear();
OwnerRegistrationControlEntry[] persisted = subject.findByUserId(userId);
assertNotNull(persisted);
assertEquals(0, persisted.length);
}
use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class DomainRoleEntryManagerTest method testCurrentUserHasRoleInDomain.
private boolean testCurrentUserHasRoleInDomain(Role persistedRole, Set<String> domains) {
String username = "current-user";
DomainRoleEntryEntity entry = new DomainRoleEntryEntity();
entry.setUserId(username);
entry.setRole(persistedRole);
entry.setDomains(domains);
entityManager.persist(entry);
JoynrJeeMessageContext.getInstance().activate();
joynrCallingPrincipal.setUsername(username);
boolean result = subject.hasCurrentUserGotRoleForDomain(Role.MASTER, "domain");
JoynrJeeMessageContext.getInstance().deactivate();
return result;
}
use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class DomainRoleEntryManagerTest method create.
private DomainRoleEntryEntity create(String userId, Set<String> domains, Role role) {
DomainRoleEntryEntity entity = new DomainRoleEntryEntity();
entity.setUserId(userId);
entity.setDomains(domains);
entity.setRole(role);
entityManager.persist(entity);
return entity;
}
use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManagerTest method testFindByUserIdAndThatAreEditable.
@Test
public void testFindByUserIdAndThatAreEditable() {
String userId = "user";
String domain = "domain1";
create(userId, domain, "interfaceName1", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.YES, new Permission[0], ControlEntryType.MASTER);
create(userId, domain, "interfaceName1", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.YES, new Permission[0], ControlEntryType.MEDIATOR);
create(userId, "domain2", "interfaceName2", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.YES, new Permission[0], ControlEntryType.MASTER);
DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
domainRoleEntryEntity.setUserId(userId);
domainRoleEntryEntity.setRole(Role.MASTER);
domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
entityManager.persist(domainRoleEntryEntity);
flushAndClear();
MasterRegistrationControlEntry[] result = subject.findByUserIdAndThatAreEditable(userId, ControlEntryType.MASTER);
assertNotNull(result);
assertEquals(1, result.length);
assertEquals(domain, result[0].getDomain());
}
Aggregations