Search in sources :

Example 26 with MasterAccessControlEntry

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

the class GlobalDomainAccessControlListEditorBeanTest method testRemoveMasterAccessControlEntry.

@Test
public void testRemoveMasterAccessControlEntry() {
    MasterAccessControlEntry mace = new MasterAccessControlEntry(USER_ID, DOMAIN, INTERFACE_NAME, TrustLevel.LOW, new TrustLevel[0], TrustLevel.HIGH, new TrustLevel[0], OPERATION, Permission.ASK, new Permission[0]);
    when(masterAccessControlEntryManagerMock.removeByUserIdDomainInterfaceNameAndOperation(USER_ID, DOMAIN, INTERFACE_NAME, OPERATION, ControlEntryType.MASTER)).thenReturn(mace);
    Boolean result = globalDomainAccessControlListEditorSubject.removeMasterAccessControlEntry(USER_ID, DOMAIN, INTERFACE_NAME, OPERATION);
    assertEquals(Boolean.TRUE, result);
    verify(masterAccessControlEntryManagerMock).removeByUserIdDomainInterfaceNameAndOperation(eq(USER_ID), eq(DOMAIN), eq(INTERFACE_NAME), eq(OPERATION), eq(ControlEntryType.MASTER));
    verify(globalDomainAccessControllerBeanMock).doFireMasterAccessControlEntryChanged(eq(ChangeType.REMOVE), eq(mace));
}
Also used : MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Example 27 with MasterAccessControlEntry

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

the class MasterAccessControlEntryManagerTest method testUpdate.

@Test
public void testUpdate() {
    create("user", "domain", "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.YES, new Permission[0]);
    MasterAccessControlEntry entry = subject.findByUserId("user", MASTER)[0];
    flushAndClear();
    entry.setDefaultRequiredTrustLevel(TrustLevel.LOW);
    entry.setPossibleRequiredTrustLevels(new TrustLevel[] { TrustLevel.HIGH, TrustLevel.MID });
    entry.setDefaultConsumerPermission(Permission.ASK);
    CreateOrUpdateResult<MasterAccessControlEntry> result = subject.createOrUpdate(entry, MASTER);
    assertNotNull(result);
    assertEquals(ChangeType.UPDATE, result.getChangeType());
    assertNotNull(result.getEntry());
    assertEquals("user", result.getEntry().getUid());
    flushAndClear();
    entry = subject.findByUserId("user", MASTER)[0];
    assertEquals(TrustLevel.LOW, entry.getDefaultRequiredTrustLevel());
    assertEquals(2, entry.getPossibleRequiredTrustLevels().length);
    assertEquals(Permission.ASK, entry.getDefaultConsumerPermission());
}
Also used : MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Example 28 with MasterAccessControlEntry

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

the class MasterAccessControlEntryManagerTest method testRemoveNotAllowed.

@Test
public void testRemoveNotAllowed() {
    String userId = "user";
    MasterAccessControlEntryEntity entity = create(userId, "domain", "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.YES, new Permission[0]);
    flushAndClear();
    MasterAccessControlEntry result = null;
    JoynrJeeMessageContext.getInstance().activate();
    try {
        joynrCallingPrincipal.setUsername(userId);
        subject.removeByUserIdDomainInterfaceNameAndOperation(entity.getUserId(), entity.getDomain(), entity.getInterfaceName(), entity.getOperation(), MASTER);
    } finally {
        JoynrJeeMessageContext.getInstance().deactivate();
    }
    assertNull(result);
    flushAndClear();
    MasterAccessControlEntryEntity persisted = entityManager.find(MasterAccessControlEntryEntity.class, entity.getId());
    assertNotNull(persisted);
}
Also used : MasterAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Example 29 with MasterAccessControlEntry

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

the class MasterAccessControlEntryManagerTest method testCorrectTypeFound.

@Test
public void testCorrectTypeFound() {
    create("user", "domain", "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.YES, new Permission[0], MASTER);
    create("user", "domain", "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.YES, new Permission[0], MEDIATOR);
    flushAndClear();
    for (ControlEntryType type : new ControlEntryType[] { MASTER, MEDIATOR }) {
        MasterAccessControlEntry[] persisted = subject.findByUserId("user", type);
        assertNotNull("Not found for user and " + type, persisted);
        assertEquals("Not found for user and " + type, 1, persisted.length);
    }
}
Also used : ControlEntryType(io.joynr.accesscontrol.global.jee.persistence.ControlEntryType) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Example 30 with MasterAccessControlEntry

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

the class MasterAccessControlEntryManagerTest method testCreate.

@Test
public void testCreate() {
    MasterAccessControlEntry newEntry = new MasterAccessControlEntry("user", "domain", "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.ASK, new Permission[0]);
    CreateOrUpdateResult<MasterAccessControlEntry> result = subject.createOrUpdate(newEntry, MASTER);
    assertNotNull(result);
    assertEquals(ChangeType.ADD, result.getChangeType());
    assertNotNull(result.getEntry());
    assertEquals("user", result.getEntry().getUid());
    flushAndClear();
    MasterAccessControlEntry[] persisted = subject.findByUserId("user", MASTER);
    assertNotNull(persisted);
    assertEquals(1, persisted.length);
    MasterAccessControlEntry entry = persisted[0];
    assertEquals("user", entry.getUid());
    assertEquals("domain", entry.getDomain());
    assertEquals("interfaceName", entry.getInterfaceName());
    assertEquals("operation", entry.getOperation());
    assertEquals(TrustLevel.HIGH, entry.getDefaultRequiredTrustLevel());
    assertEquals(TrustLevel.LOW, entry.getDefaultRequiredControlEntryChangeTrustLevel());
    assertEquals(Permission.ASK, entry.getDefaultConsumerPermission());
    assertNotNull(entry.getPossibleRequiredTrustLevels());
    assertEquals(0, entry.getPossibleRequiredTrustLevels().length);
    assertNotNull(entry.getPossibleRequiredControlEntryChangeTrustLevels());
    assertEquals(0, entry.getPossibleRequiredControlEntryChangeTrustLevels().length);
    assertNotNull(entry.getPossibleConsumerPermissions());
    assertEquals(0, entry.getPossibleConsumerPermissions().length);
}
Also used : MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Aggregations

MasterAccessControlEntry (joynr.infrastructure.DacTypes.MasterAccessControlEntry)41 Test (org.junit.Test)14 OwnerAccessControlEntry (joynr.infrastructure.DacTypes.OwnerAccessControlEntry)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)7 Permission (joynr.infrastructure.DacTypes.Permission)6 TrustLevel (joynr.infrastructure.DacTypes.TrustLevel)6 Before (org.junit.Before)6 MasterAccessControlEntryEntity (io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity)5 ArrayList (java.util.ArrayList)4 Query (javax.persistence.Query)3 DomainRoleEntryEntity (io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)2 UserDomainInterfaceOperationKey (io.joynr.accesscontrol.primarykey.UserDomainInterfaceOperationKey)2 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 MessagingQos (io.joynr.messaging.MessagingQos)2 Promise (io.joynr.provider.Promise)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DomainAccessControlStoreEhCache (io.joynr.accesscontrol.DomainAccessControlStoreEhCache)1 ControlEntryType (io.joynr.accesscontrol.global.jee.persistence.ControlEntryType)1 ProxyBuilderFactoryImpl (io.joynr.proxy.ProxyBuilderFactoryImpl)1