Search in sources :

Example 41 with IdmRoleCompositionDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with IdmRoleCompositionDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with IdmRoleCompositionDto

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())));
}
Also used : IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Set(java.util.Set) Test(org.junit.Test) IdmRoleCompositionService(eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService) UUID(java.util.UUID) ObserveRequestProcessor(eu.bcvsolutions.idm.core.model.event.processor.ObserveRequestProcessor) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Ignore(org.junit.Ignore) LocalDate(java.time.LocalDate) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with IdmRoleCompositionDto

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());
}
Also used : SysSystem_(eu.bcvsolutions.idm.acc.entity.SysSystem_) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysRoleSystemAttribute(eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) Predicate(javax.persistence.criteria.Predicate) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) AbstractEntity_(eu.bcvsolutions.idm.core.api.entity.AbstractEntity_) ImmutableMap(com.google.common.collect.ImmutableMap) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) Set(java.util.Set) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IdmRoleCompositionService(eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Priority(javax.annotation.Priority) List(java.util.List) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) Ordered(org.springframework.core.Ordered) SysSystemGroupSystem_(eu.bcvsolutions.idm.acc.entity.SysSystemGroupSystem_) SysSystemMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemMapping_) ExportManager(eu.bcvsolutions.idm.core.api.service.ExportManager) SysSystemGroupSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter) SysRoleSystem_(eu.bcvsolutions.idm.acc.entity.SysRoleSystem_) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) SysSystemGroupSystem(eu.bcvsolutions.idm.acc.entity.SysSystemGroupSystem) HashMap(java.util.HashMap) IdmRoleSystemService(eu.bcvsolutions.idm.core.api.service.IdmRoleSystemService) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttribute_(eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute_) SysSystemGroup_(eu.bcvsolutions.idm.acc.entity.SysSystemGroup_) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) SysSystemGroupSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemGroupSystemService) Root(javax.persistence.criteria.Root) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) SysRoleSystem(eu.bcvsolutions.idm.acc.entity.SysRoleSystem) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) SysRoleSystemRepository(eu.bcvsolutions.idm.acc.repository.SysRoleSystemRepository) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SystemGroupType(eu.bcvsolutions.idm.acc.domain.SystemGroupType) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Subquery(javax.persistence.criteria.Subquery) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) Set(java.util.Set) HashMap(java.util.HashMap) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) Objects(java.util.Objects) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) UUID(java.util.UUID)

Example 45 with IdmRoleCompositionDto

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);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException)

Aggregations

IdmRoleCompositionDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto)47 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)35 Test (org.junit.Test)24 UUID (java.util.UUID)23 List (java.util.List)22 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)21 Autowired (org.springframework.beans.factory.annotation.Autowired)21 IdmRoleCompositionService (eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService)20 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)19 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)18 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)16 Set (java.util.Set)16 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)15 Assert (org.junit.Assert)15 Transactional (org.springframework.transaction.annotation.Transactional)15 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)14 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)13 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)13 ArrayList (java.util.ArrayList)13 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)12