Search in sources :

Example 1 with IdentityState

use of eu.bcvsolutions.idm.core.api.domain.IdentityState in project CzechIdMng by bcvsolutions.

the class IdentityContractExclusionProcessor method process.

/**
 * Check identity state after contract is excluded
 *
 * @param contract
 * @param skipRecalculation Skip automatic role recalculation
 * @return
 */
public OperationResult process(IdmIdentityContractDto contract, Boolean skipRecalculation) {
    IdmIdentityDto identity = identityService.get(contract.getIdentity());
    IdentityState newState = identityService.evaluateState(identity.getId());
    // 
    if (identity.getState() != newState) {
        LOG.info("Change identity [{}] state [{}]", identity.getUsername(), newState);
        // 
        identity.setState(newState);
        // is necessary publish new event with skip recalculation automatic roles
        IdentityEvent identityEvent = new IdentityEvent(IdentityEventType.UPDATE, identity);
        identityEvent.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, skipRecalculation);
        identityService.publish(identityEvent);
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Example 2 with IdentityState

use of eu.bcvsolutions.idm.core.api.domain.IdentityState in project CzechIdMng by bcvsolutions.

the class IdentityContractSaveProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto contract = event.getContent();
    contract = service.saveInternal(contract);
    event.setContent(contract);
    // 
    // check identity state
    IdmIdentityContractDto previousContract = event.getOriginalSource();
    IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity.getName(), IdmIdentityDto.class);
    if ((identity.getState() == IdentityState.CREATED || identity.isDisabled()) && contractChanged(previousContract, contract)) {
        // synchronize identity states, which has no effect on HR processes
        identity = identityService.get(contract.getIdentity());
        IdentityState newState = identityService.evaluateState(identity.getId());
        if (newState.isDisabled() && identity.getState() != newState) {
            identity.setState(newState);
            // publish new save event for identity with skip recalculation
            IdentityEvent identityEvent = new IdentityEvent(IdentityEventType.UPDATE, identity);
            identityEvent.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, true);
            identityService.publish(identityEvent);
        }
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Example 3 with IdentityState

use of eu.bcvsolutions.idm.core.api.domain.IdentityState in project CzechIdMng by bcvsolutions.

the class IdentityContractEnableProcessor method process.

/**
 * Check identity state after contract is enabled
 *
 * @param contract
 * @param skipRecalculation Skip automatic role recalculation
 * @return
 */
public OperationResult process(IdmIdentityContractDto contract, Boolean skipRecalculation) {
    if (contract.isValid() && contract.getState() != ContractState.EXCLUDED) {
        IdmIdentityDto identity = identityService.get(contract.getIdentity());
        IdentityState newState = identityService.evaluateState(identity.getId());
        // we want to enable identity with contract other than default one
        if (newState == IdentityState.VALID && (identity.isDisabled() || identity.getState() == IdentityState.CREATED)) {
            LOG.info("Change identity [{}] state [{}]", identity.getUsername(), IdentityState.VALID);
            // 
            identity.setState(IdentityState.VALID);
            // is neccessary publish new event with skip recalculation automatic roles
            IdentityEvent event = new IdentityEvent(IdentityEventType.UPDATE, identity);
            event.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, skipRecalculation);
            identityService.publish(event);
        }
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Example 4 with IdentityState

use of eu.bcvsolutions.idm.core.api.domain.IdentityState in project CzechIdMng by bcvsolutions.

the class IdentityContractEndProcessor method process.

/**
 * Check identity state after contract ended
 *
 * @param contract
 * @param skipRecalculation Skip automatic role recalculation
 * @return
 */
public OperationResult process(IdmIdentityContractDto contract, Boolean skipRecalculation) {
    // update identity state
    IdmIdentityDto identity = identityService.get(contract.getIdentity());
    IdentityState newState = identityService.evaluateState(identity.getId());
    if (identity.getState() != newState) {
        LOG.info("Change identity [{}] state [{}]", identity.getUsername(), newState);
        // 
        identity.setState(newState);
        // is neccessary publish new event with skip recalculation automatic roles
        IdentityEvent identityEvent = new IdentityEvent(IdentityEventType.UPDATE, identity);
        identityEvent.getProperties().put(IdmAutomaticRoleAttributeService.SKIP_RECALCULATION, skipRecalculation);
        identityService.publish(identityEvent);
    }
    // TODO: remove? It's solved by different process
    if (!contract.isValidNowOrInFuture()) {
        identityRoleService.findAllByContract(contract.getId()).forEach(role -> {
            identityRoleService.delete(role);
        });
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState)

Aggregations

IdentityState (eu.bcvsolutions.idm.core.api.domain.IdentityState)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 IdentityEvent (eu.bcvsolutions.idm.core.model.event.IdentityEvent)4 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1