use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionServiceIntegrationTest method testFindAllSuperiorWithSelf.
@Test
@Transactional
public void testFindAllSuperiorWithSelf() {
// prepare role composition
IdmRoleDto superior = getHelper().createRole();
getHelper().createRoleComposition(superior, superior);
//
List<IdmRoleCompositionDto> allSuperiorRoles = service.findAllSuperiorRoles(superior.getId());
Assert.assertTrue(allSuperiorRoles.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionServiceIntegrationTest method testFindAllSuperiorWithCycles.
@Test
@Transactional
public void testFindAllSuperiorWithCycles() {
// prepare role composition
IdmRoleDto superior = getHelper().createRole();
IdmRoleDto subOne = getHelper().createRole();
IdmRoleDto subTwo = getHelper().createRole();
getHelper().createRoleComposition(superior, subOne);
getHelper().createRoleComposition(subOne, subTwo);
getHelper().createRoleComposition(subTwo, superior);
//
List<IdmRoleCompositionDto> allSuperiorRoles = service.findAllSuperiorRoles(superior.getId());
Assert.assertEquals(2, allSuperiorRoles.size());
// ordered
Assert.assertEquals(subTwo.getId(), allSuperiorRoles.get(0).getSuperior());
Assert.assertEquals(subOne.getId(), allSuperiorRoles.get(1).getSuperior());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionServiceIntegrationTest method testFindDirectSubRoles.
@Test
@Transactional
public void testFindDirectSubRoles() {
// prepare role composition
IdmRoleDto superior = getHelper().createRole();
IdmRoleDto subOne = getHelper().createRole();
IdmRoleDto subTwo = getHelper().createRole();
IdmRoleDto subOneSub = getHelper().createRole();
getHelper().createRoleComposition(superior, subOne);
getHelper().createRoleComposition(superior, subTwo);
getHelper().createRoleComposition(subOne, subOneSub);
//
List<IdmRoleCompositionDto> directSubRoles = service.findDirectSubRoles(superior.getId());
Assert.assertEquals(2, directSubRoles.size());
Assert.assertTrue(directSubRoles.stream().anyMatch(s -> s.getSub().equals(subOne.getId())));
Assert.assertTrue(directSubRoles.stream().anyMatch(s -> s.getSub().equals(subTwo.getId())));
//
directSubRoles = service.findDirectSubRoles(subOne.getId());
Assert.assertEquals(1, directSubRoles.size());
Assert.assertTrue(directSubRoles.stream().anyMatch(s -> s.getSub().equals(subOneSub.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class DefaultSysRoleSystemService method getConceptsForSystem.
@Override
public List<IdmConceptRoleRequestDto> getConceptsForSystem(List<IdmConceptRoleRequestDto> concepts, UUID systemId) {
// Roles using in concepts
Set<UUID> roleIds = //
concepts.stream().map(//
IdmConceptRoleRequestDto::getRole).filter(//
Objects::nonNull).distinct().collect(Collectors.toSet());
// We have direct roles, but we need sub-roles too. Beware here could be many
// selects!
Set<UUID> allSubRoles = Sets.newHashSet(roleIds);
Map<UUID, Set<UUID>> roleWithSubroles = new HashMap<UUID, Set<UUID>>();
roleIds.forEach(roleId -> {
Set<UUID> subRoles = //
roleCompositionService.findAllSubRoles(roleId).stream().map(//
IdmRoleCompositionDto::getSub).distinct().collect(//
Collectors.toSet());
// Put to result map, where key is super role and value set of all sub-roles
roleWithSubroles.put(roleId, subRoles);
allSubRoles.addAll(subRoles);
});
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setSystemId(systemId);
roleSystemFilter.setRoleIds(allSubRoles);
Set<UUID> roles = //
this.find(roleSystemFilter, null).getContent().stream().map(//
SysRoleSystemDto::getRole).distinct().collect(Collectors.toSet());
return //
concepts.stream().filter(concept -> {
UUID roleId = concept.getRole();
if (roleId == null) {
return false;
}
if (roles.contains(roleId)) {
// Direct role
return true;
}
Set<UUID> subRoles = roleWithSubroles.get(roleId);
if (subRoles == null) {
return false;
}
// Sub-role
return //
roles.stream().filter(//
role -> subRoles.contains(role)).findFirst().isPresent();
}).collect(Collectors.toList());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto in project CzechIdMng by bcvsolutions.
the class RemoveRoleCompositionTaskExecutor method end.
@Override
protected Boolean end(Boolean result, Exception ex) {
if (!BooleanUtils.isTrue(result) || ex != null) {
return super.end(result, ex);
}
//
IdmRoleCompositionDto roleComposition = roleCompositionService.get(roleCompositionId);
Assert.notNull(roleComposition, "Role composition is required.");
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleCompositionId(roleComposition.getId());
//
long assignedRoleCount = identityRoleService.count(filter);
if (assignedRoleCount != 0) {
// some assigned role was created in the meantime
LOG.warn("Remove role composition [{}] is not complete, some identity roles [{}] remains assigned to identities.", roleCompositionId, assignedRoleCount);
//
return super.end(result, new ResultCodeException(CoreResultCode.ROLE_COMPOSITION_REMOVE_HAS_ASSIGNED_ROLES, ImmutableMap.of("roleCompositionId", roleCompositionId.toString(), "assignedRoles", String.valueOf(assignedRoleCount))));
}
//
LOG.debug("Remove role composition [{}]", roleCompositionId);
try {
roleCompositionService.deleteInternal(roleComposition);
//
LOG.debug("End: Remove role composition [{}].", roleCompositionId);
//
} catch (Exception O_o) {
LOG.debug("Remove role composition [{}] failed", roleCompositionId, O_o);
//
IdmLongRunningTaskDto task = longRunningTaskService.get(getLongRunningTaskId());
return super.end(result, new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", getLongRunningTaskId(), "taskType", task.getTaskType(), ConfigurationService.PROPERTY_INSTANCE_ID, task.getInstanceId())));
}
//
return super.end(result, ex);
}
Aggregations