Search in sources :

Example 6 with MasterRegistrationControlEntry

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

the class GlobalDomainAccessControlListEditorBeanTest method testCreateAndUpdateMasterAndMediatorRegistrationControlEntry.

@Test
public void testCreateAndUpdateMasterAndMediatorRegistrationControlEntry() {
    for (ChangeType changeType : new ChangeType[] { ChangeType.ADD, ChangeType.UPDATE }) {
        Map<ControlEntryType, Function<MasterRegistrationControlEntry, Boolean>> globalDomainAccessControllerSubjectCalls = new HashMap<>();
        globalDomainAccessControllerSubjectCalls.put(ControlEntryType.MASTER, (updatedEntry) -> {
            return globalDomainAccessControlListEditorSubject.updateMasterRegistrationControlEntry(updatedEntry);
        });
        globalDomainAccessControllerSubjectCalls.put(ControlEntryType.MEDIATOR, (updatedEntry) -> {
            return globalDomainAccessControlListEditorSubject.updateMediatorRegistrationControlEntry(updatedEntry);
        });
        Map<ControlEntryType, Consumer<MasterRegistrationControlEntry>> multicastVerifiers = new HashMap<>();
        multicastVerifiers.put(ControlEntryType.MASTER, (mrce) -> {
            verify(globalDomainAccessControllerBeanMock).doFireMasterRegistrationControlEntryChanged(eq(changeType), eq(mrce));
        });
        multicastVerifiers.put(ControlEntryType.MEDIATOR, (mrce) -> {
            verify(globalDomainAccessControllerBeanMock).doFireMediatorRegistrationControlEntryChanged(eq(changeType), eq(mrce));
        });
        for (ControlEntryType type : new ControlEntryType[] { ControlEntryType.MASTER, ControlEntryType.MEDIATOR }) {
            reset(masterRegistrationControlEntryManagerMock);
            // reset(globalDomainAccessControllerSubscriptionPublisherMock);
            MasterRegistrationControlEntry mrce = new MasterRegistrationControlEntry(USER_ID, DOMAIN, INTERFACE_NAME, TrustLevel.LOW, new TrustLevel[0], TrustLevel.HIGH, new TrustLevel[0], Permission.ASK, new Permission[0]);
            when(masterRegistrationControlEntryManagerMock.createOrUpdate(mrce, type)).thenReturn(new CreateOrUpdateResult<MasterRegistrationControlEntry>(mrce, changeType));
            assertTrue(globalDomainAccessControllerSubjectCalls.get(type).apply(mrce));
            verify(masterRegistrationControlEntryManagerMock).createOrUpdate(mrce, type);
            multicastVerifiers.get(type).accept(mrce);
        }
    }
}
Also used : Function(java.util.function.Function) ControlEntryType(io.joynr.accesscontrol.global.jee.persistence.ControlEntryType) Consumer(java.util.function.Consumer) ChangeType(joynr.infrastructure.DacTypes.ChangeType) HashMap(java.util.HashMap) MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry) Test(org.junit.Test)

Example 7 with MasterRegistrationControlEntry

use of joynr.infrastructure.DacTypes.MasterRegistrationControlEntry 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)

Example 8 with MasterRegistrationControlEntry

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

the class MasterRegistrationControlEntryManagerTest method testCreate.

@Test
public void testCreate() {
    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]);
    CreateOrUpdateResult<MasterRegistrationControlEntry> result = subject.createOrUpdate(data, ControlEntryType.MASTER);
    assertNotNull(result);
    assertEquals(ChangeType.ADD, result.getChangeType());
    assertNotNull(result.getEntry());
    assertEquals(userId, result.getEntry().getUid());
    flushAndClear();
    MasterRegistrationControlEntry[] persisted = subject.findByUserIdAndType(userId, ControlEntryType.MASTER);
    assertNotNull(persisted);
    assertEquals(1, persisted.length);
    assertEquals(domain, persisted[0].getDomain());
    assertEquals(interfaceName, persisted[0].getInterfaceName());
    assertEquals(TrustLevel.LOW, persisted[0].getDefaultRequiredTrustLevel());
}
Also used : MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry) Test(org.junit.Test)

Example 9 with MasterRegistrationControlEntry

use of joynr.infrastructure.DacTypes.MasterRegistrationControlEntry 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 10 with MasterRegistrationControlEntry

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

the class MasterRegistrationControlEntryManager method mapEntityToJoynrType.

private MasterRegistrationControlEntry mapEntityToJoynrType(MasterRegistrationControlEntryEntity entity) {
    Set<TrustLevel> possibleRequiredTrustLevels = Sets.newHashSet(entity.getPossibleRequiredTrustLevels());
    Set<TrustLevel> possibleRequiredControlEntryChangeTrustLevels = Sets.newHashSet(entity.getPossibleRequiredControlEntryChangeTrustLevels());
    Set<Permission> possibleProviderPermissions = Sets.newHashSet(entity.getDefaultProviderPermission());
    MasterRegistrationControlEntry entry = new MasterRegistrationControlEntry(entity.getUserId(), entity.getDomain(), entity.getInterfaceName(), entity.getDefaultRequiredTrustLevel(), possibleRequiredTrustLevels.toArray(new TrustLevel[possibleRequiredTrustLevels.size()]), entity.getDefaultRequiredControlEntryChangeTrustLevel(), possibleRequiredControlEntryChangeTrustLevels.toArray(new TrustLevel[possibleRequiredControlEntryChangeTrustLevels.size()]), entity.getDefaultProviderPermission(), possibleProviderPermissions.toArray(new Permission[possibleProviderPermissions.size()]));
    return entry;
}
Also used : TrustLevel(joynr.infrastructure.DacTypes.TrustLevel) Permission(joynr.infrastructure.DacTypes.Permission) MasterRegistrationControlEntry(joynr.infrastructure.DacTypes.MasterRegistrationControlEntry)

Aggregations

MasterRegistrationControlEntry (joynr.infrastructure.DacTypes.MasterRegistrationControlEntry)11 Test (org.junit.Test)8 ControlEntryType (io.joynr.accesscontrol.global.jee.persistence.ControlEntryType)4 HashMap (java.util.HashMap)4 Function (java.util.function.Function)3 DomainRoleEntryEntity (io.joynr.accesscontrol.global.jee.persistence.DomainRoleEntryEntity)2 Consumer (java.util.function.Consumer)2 MasterRegistrationControlEntryEntity (io.joynr.accesscontrol.global.jee.persistence.MasterRegistrationControlEntryEntity)1 Supplier (java.util.function.Supplier)1 ChangeType (joynr.infrastructure.DacTypes.ChangeType)1 Permission (joynr.infrastructure.DacTypes.Permission)1 TrustLevel (joynr.infrastructure.DacTypes.TrustLevel)1