Search in sources :

Example 1 with OwnerAccessControlEntryEntity

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

the class OwnerAccessControlEntryManagerTest method create.

private OwnerAccessControlEntryEntity create(String userId, String domain, String interfaceName, TrustLevel requiredTrustLevel, TrustLevel requiredAceChangeTrustLevel, String operation, Permission consumerPermission) {
    OwnerAccessControlEntryEntity entity = new OwnerAccessControlEntryEntity();
    entity.setUserId(userId);
    entity.setDomain(domain);
    entity.setInterfaceName(interfaceName);
    entity.setRequiredTrustLevel(requiredTrustLevel);
    entity.setRequiredAceChangeTrustLevel(requiredAceChangeTrustLevel);
    entity.setOperation(operation);
    entity.setConsumerPermission(consumerPermission);
    entityManager.persist(entity);
    return entity;
}
Also used : OwnerAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerAccessControlEntryEntity)

Example 2 with OwnerAccessControlEntryEntity

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

the class OwnerAccessControlEntryManagerTest method testRemoveNotAllowed.

@Test
public void testRemoveNotAllowed() {
    String userId = "userId";
    String domain = "domain";
    String interfaceName = "interfaceName";
    String operation = "operation";
    OwnerAccessControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.MID, TrustLevel.HIGH, operation, Permission.YES);
    flushAndClear();
    OwnerAccessControlEntry result = null;
    JoynrJeeMessageContext.getInstance().activate();
    try {
        joynrCallingPrincipal.setUsername(userId);
        result = subject.removeByUserIdDomainInterfaceNameAndOperation(userId, domain, interfaceName, operation);
    } finally {
        JoynrJeeMessageContext.getInstance().deactivate();
    }
    assertNull(result);
    flushAndClear();
    OwnerAccessControlEntryEntity persisted = entityManager.find(OwnerAccessControlEntryEntity.class, entity.getId());
    assertNotNull(persisted);
}
Also used : OwnerAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerAccessControlEntryEntity) OwnerAccessControlEntry(joynr.infrastructure.DacTypes.OwnerAccessControlEntry) Test(org.junit.Test)

Example 3 with OwnerAccessControlEntryEntity

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

the class OwnerAccessControlEntryManagerTest method testUpdate.

@Test
public void testUpdate() {
    OwnerAccessControlEntryEntity entity = create("user", "domain", "interfaceName", TrustLevel.HIGH, TrustLevel.LOW, "operation", Permission.ASK);
    entityManager.persist(entity);
    flushAndClear();
    OwnerAccessControlEntry updateData = new OwnerAccessControlEntry("user", "domain", "interfaceName", TrustLevel.MID, TrustLevel.HIGH, "operation", Permission.YES);
    CreateOrUpdateResult<OwnerAccessControlEntry> result = subject.createOrUpdate(updateData);
    assertNotNull(result);
    assertEquals(ChangeType.UPDATE, result.getChangeType());
    assertNotNull(result.getEntry());
    assertEquals("user", result.getEntry().getUid());
    flushAndClear();
    entity = entityManager.find(OwnerAccessControlEntryEntity.class, entity.getId());
    assertNotNull(entity);
    assertEquals(TrustLevel.MID, entity.getRequiredTrustLevel());
    assertEquals(TrustLevel.HIGH, entity.getRequiredAceChangeTrustLevel());
    assertEquals(Permission.YES, entity.getConsumerPermission());
}
Also used : OwnerAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerAccessControlEntryEntity) OwnerAccessControlEntry(joynr.infrastructure.DacTypes.OwnerAccessControlEntry) Test(org.junit.Test)

Example 4 with OwnerAccessControlEntryEntity

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

the class OwnerAccessControlEntryManager method findByUserIdDomainInterfaceNameAndOperation.

private OwnerAccessControlEntryEntity findByUserIdDomainInterfaceNameAndOperation(String userId, String domain, String interfaceName, String operation) {
    OwnerAccessControlEntryEntity entity = null;
    Query query = entityManager.createQuery("select oace from OwnerAccessControlEntryEntity oace where " + "oace.userId = :userId and oace.domain = :domain and oace.interfaceName = :interfaceName " + "and oace.operation = :operation", OwnerAccessControlEntryEntity.class);
    query.setParameter("userId", userId);
    query.setParameter("domain", domain);
    query.setParameter("interfaceName", interfaceName);
    query.setParameter("operation", operation);
    List<OwnerAccessControlEntryEntity> resultList = query.getResultList();
    if (resultList.size() == 1) {
        entity = resultList.get(0);
    } else if (resultList.size() > 1) {
        throw new JoynrIllegalStateException(format("Too many results found for %s for userId / domain / interfaceName / operation: %s / %s / %s / %s", OwnerAccessControlEntryEntity.class.getSimpleName(), userId, domain, interfaceName, operation));
    }
    return entity;
}
Also used : OwnerAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerAccessControlEntryEntity) Query(javax.persistence.Query) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 5 with OwnerAccessControlEntryEntity

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

the class OwnerAccessControlEntryManager method createOrUpdate.

public CreateOrUpdateResult<OwnerAccessControlEntry> createOrUpdate(OwnerAccessControlEntry updatedOwnerAce) {
    if (!domainRoleEntryManager.hasCurrentUserGotRoleForDomain(Role.OWNER, updatedOwnerAce.getDomain())) {
        return null;
    }
    OwnerAccessControlEntryEntity entity = findByUserIdDomainInterfaceNameAndOperation(updatedOwnerAce.getUid(), updatedOwnerAce.getDomain(), updatedOwnerAce.getInterfaceName(), updatedOwnerAce.getOperation());
    boolean created = entity == null;
    if (created) {
        entity = new OwnerAccessControlEntryEntity();
        entity.setUserId(updatedOwnerAce.getUid());
        entity.setDomain(updatedOwnerAce.getDomain());
        entity.setInterfaceName(updatedOwnerAce.getInterfaceName());
        entity.setOperation(updatedOwnerAce.getOperation());
        entityManager.persist(entity);
    }
    entity.setRequiredTrustLevel(updatedOwnerAce.getRequiredTrustLevel());
    entity.setRequiredAceChangeTrustLevel(updatedOwnerAce.getRequiredAceChangeTrustLevel());
    entity.setConsumerPermission(updatedOwnerAce.getConsumerPermission());
    return new CreateOrUpdateResult<>(mapEntityToJoynrType(entity), created ? ChangeType.ADD : ChangeType.UPDATE);
}
Also used : OwnerAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerAccessControlEntryEntity)

Aggregations

OwnerAccessControlEntryEntity (io.joynr.accesscontrol.global.jee.persistence.OwnerAccessControlEntryEntity)7 OwnerAccessControlEntry (joynr.infrastructure.DacTypes.OwnerAccessControlEntry)3 Test (org.junit.Test)3 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 Query (javax.persistence.Query)1