Search in sources :

Example 1 with DomainRoleEntryEntity

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());
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Example 2 with DomainRoleEntryEntity

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);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) OwnerRegistrationControlEntry(joynr.infrastructure.DacTypes.OwnerRegistrationControlEntry) Test(org.junit.Test)

Example 3 with DomainRoleEntryEntity

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;
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)

Example 4 with DomainRoleEntryEntity

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;
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)

Example 5 with DomainRoleEntryEntity

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());
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry) Test(org.junit.Test)

Aggregations

DomainRoleEntryEntity (io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)15 Test (org.junit.Test)9 Query (javax.persistence.Query)2 DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)2 MasterAccessControlEntry (joynr.infrastructure.DacTypes.MasterAccessControlEntry)2 MasterRegistrationControlEntry (joynr.infrastructure.DacTypes.MasterRegistrationControlEntry)2 OwnerAccessControlEntry (joynr.infrastructure.DacTypes.OwnerAccessControlEntry)2 OwnerRegistrationControlEntry (joynr.infrastructure.DacTypes.OwnerRegistrationControlEntry)2