Search in sources :

Example 1 with OwnerRegistrationControlEntryEntity

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

the class OwnerRegistrationControlEntryManagerTest method testRemove.

@Test
public void testRemove() {
    String userId = "user";
    String domain = "domain";
    String interfaceName = "interfaceName";
    OwnerRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
    flushAndClear();
    OwnerRegistrationControlEntry removedEntry = subject.removeByUserIdDomainAndInterfaceName(userId, domain, interfaceName);
    assertNotNull(removedEntry);
    assertEquals(userId, removedEntry.getUid());
    flushAndClear();
    OwnerRegistrationControlEntryEntity persisted = entityManager.find(OwnerRegistrationControlEntryEntity.class, entity.getId());
    assertNull(persisted);
}
Also used : OwnerRegistrationControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity) OwnerRegistrationControlEntry(joynr.infrastructure.DacTypes.OwnerRegistrationControlEntry) Test(org.junit.Test)

Example 2 with OwnerRegistrationControlEntryEntity

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

the class OwnerRegistrationControlEntryManagerTest method create.

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

Example 3 with OwnerRegistrationControlEntryEntity

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

the class OwnerRegistrationControlEntryManagerTest method testUpdate.

@Test
public void testUpdate() {
    String userId = "user";
    String domain = "domain";
    String interfaceName = "interfaceName";
    OwnerRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
    flushAndClear();
    OwnerRegistrationControlEntry updatedData = new OwnerRegistrationControlEntry(userId, domain, interfaceName, TrustLevel.HIGH, TrustLevel.LOW, Permission.NO);
    CreateOrUpdateResult<OwnerRegistrationControlEntry> result = subject.createOrUpdate(updatedData);
    assertNotNull(result);
    assertEquals(ChangeType.UPDATE, result.getChangeType());
    assertNotNull(result.getEntry());
    assertEquals(userId, result.getEntry().getUid());
    flushAndClear();
    OwnerRegistrationControlEntryEntity persisted = entityManager.find(OwnerRegistrationControlEntryEntity.class, entity.getId());
    assertNotNull(persisted);
    assertEquals(TrustLevel.HIGH, persisted.getRequiredTrustLevel());
    assertEquals(TrustLevel.LOW, persisted.getRequiredAceChangeTrustLevel());
    assertEquals(Permission.NO, persisted.getProviderPermission());
}
Also used : OwnerRegistrationControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity) OwnerRegistrationControlEntry(joynr.infrastructure.DacTypes.OwnerRegistrationControlEntry) Test(org.junit.Test)

Example 4 with OwnerRegistrationControlEntryEntity

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

the class OwnerRegistrationControlEntryManager method findByUserIdDomainAndInterfaceName.

private OwnerRegistrationControlEntryEntity findByUserIdDomainAndInterfaceName(String userId, String domain, String interfaceName) {
    Query query = entityManager.createQuery("select orce from OwnerRegistrationControlEntryEntity orce " + "where orce.userId = :userId and orce.domain = :domain and orce.interfaceName = :interfaceName", OwnerRegistrationControlEntryEntity.class);
    query.setParameter("userId", userId);
    query.setParameter("domain", domain);
    query.setParameter("interfaceName", interfaceName);
    List<OwnerRegistrationControlEntryEntity> resultList = query.getResultList();
    OwnerRegistrationControlEntryEntity entity = null;
    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", OwnerRegistrationControlEntryEntity.class.getSimpleName(), userId, domain, interfaceName));
    }
    return entity;
}
Also used : OwnerRegistrationControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity) Query(javax.persistence.Query) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 5 with OwnerRegistrationControlEntryEntity

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

the class OwnerRegistrationControlEntryManagerTest method testRemoveNotAllowedWithoutOwnerRole.

@Test
public void testRemoveNotAllowedWithoutOwnerRole() {
    String userId = "user";
    String domain = "domain";
    String interfaceName = "interfaceName";
    OwnerRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.MID, TrustLevel.HIGH, Permission.ASK);
    flushAndClear();
    JoynrJeeMessageContext.getInstance().activate();
    try {
        joynrCallingPrincipal.setUsername(userId);
        assertNull(subject.removeByUserIdDomainAndInterfaceName(userId, domain, interfaceName));
    } finally {
        JoynrJeeMessageContext.getInstance().deactivate();
    }
    flushAndClear();
    OwnerRegistrationControlEntryEntity persisted = entityManager.find(OwnerRegistrationControlEntryEntity.class, entity.getId());
    assertNotNull(persisted);
}
Also used : OwnerRegistrationControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity) Test(org.junit.Test)

Aggregations

OwnerRegistrationControlEntryEntity (io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity)6 Test (org.junit.Test)3 OwnerRegistrationControlEntry (joynr.infrastructure.DacTypes.OwnerRegistrationControlEntry)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 Query (javax.persistence.Query)1