Search in sources :

Example 1 with AbstractIdmAutomaticRoleDto

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

the class DefaultIdmAutomaticRoleAttributeService method removeAutomaticRoles.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void removeAutomaticRoles(UUID contractId, Set<AbstractIdmAutomaticRoleDto> automaticRoles) {
    for (AbstractIdmAutomaticRoleDto autoRole : automaticRoles) {
        IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
        identityRoleFilter.setIdentityContractId(contractId);
        identityRoleFilter.setAutomaticRoleId(autoRole.getId());
        // TODO: possible performance update with pageable
        for (IdmIdentityRoleDto identityRole : identityRoleService.find(identityRoleFilter, null).getContent()) {
            // skip check granted authorities
            IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.DELETE, identityRole);
            event.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
            identityRoleService.publish(event);
        }
    }
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AbstractIdmAutomaticRoleDto

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

the class DefaultIdmRoleTreeNodeService method addAutomaticRoles.

@Override
@Transactional
public void addAutomaticRoles(IdmIdentityContractDto contract, Set<IdmRoleTreeNodeDto> automaticRoles) {
    // original method assignAutomaticRoles has also only @Transactional without reguired new
    for (AbstractIdmAutomaticRoleDto autoRole : automaticRoles) {
        // create identity role directly
        IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
        identityRole.setRoleTreeNode(autoRole.getId());
        identityRole.setIdentityContract(contract.getId());
        identityRole.setRole(autoRole.getRole());
        identityRole.setValidFrom(contract.getValidFrom());
        identityRole.setValidTill(contract.getValidTill());
        // 
        // start event with skip check authorities
        IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.CREATE, identityRole);
        event.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
        identityRoleService.publish(event);
    }
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with AbstractIdmAutomaticRoleDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testDisabledContract.

@Test
public void testDisabledContract() {
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    IdmIdentityContractDto contract2 = testHelper.createIdentityContact(identity, null, new LocalDate().minusMonths(5), new LocalDate().plusMonths(5));
    contract2.setState(ContractState.DISABLED);
    contract2 = identityContractService.save(contract2);
    // 
    IdmIdentityContractDto contract3 = testHelper.createIdentityContact(identity, null, null, new LocalDate().plusMonths(5));
    contract3.setState(ContractState.DISABLED);
    contract3 = identityContractService.save(contract3);
    // 
    IdmIdentityContractDto contract4 = testHelper.createIdentityContact(identity, null, null, null);
    contract4.setState(ContractState.DISABLED);
    contract4 = identityContractService.save(contract4);
    // 
    IdmIdentityContractDto contract5 = testHelper.createIdentityContact(identity, null, new LocalDate().minusMonths(5), null);
    contract5.setState(ContractState.DISABLED);
    contract5 = identityContractService.save(contract5);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, identity.getUsername());
    // 
    this.recalculateSync(automaticRole.getId());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract2.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract4.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract5.getId());
    assertEquals(0, identityRoles.size());
    // 
    contract5.setState(null);
    contract5 = identityContractService.save(contract5);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract5.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract4.setState(null);
    contract4 = identityContractService.save(contract4);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract4.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract3.setState(null);
    contract3 = identityContractService.save(contract3);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract2.setState(null);
    contract2 = identityContractService.save(contract2);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract2.getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        assertEquals(automaticRole.getId(), identityRole.getRoleTreeNode());
        AbstractIdmAutomaticRoleDto embedded = DtoUtils.getEmbedded(identityRole, IdmAutomaticRoleAttributeService.ROLE_TREE_NODE_ATTRIBUTE_NAME, AbstractIdmAutomaticRoleDto.class, null);
        assertEquals(automaticRole, embedded);
        assertEquals(role.getId(), embedded.getRole());
        assertEquals(role.getId(), identityRole.getRole());
    }
    // 
    contract3.setState(ContractState.DISABLED);
    contract3 = identityContractService.save(contract3);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(org.joda.time.LocalDate) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with AbstractIdmAutomaticRoleDto

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

the class IdentityContractAutomaticRoleProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto identityContract = event.getContent();
    UUID contractId = identityContract.getId();
    // 
    // both by default - contract can be saved together with identity => we need to recalculate all rules
    AutomaticRoleAttributeRuleType type = null;
    // just contract eav save
    if (CoreEventType.EAV_SAVE.name().equals(event.getParentType())) {
        type = AutomaticRoleAttributeRuleType.CONTRACT_EAV;
    }
    // 
    // resolve automatic role by attribute
    Set<AbstractIdmAutomaticRoleDto> allNewPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(true, type, contractId);
    Set<AbstractIdmAutomaticRoleDto> allNotPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(false, type, contractId);
    // we don't know precious size - guava is used instead simple ArrayList constructor
    List<IdmConceptRoleRequestDto> concepts = Lists.newArrayListWithExpectedSize(allNewPassedAutomaticRoleForContract.size() + allNotPassedAutomaticRoleForContract.size());
    // Iterate over newly passed
    for (AbstractIdmAutomaticRoleDto autoRole : allNewPassedAutomaticRoleForContract) {
        IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
        concept.setIdentityContract(contractId);
        concept.setValidFrom(identityContract.getValidFrom());
        concept.setValidTill(identityContract.getValidTill());
        concept.setRole(autoRole.getRole());
        concept.setAutomaticRole(autoRole.getId());
        concept.setOperation(ConceptRoleRequestOperation.ADD);
        concepts.add(concept);
    }
    // Iterate over newly not passed
    for (AbstractIdmAutomaticRoleDto autoRole : allNotPassedAutomaticRoleForContract) {
        // Find all identity roles
        IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
        filter.setAutomaticRoleId(autoRole.getId());
        filter.setIdentityContractId(contractId);
        ;
        List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
        // 
        for (IdmIdentityRoleDto identityRole : identityRoles) {
            IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
            concept.setIdentityContract(contractId);
            concept.setRole(autoRole.getRole());
            concept.setAutomaticRole(autoRole.getId());
            concept.setIdentityRole(identityRole.getId());
            concept.setOperation(ConceptRoleRequestOperation.REMOVE);
            concepts.add(concept);
        }
    }
    // 
    // Execute concepts
    IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
    roleRequest.setConceptRoles(concepts);
    roleRequest.setApplicant(identityContract.getIdentity());
    roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), event);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 5 with AbstractIdmAutomaticRoleDto

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

the class DefaultIdmRoleTreeNodeService method createIdentityRole.

/**
 * Method create identity role and start event with create
 * the identity role and skip check authorities.
 *
 * @param contract
 * @param automaticRoles
 */
private void createIdentityRole(IdmIdentityContractDto contract, IdmContractPositionDto contractPosition, Set<IdmRoleTreeNodeDto> automaticRoles) {
    for (AbstractIdmAutomaticRoleDto autoRole : automaticRoles) {
        // create identity role directly
        IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
        identityRole.setAutomaticRole(autoRole.getId());
        identityRole.setIdentityContract(contract.getId());
        identityRole.setContractPosition(contractPosition == null ? null : contractPosition.getId());
        identityRole.setRole(autoRole.getRole());
        identityRole.setValidFrom(contract.getValidFrom());
        identityRole.setValidTill(contract.getValidTill());
        // 
        // start event with skip check authorities
        IdentityRoleEvent event = new IdentityRoleEvent(IdentityRoleEventType.CREATE, identityRole);
        event.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
        identityRoleService.publish(event);
    }
}
Also used : IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Aggregations

AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)18 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)11 UUID (java.util.UUID)10 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)9 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)6 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)6 RoleRequestEvent (eu.bcvsolutions.idm.core.model.event.RoleRequestEvent)6 ArrayList (java.util.ArrayList)6 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)5 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)5 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)3 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)3 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)3 IdentityRoleEvent (eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent)3 HashSet (java.util.HashSet)3 AutomaticRoleAttributeRuleType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType)2 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)2 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)2