Search in sources :

Example 56 with IdmIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleCompositionService method removeSubRoles.

@Override
@Transactional
public void removeSubRoles(EntityEvent<IdmIdentityRoleDto> event, BasePermission... permission) {
    Assert.notNull(event, "Event is required.");
    IdmIdentityRoleDto directRole = event.getContent();
    Assert.notNull(directRole, "Direct role is required.");
    Assert.notNull(directRole.getId(), "Direct role identifier is required.");
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setDirectRoleId(directRole.getId());
    // 
    identityRoleService.find(filter, null).forEach(subIdentityRole -> {
        IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.DELETE, subIdentityRole);
        // 
        identityRoleService.publish(subEvent, event, permission);
        // Notes identity-accounts to ACM
        notingIdentityAccountForDelayedAcm(event, subEvent);
    });
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with IdmIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleCompositionService method assignSubRoles.

/**
 * @Transactional is not needed - (asynchronous) events is thrown for every sub role anyway ...
 * Can be called repetitively for given identity role => checks or creates missing sub roles by composition.
 */
@Override
@SuppressWarnings("unchecked")
public void assignSubRoles(EntityEvent<IdmIdentityRoleDto> event, UUID roleCompositionId, BasePermission... permission) {
    Assert.notNull(event, "Event is required.");
    IdmIdentityRoleDto identityRole = event.getContent();
    Assert.notNull(identityRole, "Identity role identifier is required.");
    // find direct sub roles
    IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
    compositionFilter.setSuperiorId(identityRole.getRole());
    compositionFilter.setId(roleCompositionId);
    // 
    List<IdmRoleCompositionDto> directSubRoles = find(compositionFilter, null, permission).getContent();
    LOG.debug("Assign sub roles [{}] for identity role [{}], role [{}]", directSubRoles.size(), identityRole.getId(), identityRole.getRole());
    // 
    Map<String, Serializable> props = resolveProperties(event);
    Set<UUID> processedRoles = (Set<UUID>) props.get(IdentityRoleEvent.PROPERTY_PROCESSED_ROLES);
    processedRoles.add(identityRole.getRole());
    // 
    directSubRoles.forEach(subRoleComposition -> {
        IdmRoleDto subRole = DtoUtils.getEmbedded(subRoleComposition, IdmRoleComposition_.sub);
        if (processedRoles.contains(subRole.getId())) {
            LOG.debug("Role [{}] was already processed by other business role composition - cycle, skipping", subRole.getCode());
        } else {
            // try to find currently assigned subrole by this configuration (return operation)
            IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
            filter.setRoleCompositionId(subRoleComposition.getId());
            filter.setDirectRoleId(identityRole.getDirectRole() == null ? identityRole.getId() : identityRole.getDirectRole());
            if (identityRoleService.find(filter, null).getTotalElements() > 0) {
                LOG.debug("Role [{}] was already processed by other business role composition - cycle, skipping", subRole.getCode());
            } else {
                // 
                IdmIdentityRoleDto subIdentityRole = new IdmIdentityRoleDto();
                subIdentityRole.setRole(subRole.getId());
                subIdentityRole.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_ROLE, subRole);
                subIdentityRole.setIdentityContract(identityRole.getIdentityContract());
                subIdentityRole.setContractPosition(identityRole.getContractPosition());
                subIdentityRole.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT, identityRole.getEmbedded().get(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT));
                subIdentityRole.setValidFrom(identityRole.getValidFrom());
                subIdentityRole.setValidTill(identityRole.getValidTill());
                subIdentityRole.setDirectRole(identityRole.getDirectRole() == null ? identityRole.getId() : identityRole.getDirectRole());
                subIdentityRole.setRoleComposition(subRoleComposition.getId());
                // 
                processedRoles.add(subRole.getId());
                IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.CREATE, subIdentityRole, props);
                // 
                identityRoleService.publish(subEvent, event, permission);
                // Notes new created assigned role to parent event
                IdmIdentityRoleDto subContent = subEvent.getContent();
                notingAssignedRole(event, subEvent, subContent, IdentityRoleEvent.PROPERTY_ASSIGNED_NEW_ROLES);
            }
        }
    });
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) Serializable(java.io.Serializable) HashSet(java.util.HashSet) Set(java.util.Set) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter)

Example 58 with IdmIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleCompositionService method updateSubRoles.

@Override
@Transactional
public void updateSubRoles(EntityEvent<IdmIdentityRoleDto> event, BasePermission... permission) {
    Assert.notNull(event, "Event is required.");
    IdmIdentityRoleDto identityRole = event.getContent();
    Assert.notNull(identityRole, "Identity role identifier is required.");
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setDirectRoleId(identityRole.getId());
    // 
    identityRoleService.find(filter, null).forEach(subIdentityRole -> {
        subIdentityRole.setIdentityContract(identityRole.getIdentityContract());
        subIdentityRole.setContractPosition(identityRole.getContractPosition());
        subIdentityRole.getEmbedded().put(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT, identityRole.getEmbedded().get(IdmIdentityRoleDto.PROPERTY_IDENTITY_CONTRACT));
        subIdentityRole.setValidFrom(identityRole.getValidFrom());
        subIdentityRole.setValidTill(identityRole.getValidTill());
        // 
        IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.UPDATE, subIdentityRole);
        // 
        identityRoleService.publish(subEvent, event, permission);
        // Notes updated assigned role to parent event
        IdmIdentityRoleDto subContent = subEvent.getContent();
        notingAssignedRole(event, subEvent, subContent, IdentityRoleEvent.PROPERTY_ASSIGNED_UPDATED_ROLES);
    });
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with IdmIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class IdentityRoleByRoleCatalogueCodeFilterIntegrationTest method testOneResult.

@Test
public void testOneResult() {
    IdmRoleDto role = getHelper().createRole();
    IdmRoleCatalogueDto roleCatalogue = getHelper().createRoleCatalogue();
    getHelper().createRoleCatalogueRole(role, roleCatalogue);
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityRoleDto createIdentityRole = getHelper().createIdentityRole(identity, role);
    MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
    params.set(IdentityRoleByRoleCatalogueCodeFilter.PARAMETER_ROLE_CATALOGUE_CODE, roleCatalogue.getCode());
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter(params);
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
    Assert.assertFalse(identityRoles.isEmpty());
    Assert.assertEquals(1, identityRoles.size());
    IdmIdentityRoleDto foundedIdentityRole = identityRoles.get(0);
    Assert.assertEquals(createIdentityRole.getId(), foundedIdentityRole.getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 60 with IdmIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class IdentityRoleExpirationTaskExecutorIntegrationTest method testExpiredBusinessRole.

@Test
public void testExpiredBusinessRole() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    // 
    // normal and business role
    IdmRoleDto roleOne = getHelper().createRole();
    IdmRoleDto roleRoot = getHelper().createRole();
    IdmRoleDto roleSub = getHelper().createRole();
    getHelper().createRoleComposition(roleRoot, roleSub);
    // 
    // assign roles
    IdmIdentityRoleDto assignedRoleOne = getHelper().createIdentityRole(contract, roleRoot);
    IdmIdentityRoleDto assignedRoleTwo = getHelper().createIdentityRole(contract, roleOne);
    // 
    // expire contract
    assignedRoleOne.setValidTill(LocalDate.now().minusDays(2));
    assignedRoleOne = identityRoleService.save(assignedRoleOne);
    assignedRoleTwo.setValidTill(LocalDate.now().minusDays(2));
    assignedRoleTwo = identityRoleService.save(assignedRoleTwo);
    // 
    // test after create before lrt is executed
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityContractId(contract.getId());
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(filter, null).getContent();
    // 
    Assert.assertEquals(3, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleOne.getId())));
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleRoot.getId())));
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleSub.getId())));
    Assert.assertTrue(assignedRoles.stream().allMatch(ir -> !ir.isValid()));
    // 
    IdentityRoleExpirationTaskExecutor lrt = new IdentityRoleExpirationTaskExecutor();
    lrt.init(null);
    lrtManager.executeSync(lrt);
    // 
    assignedRoles = identityRoleService.find(filter, null).getContent();
    // 
    Assert.assertTrue(assignedRoles.isEmpty());
}
Also used : IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) UUID(java.util.UUID) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)116 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)85 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)84 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)81 Test (org.junit.Test)72 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)67 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)46 UUID (java.util.UUID)41 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)39 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)38 List (java.util.List)38 Autowired (org.springframework.beans.factory.annotation.Autowired)38 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)33 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)31 LocalDate (java.time.LocalDate)31 Assert (org.junit.Assert)28 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)27 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)25 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)25 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)25