Search in sources :

Example 1 with MasterAccessControlEntryEntity

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

the class MasterAccessControlEntryManager method createOrUpdate.

public CreateOrUpdateResult<MasterAccessControlEntry> createOrUpdate(MasterAccessControlEntry updatedMasterAce, ControlEntryType type) {
    MasterAccessControlEntryEntity entity = findByUserIdDomainInterfaceNameOperationAndType(updatedMasterAce.getUid(), updatedMasterAce.getDomain(), updatedMasterAce.getInterfaceName(), updatedMasterAce.getOperation(), type);
    if (!domainRoleEntryManager.hasCurrentUserGotRoleForDomain(Role.MASTER, updatedMasterAce.getDomain())) {
        return null;
    }
    boolean created = entity == null;
    if (created) {
        entity = new MasterAccessControlEntryEntity();
        entity.setUserId(updatedMasterAce.getUid());
        entity.setDomain(updatedMasterAce.getDomain());
        entity.setInterfaceName(updatedMasterAce.getInterfaceName());
        entity.setOperation(updatedMasterAce.getOperation());
        entity.setType(type);
        entityManager.persist(entity);
    }
    entity.setDefaultRequiredTrustLevel(updatedMasterAce.getDefaultRequiredTrustLevel());
    entity.setPossibleRequiredTrustLevels(Sets.newHashSet(updatedMasterAce.getPossibleRequiredTrustLevels()));
    entity.setDefaultRequiredControlEntryChangeTrustLevel(updatedMasterAce.getDefaultRequiredControlEntryChangeTrustLevel());
    entity.setPossibleRequiredControlEntryChangeTrustLevels(Sets.newHashSet(updatedMasterAce.getPossibleRequiredControlEntryChangeTrustLevels()));
    entity.setDefaultConsumerPermission(updatedMasterAce.getDefaultConsumerPermission());
    entity.setPossibleConsumerPermissions(Sets.newHashSet(updatedMasterAce.getPossibleConsumerPermissions()));
    return new CreateOrUpdateResult<>(mapEntityToJoynrType(entity), created ? ChangeType.ADD : ChangeType.UPDATE);
}
Also used : MasterAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity)

Example 2 with MasterAccessControlEntryEntity

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

the class MasterAccessControlEntryManager method findByDomainAndInterfaceName.

public MasterAccessControlEntry[] findByDomainAndInterfaceName(String domain, String interfaceName, ControlEntryType type) {
    Query query = entityManager.createQuery("select mace from MasterAccessControlEntryEntity mace " + "where mace.domain = :domain and mace.interfaceName = :interfaceName and mace.type = :type", MasterAccessControlEntryEntity.class);
    query.setParameter("domain", domain);
    query.setParameter("interfaceName", interfaceName);
    query.setParameter("type", type);
    List<MasterAccessControlEntryEntity> resultList = query.getResultList();
    Set<MasterAccessControlEntry> resultSet = resultList.stream().map(this::mapEntityToJoynrType).collect(toSet());
    return resultSet.toArray(new MasterAccessControlEntry[resultSet.size()]);
}
Also used : MasterAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity) Query(javax.persistence.Query) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry)

Example 3 with MasterAccessControlEntryEntity

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

the class MasterAccessControlEntryManagerTest method testRemove.

@Test
public void testRemove() {
    MasterAccessControlEntryEntity entity = create("user", "domain", "interfaceName", TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], "operation", Permission.YES, new Permission[0]);
    flushAndClear();
    MasterAccessControlEntry result = subject.removeByUserIdDomainInterfaceNameAndOperation(entity.getUserId(), entity.getDomain(), entity.getInterfaceName(), entity.getOperation(), MASTER);
    assertNotNull(result);
    assertEquals("user", result.getUid());
    flushAndClear();
    MasterAccessControlEntryEntity persisted = entityManager.find(MasterAccessControlEntryEntity.class, entity.getId());
    assertNull(persisted);
}
Also used : MasterAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity) MasterAccessControlEntry(joynr.infrastructure.DacTypes.MasterAccessControlEntry) Test(org.junit.Test)

Example 4 with MasterAccessControlEntryEntity

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

the class MasterAccessControlEntryManagerTest method create.

private MasterAccessControlEntryEntity create(String userId, String domain, String interfaceName, TrustLevel trustLevel, TrustLevel[] possibleTrustLevels, TrustLevel changeTrustLevel, TrustLevel[] possibleChangeTrustLevels, String operation, Permission permission, Permission[] possiblePermissions, ControlEntryType type) {
    MasterAccessControlEntryEntity entity = new MasterAccessControlEntryEntity();
    entity.setUserId(userId);
    entity.setDomain(domain);
    entity.setInterfaceName(interfaceName);
    entity.setDefaultRequiredTrustLevel(trustLevel);
    entity.setPossibleRequiredTrustLevels(Sets.newHashSet(possibleTrustLevels));
    entity.setDefaultRequiredControlEntryChangeTrustLevel(changeTrustLevel);
    entity.setPossibleRequiredControlEntryChangeTrustLevels(Sets.newHashSet(possibleChangeTrustLevels));
    entity.setOperation(operation);
    entity.setDefaultConsumerPermission(permission);
    entity.setPossibleConsumerPermissions(Sets.newHashSet(possiblePermissions));
    entity.setType(type);
    entityManager.persist(entity);
    return entity;
}
Also used : MasterAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity)

Example 5 with MasterAccessControlEntryEntity

use of io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity 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)

Aggregations

MasterAccessControlEntryEntity (io.joynr.accesscontrol.global.jee.persistence.MasterAccessControlEntryEntity)8 MasterAccessControlEntry (joynr.infrastructure.DacTypes.MasterAccessControlEntry)5 Query (javax.persistence.Query)4 Test (org.junit.Test)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1