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);
}
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()]);
}
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);
}
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;
}
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);
}
Aggregations