Search in sources :

Example 1 with IdentityContractEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.

the class ContractSynchronizationExecutor method callProvisioningForEntity.

/**
 * Call provisioning for given account
 *
 * @param entity
 * @param entityType
 * @param logItem
 */
@Override
protected void callProvisioningForEntity(IdmIdentityContractDto entity, SystemEntityType entityType, SysSyncItemLogDto logItem) {
    addToItemLog(logItem, MessageFormat.format("Call provisioning (process IdentityContractEvent.UPDATE) for contract ({0}) with position ({1}).", entity.getId(), entity.getPosition()));
    IdentityContractEvent event = new IdentityContractEvent(IdentityContractEventType.UPDATE, entity);
    // We do not want execute HR processes for every contract. We need start
    // them for every identity only once.
    // For this we skip them now. HR processes must be start after whole
    // sync finished (by using dependent scheduled task)!
    event.getProperties().put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
    // 
    // We don't want recalculate automatic role by attribute recalculation for every
    // contract.
    // Recalculation will be started only once.
    event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
    entityEventManager.process(event);
}
Also used : IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent)

Example 2 with IdentityContractEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.

the class TreeNodeDeleteProcessor method process.

@Override
public EventResult<IdmTreeNodeDto> process(EntityEvent<IdmTreeNodeDto> event) {
    IdmTreeNodeDto treeNode = event.getContent();
    Assert.notNull(treeNode, "Tree node is required.");
    UUID treeNodeId = treeNode.getId();
    Assert.notNull(treeNodeId, "Tree node identifier is required.");
    boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
    // check role can be removed without force
    if (!forceDelete) {
        checkWithoutForceDelete(treeNode);
    }
    // 
    // check automatic role request
    IdmAutomaticRoleRequestFilter roleRequestFilter = new IdmAutomaticRoleRequestFilter();
    roleRequestFilter.setTreeNodeId(treeNodeId);
    List<IdmAutomaticRoleRequestDto> roleRequestDtos = roleRequestService.find(roleRequestFilter, null).getContent();
    for (IdmAutomaticRoleRequestDto request : roleRequestDtos) {
        if (!request.getState().isTerminatedState()) {
            roleRequestService.cancel(request);
        }
        request.setTreeNode(null);
        roleRequestService.save(request);
    }
    if (forceDelete) {
        // delete all tree node children
        service.findChildrenByParent(treeNodeId, null).forEach(child -> {
            TreeNodeEvent treeNodeEvent = new TreeNodeEvent(TreeNodeEventType.DELETE, child);
            // 
            service.publish(treeNodeEvent, event);
            clearSession();
        });
        // 
        // update contract slices
        IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
        sliceFilter.setTreeNode(treeNodeId);
        sliceFilter.setRecursionType(RecursionType.NO);
        contractSliceService.find(sliceFilter, null).forEach(slice -> {
            slice.setWorkPosition(null);
            contractSliceService.save(slice);
            clearSession();
        });
        // 
        // update related contracts
        IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
        contractFilter.setWorkPosition(treeNodeId);
        contractFilter.setRecursionType(RecursionType.NO);
        identityContractService.find(contractFilter, null).forEach(identityContract -> {
            // prepare event
            identityContract.setWorkPosition(null);
            IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.UPDATE, identityContract);
            // 
            identityContractService.publish(contractEvent, event);
            clearSession();
        });
        // 
        // update related contract positions
        IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
        positionFilter.setWorkPosition(treeNodeId);
        contractPositionService.find(positionFilter, null).forEach(contractPosition -> {
            // prepare event
            contractPosition.setWorkPosition(null);
            ContractPositionEvent contractPositionEvent = new ContractPositionEvent(ContractPositionEventType.UPDATE, contractPosition);
            // 
            contractPositionService.publish(contractPositionEvent, event);
            clearSession();
        });
        // 
        // related automatic roles by tree structure
        IdmRoleTreeNodeFilter roleTreeNodefilter = new IdmRoleTreeNodeFilter();
        roleTreeNodefilter.setTreeNodeId(treeNodeId);
        roleTreeNodeService.findIds(roleTreeNodefilter, null).stream().forEach(roleTreeNodeId -> {
            // sync => all asynchronous requests have to be prepared in event queue
            RemoveAutomaticRoleTaskExecutor automaticRoleTask = AutowireHelper.createBean(RemoveAutomaticRoleTaskExecutor.class);
            automaticRoleTask.setAutomaticRoleId(roleTreeNodeId);
            longRunningTaskManager.executeSync(automaticRoleTask);
            clearSession();
        });
    }
    // 
    if (forceDelete) {
        LOG.debug("Tree node [{}] should be deleted by caller after all asynchronus processes are completed.", treeNode.getCode());
        // 
        // dirty flag only - will be processed after asynchronous events ends
        IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
        stateDeleted.setEvent(event.getId());
        stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
        entityStateManager.saveState(treeNode, stateDeleted);
        // 
        // set disabled
        treeNode.setDisabled(true);
        service.saveInternal(treeNode);
    } else {
        service.deleteInternal(treeNode);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) TreeNodeEvent(eu.bcvsolutions.idm.core.model.event.TreeNodeEvent) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) RemoveAutomaticRoleTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.RemoveAutomaticRoleTaskExecutor) IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) UUID(java.util.UUID) IdmAutomaticRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter)

Example 3 with IdentityContractEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.

the class IdentityDeleteProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto identity = event.getContent();
    UUID identityId = identity.getId();
    Assert.notNull(identityId, "Identity ID is required!");
    boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
    // 
    // delete contract slices
    IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
    sliceFilter.setIdentity(identityId);
    contractSliceService.find(sliceFilter, null).forEach(guarantee -> {
        contractSliceService.delete(guarantee);
    });
    // delete contract slice guarantees
    IdmContractSliceGuaranteeFilter sliceGuaranteeFilter = new IdmContractSliceGuaranteeFilter();
    sliceGuaranteeFilter.setGuaranteeId(identityId);
    contractSliceGuaranteeService.find(sliceGuaranteeFilter, null).forEach(guarantee -> {
        contractSliceGuaranteeService.delete(guarantee);
    });
    // 
    // contracts
    identityContractService.findAllByIdentity(identityId).forEach(identityContract -> {
        // when identity is deleted, then HR processes has to be skipped (prevent to update deleted identity, when contract is removed)
        Map<String, Serializable> properties = new HashMap<>();
        properties.put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
        // propagate force attribute
        properties.put(PROPERTY_FORCE_DELETE, forceDelete);
        // prepare event
        IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.DELETE, identityContract, properties);
        contractEvent.setPriority(PriorityType.HIGH);
        // 
        identityContractService.publish(contractEvent);
    });
    // delete contract guarantees
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setGuaranteeId(identityId);
    contractGuaranteeService.find(filter, null).forEach(guarantee -> {
        contractGuaranteeService.delete(guarantee);
    });
    // remove role guarantee
    IdmRoleGuaranteeFilter roleGuaranteeFilter = new IdmRoleGuaranteeFilter();
    roleGuaranteeFilter.setGuarantee(identityId);
    roleGuaranteeService.find(roleGuaranteeFilter, null).forEach(roleGuarantee -> {
        roleGuaranteeService.delete(roleGuarantee);
    });
    // remove password
    passwordProcessor.deletePassword(identity);
    // delete password history for identity
    passwordHistoryService.deleteAllByIdentity(identityId);
    // disable related tokens - tokens has to be disabled to prevent their usage (when tokens are deleted, then token is recreated)
    tokenManager.disableTokens(identity);
    // 
    // delete all identity's profiles
    IdmProfileFilter profileFilter = new IdmProfileFilter();
    profileFilter.setIdentityId(identityId);
    profileService.find(profileFilter, null).forEach(profile -> {
        profileService.delete(profile);
    });
    // remove all IdentityRoleValidRequest for this identity
    List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityId(identityId);
    identityRoleValidRequestService.deleteAll(validRequests);
    // 
    // delete all identity's delegations - delegate
    IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
    delegationFilter.setDelegateId(identityId);
    delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
        delegationDefinitionService.delete(delegation);
    });
    // 
    // delete all identity's delegations - delegator
    delegationFilter = new IdmDelegationDefinitionFilter();
    delegationFilter.setDelegatorId(identityId);
    delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
        delegationDefinitionService.delete(delegation);
    });
    // deletes identity
    if (forceDelete) {
        LOG.debug("Identity [{}] should be deleted by caller after all asynchronus processes are completed.", identityId);
        // 
        // dirty flag only - will be processed after asynchronous events ends
        IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
        stateDeleted.setEvent(event.getId());
        stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
        entityStateManager.saveState(identity, stateDeleted);
        // 
        // set disabled (automatically)
        identity.setState(IdentityState.DISABLED);
        service.saveInternal(identity);
    } else {
        // delete all role requests where is this identity applicant
        IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
        roleRequestFilter.setApplicantId(identityId);
        roleRequestService.find(roleRequestFilter, null).forEach(request -> {
            roleRequestService.delete(request);
        });
        // 
        service.deleteInternal(identity);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) Serializable(java.io.Serializable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) IdmProfileFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmContractSliceFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter) IdmDelegationDefinitionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmDelegationDefinitionFilter) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmIdentityRoleValidRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleValidRequestDto)

Example 4 with IdentityContractEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.

the class ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmEntityStateDto state) {
    UUID ownerId = state.getOwnerId();
    if (processedOwnerIds.contains(ownerId)) {
        LOG.debug("Automatic roles for owner [{}] was already processed, delete state only.", ownerId);
        // 
        entityStateManager.deleteState(state);
        // Item will be deleted only - we need some result - counter / count will match.
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    }
    // process automatic role on state owner
    if (state.getOwnerType().equals(entityStateManager.getOwnerType(IdmIdentityContractDto.class))) {
        // contract
        LOG.debug("Process automatic roles for contract [{}].", ownerId);
        // 
        IdmIdentityContractDto contract = lookupService.lookupDto(IdmIdentityContractDto.class, ownerId);
        if (contract == null) {
            getItemService().createLogItem(state, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.CONTENT_DELETED, ImmutableMap.of("ownerId", ownerId, "ownerType", entityStateManager.getOwnerType(IdmIdentityContractDto.class)))).build(), this.getLongRunningTaskId());
        } else if (!contract.isValidNowOrInFuture()) {
            removeAllAutomaticRoles(contract);
            // 
            getItemService().createLogItem(contract, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
        } else {
            EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.NOTIFY, contract);
            event.setOriginalSource((IdmIdentityContractDto) state.getResult().getModel().getParameters().get(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE));
            contractProcessor.process(event);
            // 
            getItemService().createLogItem(contract, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
        }
    } else {
        // position
        LOG.debug("Process automatic roles for position [{}].", ownerId);
        // 
        IdmContractPositionDto position = lookupService.lookupDto(IdmContractPositionDto.class, ownerId);
        if (position == null) {
            getItemService().createLogItem(state, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.CONTENT_DELETED, ImmutableMap.of("ownerId", ownerId, "ownerType", entityStateManager.getOwnerType(IdmIdentityContractDto.class)))).build(), this.getLongRunningTaskId());
        } else {
            EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.NOTIFY, position);
            positionProcessor.process(event);
            // 
            getItemService().createLogItem(position, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
        }
    }
    processedOwnerIds.add(ownerId);
    entityStateManager.deleteState(state);
    // Log added manually above - log processed contract / position instead of deleted entity state.
    return Optional.empty();
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) ContractPositionEvent(eu.bcvsolutions.idm.core.model.event.ContractPositionEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 5 with IdentityContractEvent

use of eu.bcvsolutions.idm.core.model.event.IdentityContractEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerIntergationTest method testOriginalSourceWithNotifyOnDifferentType.

@Test
public void testOriginalSourceWithNotifyOnDifferentType() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    // 
    IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
    eventFilter.setOwnerType(manager.getOwnerType(identity));
    eventFilter.setOwnerId(identity.getId());
    manager.findEvents(eventFilter, null).forEach(entityEvent -> {
        manager.deleteEvent(entityEvent);
    });
    // 
    try {
        getHelper().enableAsynchronousProcessing();
        // 
        EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.UPDATE, contract);
        event.setOriginalSource(contract);
        manager.changedEntity(identity.getClass(), identity.getId(), event);
        // 
        eventFilter.setEventType(IdentityEventType.NOTIFY.name());
        eventFilter.setStates(Lists.newArrayList(OperationState.EXECUTED));
        getHelper().waitForResult(res -> {
            return manager.findEvents(eventFilter, null).getContent().isEmpty();
        });
        // 
        manager.findEvents(eventFilter, null).stream().allMatch(entityEvent -> {
            return entityEvent.getContent().getId().equals(identity.getId()) && entityEvent.getOriginalSource().getId().equals(identity.getId());
        });
    } finally {
        getHelper().disableAsynchronousProcessing();
    }
}
Also used : IdentityContractEvent(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdentityContractEvent (eu.bcvsolutions.idm.core.model.event.IdentityContractEvent)18 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 UUID (java.util.UUID)8 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)7 IdentityContractEventType (eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType)7 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)5 IdmContractGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)5 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)5 Serializable (java.io.Serializable)5 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)4 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)4 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)4 ContractState (eu.bcvsolutions.idm.core.api.domain.ContractState)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)4 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)4 IdmContractGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ImmutableMap (com.google.common.collect.ImmutableMap)3