use of io.joynr.accesscontrol.global.jee.persistence.MasterRegistrationControlEntryEntity in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManagerTest method testRemoveNotAllowedWithoutMasterRole.
@Test
public void testRemoveNotAllowedWithoutMasterRole() {
String userId = "userId";
String domain = "domain";
String interfaceName = "interfaceName";
MasterRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.ASK, new Permission[0], ControlEntryType.MASTER);
flushAndClear();
JoynrJeeMessageContext.getInstance().activate();
try {
joynrCallingPrincipal.setUsername(userId);
assertNull(subject.removeByUserIdDomainInterfaceNameAndType(userId, domain, interfaceName, ControlEntryType.MASTER));
} finally {
JoynrJeeMessageContext.getInstance().deactivate();
}
flushAndClear();
MasterRegistrationControlEntryEntity persisted = entityManager.find(MasterRegistrationControlEntryEntity.class, entity.getId());
assertNotNull(persisted);
}
use of io.joynr.accesscontrol.global.jee.persistence.MasterRegistrationControlEntryEntity in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManagerTest method testUpdate.
@Test
public void testUpdate() {
String userId = "user";
String domain = "domain1";
String interfaceName = "interfaceName1";
MasterRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.YES, new Permission[0], ControlEntryType.MASTER);
flushAndClear();
MasterRegistrationControlEntry updatedData = new MasterRegistrationControlEntry(userId, domain, interfaceName, TrustLevel.LOW, new TrustLevel[] { TrustLevel.MID, TrustLevel.HIGH }, TrustLevel.HIGH, new TrustLevel[0], Permission.ASK, new Permission[] { Permission.NO });
CreateOrUpdateResult<MasterRegistrationControlEntry> result = subject.createOrUpdate(updatedData, ControlEntryType.MASTER);
assertNotNull(result);
assertEquals(ChangeType.UPDATE, result.getChangeType());
assertNotNull(result.getEntry());
assertEquals(userId, result.getEntry().getUid());
flushAndClear();
MasterRegistrationControlEntryEntity persisted = entityManager.find(MasterRegistrationControlEntryEntity.class, entity.getId());
assertNotNull(persisted);
assertEquals(TrustLevel.LOW, persisted.getDefaultRequiredTrustLevel());
assertEquals(2, persisted.getPossibleRequiredTrustLevels().size());
assertEquals(TrustLevel.HIGH, persisted.getDefaultRequiredControlEntryChangeTrustLevel());
assertEquals(Permission.ASK, persisted.getDefaultProviderPermission());
}
use of io.joynr.accesscontrol.global.jee.persistence.MasterRegistrationControlEntryEntity in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManager method createOrUpdate.
public CreateOrUpdateResult<MasterRegistrationControlEntry> createOrUpdate(MasterRegistrationControlEntry updatedMasterRce, ControlEntryType type) {
if (!domainRoleEntryManager.hasCurrentUserGotRoleForDomain(Role.MASTER, updatedMasterRce.getDomain())) {
return null;
}
MasterRegistrationControlEntryEntity entity = findByUserIdDomainInterfaceNameOperationAndType(updatedMasterRce.getUid(), updatedMasterRce.getDomain(), updatedMasterRce.getInterfaceName(), type);
boolean created = entity == null;
if (created) {
entity = new MasterRegistrationControlEntryEntity();
entity.setUserId(updatedMasterRce.getUid());
entity.setDomain(updatedMasterRce.getDomain());
entity.setInterfaceName(updatedMasterRce.getInterfaceName());
entity.setType(type);
entityManager.persist(entity);
}
entity.setDefaultRequiredTrustLevel(updatedMasterRce.getDefaultRequiredTrustLevel());
entity.setPossibleRequiredTrustLevels(Sets.newHashSet(updatedMasterRce.getPossibleRequiredTrustLevels()));
entity.setDefaultRequiredControlEntryChangeTrustLevel(updatedMasterRce.getDefaultRequiredControlEntryChangeTrustLevel());
entity.setPossibleRequiredControlEntryChangeTrustLevels(Sets.newHashSet(updatedMasterRce.getPossibleRequiredControlEntryChangeTrustLevels()));
entity.setDefaultProviderPermission(updatedMasterRce.getDefaultProviderPermission());
entity.setPossibleProviderPermissions(Sets.newHashSet(updatedMasterRce.getPossibleProviderPermissions()));
return new CreateOrUpdateResult<>(mapEntityToJoynrType(entity), created ? ChangeType.ADD : ChangeType.UPDATE);
}
use of io.joynr.accesscontrol.global.jee.persistence.MasterRegistrationControlEntryEntity in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManagerTest method testRemove.
@Test
public void testRemove() {
String userId = "userId";
String domain = "domain";
String interfaceName = "interfaceName";
MasterRegistrationControlEntryEntity entity = create(userId, domain, interfaceName, TrustLevel.HIGH, new TrustLevel[0], TrustLevel.LOW, new TrustLevel[0], Permission.ASK, new Permission[0], ControlEntryType.MASTER);
flushAndClear();
assertNotNull(subject.removeByUserIdDomainInterfaceNameAndType(userId, domain, interfaceName, ControlEntryType.MASTER));
flushAndClear();
MasterRegistrationControlEntryEntity persisted = entityManager.find(MasterRegistrationControlEntryEntity.class, entity.getId());
assertNull(persisted);
}
use of io.joynr.accesscontrol.global.jee.persistence.MasterRegistrationControlEntryEntity in project joynr by bmwcarit.
the class MasterRegistrationControlEntryManagerTest method create.
private MasterRegistrationControlEntryEntity create(String userId, String domain, String interfaceName, TrustLevel trustLevel, TrustLevel[] possibleTrustLevels, TrustLevel changeTrustLevel, TrustLevel[] possibleChangeTrustLevels, Permission permission, Permission[] possiblePermissions, ControlEntryType type) {
MasterRegistrationControlEntryEntity entity = new MasterRegistrationControlEntryEntity();
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.setDefaultProviderPermission(permission);
entity.setPossibleProviderPermissions(Sets.newHashSet(possiblePermissions));
entity.setType(type);
entityManager.persist(entity);
return entity;
}
Aggregations