Search in sources :

Example 6 with DomainRoleEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.

the class MasterRegistrationControlEntryManagerTest method testCreateNotAllowedWithoutMasterRole.

@Test
public void testCreateNotAllowedWithoutMasterRole() {
    String userId = "userId";
    String domain = "domain";
    String interfaceName = "interfaceName";
    MasterRegistrationControlEntry data = new MasterRegistrationControlEntry(userId, domain, interfaceName, TrustLevel.LOW, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.ASK, new Permission[0]);
    DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
    domainRoleEntryEntity.setUserId(userId);
    domainRoleEntryEntity.setRole(Role.OWNER);
    domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
    entityManager.persist(domainRoleEntryEntity);
    flushAndClear();
    JoynrJeeMessageContext.getInstance().activate();
    CreateOrUpdateResult<MasterRegistrationControlEntry> result = null;
    try {
        joynrCallingPrincipal.setUsername(userId);
        result = subject.createOrUpdate(data, ControlEntryType.MASTER);
    } finally {
        JoynrJeeMessageContext.getInstance().deactivate();
    }
    assertNull(result);
    flushAndClear();
    MasterRegistrationControlEntry[] persisted = subject.findByUserIdAndType(userId, ControlEntryType.MASTER);
    assertNotNull(persisted);
    assertEquals(0, persisted.length);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry) Test(org.junit.Test)

Example 7 with DomainRoleEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.

the class MasterAccessControlEntryManagerTest method testUserNotAllowedToCreateOrUpdate.

@Test
public void testUserNotAllowedToCreateOrUpdate() {
    String userId = "user";
    String domain = "domain";
    DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
    domainRoleEntryEntity.setUserId(userId);
    domainRoleEntryEntity.setRole(Role.OWNER);
    domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
    entityManager.persist(domainRoleEntryEntity);
    create(userId, domain, "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.YES, new Permission[0]);
    flushAndClear();
    MasterAccessControlEntry updatedData = new MasterAccessControlEntry(userId, domain, "interfaceName", TrustLevel.LOW, new TrustLevel[] { TrustLevel.HIGH }, TrustLevel.HIGH, new TrustLevel[0], "operation", Permission.ASK, new Permission[] { Permission.NO });
    CreateOrUpdateResult<MasterAccessControlEntry> result = null;
    JoynrJeeMessageContext.getInstance().activate();
    try {
        joynrCallingPrincipal.setUsername(userId);
        result = subject.createOrUpdate(updatedData, ControlEntryType.MASTER);
    } finally {
        JoynrJeeMessageContext.getInstance().deactivate();
    }
    assertNull(result);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Example 8 with DomainRoleEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.

the class OwnerAccessControlEntryManagerTest method testFindByUserIdAndAreEditable.

@Test
public void testFindByUserIdAndAreEditable() {
    String userId = "user1";
    String domain = "domain1";
    String interfaceName = "interfaceName1";
    String operation = "operation1";
    create(userId, domain, interfaceName, TrustLevel.HIGH, TrustLevel.HIGH, operation, Permission.ASK);
    create(userId, "otherdomain", "interfaceName", TrustLevel.LOW, TrustLevel.HIGH, "operation2", Permission.NO);
    DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
    domainRoleEntryEntity.setUserId(userId);
    domainRoleEntryEntity.setRole(Role.OWNER);
    domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
    entityManager.persist(domainRoleEntryEntity);
    flushAndClear();
    OwnerAccessControlEntry[] result = subject.findByUserIdThatAreEditable(userId);
    assertNotNull(result);
    assertEquals(1, result.length);
    assertEquals(interfaceName, result[0].getInterfaceName());
    assertEquals(operation, result[0].getOperation());
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) OwnerAccessControlEntry(joynr.infrastructure.DacTypes.OwnerAccessControlEntry) Test(org.junit.Test)

Example 9 with DomainRoleEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.

the class OwnerAccessControlEntryManagerTest method testCreateNotAllowedWithoutOwnerRole.

@Test
public void testCreateNotAllowedWithoutOwnerRole() {
    String userId = "user";
    String domain = "domain";
    String interfaceName = "interfaceName";
    String operation = "operation";
    DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
    domainRoleEntryEntity.setUserId(userId);
    domainRoleEntryEntity.setRole(Role.MASTER);
    domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
    entityManager.persist(domainRoleEntryEntity);
    flushAndClear();
    OwnerAccessControlEntry data = new OwnerAccessControlEntry(userId, domain, interfaceName, TrustLevel.HIGH, TrustLevel.LOW, operation, Permission.ASK);
    CreateOrUpdateResult<OwnerAccessControlEntry> result = null;
    JoynrJeeMessageContext.getInstance().activate();
    try {
        joynrCallingPrincipal.setUsername(userId);
        result = subject.createOrUpdate(data);
    } finally {
        JoynrJeeMessageContext.getInstance().deactivate();
    }
    assertNull(result);
    flushAndClear();
    assertEquals(0, subject.findByUserId(userId).length);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) OwnerAccessControlEntry(joynr.infrastructure.DacTypes.OwnerAccessControlEntry) Test(org.junit.Test)

Example 10 with DomainRoleEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity in project joynr by bmwcarit.

the class OwnerRegistrationControlEntryManagerTest method testFindByUserIdAndThatAreEditable.

@Test
public void testFindByUserIdAndThatAreEditable() {
    String userId = "userId";
    String domain = "domain1";
    create(userId, domain, "interfaceName", TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
    create(userId, "domain2", "interfaceName", TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
    DomainRoleEntryEntity domainRoleEntryEntity = new DomainRoleEntryEntity();
    domainRoleEntryEntity.setUserId(userId);
    domainRoleEntryEntity.setRole(Role.OWNER);
    domainRoleEntryEntity.setDomains(Sets.newHashSet(domain));
    entityManager.persist(domainRoleEntryEntity);
    flushAndClear();
    OwnerRegistrationControlEntry[] result = subject.findByUserIdAndThatIsEditable(userId);
    assertNotNull(result);
    assertEquals(1, result.length);
}
Also used : DomainRoleEntryEntity(io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity) OwnerRegistrationControlEntry(joynr.infrastructure.DacTypes.OwnerRegistrationControlEntry) 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