use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.
the class RoleExportBulkActionIntegrationTest method testExportAndImportRoleGuaranteeByRole.
@Test
public void testExportAndImportRoleGuaranteeByRole() {
IdmRoleDto role = createRole();
IdmRoleDto guaranteeRole = this.getHelper().createRole();
IdmRoleGuaranteeRoleDto guarantee = this.getHelper().createRoleGuaranteeRole(role, guaranteeRole);
// Make export, upload and import
IdmExportImportDto importBatch = executeExportAndImport(role, RoleExportBulkAction.NAME, ImmutableMap.of(EXECUTE_BEFORE_DTO_DELETE, this::deleteAllSubroles));
role = roleService.get(role.getId());
Assert.assertNotNull(role);
List<IdmRoleGuaranteeRoleDto> guarantees = this.findRoleGuarantees(role);
Assert.assertEquals(1, guarantees.size());
Assert.assertEquals(guarantee.getId(), guarantees.get(0).getId());
IdmRoleDto guaranteeRoleTwo = this.getHelper().createRole();
this.getHelper().createRoleGuaranteeRole(role, guaranteeRoleTwo);
guarantees = this.findRoleGuarantees(role);
Assert.assertEquals(2, guarantees.size());
// Execute import (check authoritative mode)
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
// Second guarantor had to be deleted!
guarantees = this.findRoleGuarantees(role);
Assert.assertEquals(1, guarantees.size());
Assert.assertEquals(guarantee.getId(), guarantees.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.
the class RoleGuaranteeRoleDeleteProcessor method process.
@Override
public EventResult<IdmRoleGuaranteeRoleDto> process(EntityEvent<IdmRoleGuaranteeRoleDto> event) {
IdmRoleGuaranteeRoleDto entityEvent = event.getContent();
//
service.deleteInternal(entityEvent);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleGuaranteeServiceIntegrationTest method testFindRoleGuaranteeByRoleGuaranteeAndType.
@Test
public void testFindRoleGuaranteeByRoleGuaranteeAndType() {
IdmRoleDto guaranteeRole = getHelper().createRole();
IdmRoleDto guaranteeRoleTwo = getHelper().createRole();
//
IdmRoleDto role1 = getHelper().createRole();
IdmRoleDto role2 = getHelper().createRole();
IdmRoleDto role3 = getHelper().createRole();
//
String guarranteeType = getHelper().createName();
getHelper().createRoleGuaranteeRole(role1, guaranteeRole, guarranteeType);
//
getHelper().createRoleGuaranteeRole(role2, guaranteeRoleTwo, guarranteeType);
//
getHelper().createRoleGuaranteeRole(role3, guaranteeRole, null);
//
IdmRoleGuaranteeRoleFilter filter = new IdmRoleGuaranteeRoleFilter();
filter.setGuaranteeRole(guaranteeRole.getId());
filter.setType(guarranteeType);
List<IdmRoleGuaranteeRoleDto> list = roleGuaranteeRoleService.find(filter, null).getContent();
Assert.assertEquals(1, list.size());
//
List<UUID> roles = list.stream().map(IdmRoleGuaranteeRoleDto::getRole).collect(Collectors.toList());
IdmRoleGuaranteeRoleDto roleGuaranteeFirst = list.get(0);
Assert.assertEquals(guaranteeRole.getId(), roleGuaranteeFirst.getGuaranteeRole());
Assert.assertTrue(roles.contains(role1.getId()));
Assert.assertFalse(roles.contains(role2.getId()));
Assert.assertFalse(roles.contains(role3.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceIntegrationTest method testReferentialIntegrity.
@Test
public void testReferentialIntegrity() {
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString("heslo"));
// role
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleGuarantee(role, identity);
//
// guarantee by role
IdmRoleGuaranteeRoleDto roleGuaranteeOne = new IdmRoleGuaranteeRoleDto();
roleGuaranteeOne.setRole(role.getId());
roleGuaranteeOne.setGuaranteeRole(getHelper().createRole().getId());
roleGuaranteeRoleService.save(roleGuaranteeOne);
IdmRoleGuaranteeRoleDto roleGuaranteeTwo = new IdmRoleGuaranteeRoleDto();
roleGuaranteeTwo.setRole(getHelper().createRole().getId());
roleGuaranteeTwo.setGuaranteeRole(role.getId());
roleGuaranteeRoleService.save(roleGuaranteeTwo);
//
// after save
IdmRoleGuaranteeFilter guaranteeFilter = new IdmRoleGuaranteeFilter();
guaranteeFilter.setRole(role.getId());
IdmRoleGuaranteeRoleFilter guaranteeRoleFilter = new IdmRoleGuaranteeRoleFilter();
guaranteeRoleFilter.setRole(role.getId());
IdmRoleGuaranteeRoleFilter guaranteeRoleRoleFilter = new IdmRoleGuaranteeRoleFilter();
guaranteeRoleRoleFilter.setGuaranteeRole(role.getId());
//
Assert.assertNotNull(roleService.getByCode(role.getCode()));
Assert.assertEquals(1, roleGuaranteeService.find(guaranteeFilter, null).getTotalElements());
Assert.assertEquals(1, roleGuaranteeRoleService.find(guaranteeRoleFilter, null).getTotalElements());
Assert.assertEquals(1, roleGuaranteeRoleService.find(guaranteeRoleFilter, null).getTotalElements());
roleService.delete(role);
//
// after delete
Assert.assertNull(roleService.getByCode(role.getCode()));
Assert.assertEquals(0, roleGuaranteeService.find(guaranteeFilter, null).getTotalElements());
Assert.assertEquals(0, roleGuaranteeRoleService.find(guaranteeRoleFilter, null).getTotalElements());
Assert.assertEquals(0, roleGuaranteeRoleService.find(guaranteeRoleFilter, null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.
the class RoleGuaranteeRoleByRoleEvaluatorIntegrationTest method canReadByRole.
@Test
public void canReadByRole() {
IdmIdentityDto identity = getHelper().createIdentity();
List<IdmRoleGuaranteeRoleDto> roleGuarantees = null;
IdmRoleDto role = getHelper().createRole();
IdmRoleGuaranteeRoleDto roleGuaranteeRole = null;
try {
getHelper().loginAdmin();
roleGuaranteeRole = getHelper().createRoleGuaranteeRole(role, role);
getHelper().createIdentityRole(identity, role);
getHelper().createUuidPolicy(role.getId(), role.getId(), IdmBasePermission.READ);
} finally {
logout();
}
// check created identity doesn't have compositions
try {
getHelper().login(identity.getUsername(), identity.getPassword());
Assert.assertEquals(role.getId(), roleService.get(role.getId(), IdmBasePermission.READ).getId());
roleGuarantees = service.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(roleGuarantees.isEmpty());
} finally {
logout();
}
//
// create authorization policy - assign to role
getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.ROLEGUARANTEEROLE, IdmRoleGuaranteeRole.class, RoleGuaranteeRoleByRoleEvaluator.class);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
// evaluate access
roleGuarantees = service.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, roleGuarantees.size());
Assert.assertEquals(roleGuaranteeRole.getId(), roleGuarantees.get(0).getId());
//
Set<String> permissions = service.getPermissions(roleGuaranteeRole);
Assert.assertEquals(1, permissions.size());
Assert.assertEquals(IdmBasePermission.READ.name(), permissions.iterator().next());
} finally {
logout();
}
//
getHelper().createUuidPolicy(role.getId(), role.getId(), IdmBasePermission.UPDATE);
//
try {
getHelper().login(identity.getUsername(), identity.getPassword());
//
Set<String> permissions = service.getPermissions(roleGuaranteeRole);
Assert.assertEquals(4, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.CREATE.name())));
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.DELETE.name())));
} finally {
logout();
}
}
Aggregations