Search in sources :

Example 1 with IdmRoleTreeNodeFilter

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

the class RoleDuplicateBulkActionIntegrationTest method findAutomaticRolesByTree.

private List<IdmRoleTreeNodeDto> findAutomaticRolesByTree(IdmRoleDto role) {
    IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
    filter.setRoleId(role.getId());
    // 
    return roleTreeNodeService.find(filter, null).getContent();
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter)

Example 2 with IdmRoleTreeNodeFilter

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

the class RoleDeleteProcessor method checkWithoutForceDelete.

/**
 * Check role can be deleted without force delete.
 *
 * @param role deleted role
 * @throws ResultCodeException if not
 */
private void checkWithoutForceDelete(IdmRoleDto role) {
    UUID roleId = role.getId();
    // check assigned roles
    IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
    identityRoleFilter.setRoleId(roleId);
    if (identityRoleService.count(identityRoleFilter) > 0) {
        throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_IDENTITY_ASSIGNED, ImmutableMap.of("role", role.getCode()));
    }
    // 
    // automatic roles by tree structure
    IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
    filter.setRoleId(roleId);
    if (roleTreeNodeService.count(filter) > 0) {
        throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_TREE_NODE, ImmutableMap.of("role", role.getCode()));
    }
    // 
    // related automatic roles by attribute
    IdmAutomaticRoleFilter automaticRoleFilter = new IdmAutomaticRoleFilter();
    automaticRoleFilter.setRoleId(roleId);
    if (automaticRoleAttributeService.count(automaticRoleFilter) > 0) {
        // some automatic role attribute has assigned this role
        throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_AUTOMATIC_ROLE_ASSIGNED, ImmutableMap.of("role", role.getCode()));
    }
    // 
    // business roles
    IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
    compositionFilter.setSubId(roleId);
    if (roleCompositionService.count(compositionFilter) > 0) {
        throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_COMPOSITION, ImmutableMap.of("role", role.getCode()));
    }
    compositionFilter = new IdmRoleCompositionFilter();
    compositionFilter.setSuperiorId(roleId);
    if (roleCompositionService.count(compositionFilter) > 0) {
        throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_COMPOSITION, ImmutableMap.of("role", role.getCode()));
    }
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UUID(java.util.UUID) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmAutomaticRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter)

Example 3 with IdmRoleTreeNodeFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter 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 4 with IdmRoleTreeNodeFilter

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

the class DuplicateRoleAutomaticByTreeProcessor method process.

@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
    IdmRoleDto cloned = event.getContent();
    IdmRoleDto originalSource = event.getOriginalSource();
    IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
    filter.setRoleId(cloned.getId());
    Set<UUID> usedAutomaticRoles = new HashSet<>();
    List<IdmRoleTreeNodeDto> currentAutomaticRoles = roleTreeNodeService.find(filter, null).getContent();
    // 
    filter.setRoleId(originalSource.getId());
    roleTreeNodeService.find(filter, null).forEach(automaticRole -> {
        UUID exists = exists(currentAutomaticRoles, automaticRole);
        if (exists != null) {
            usedAutomaticRoles.add(exists);
        } else {
            IdmRoleTreeNodeDto clonedAutomaticRole = new IdmRoleTreeNodeDto();
            clonedAutomaticRole.setName(automaticRole.getName());
            clonedAutomaticRole.setRole(cloned.getId());
            clonedAutomaticRole.setTreeNode(automaticRole.getTreeNode());
            clonedAutomaticRole.setRecursionType(automaticRole.getRecursionType());
            // 
            RoleTreeNodeEvent automaticRoleEvent = new RoleTreeNodeEvent(RoleTreeNodeEventType.CREATE, clonedAutomaticRole);
            // execute sync
            automaticRoleEvent.setPriority(PriorityType.IMMEDIATE);
            roleTreeNodeService.publish(automaticRoleEvent, event);
        }
    });
    // 
    // remove not used originals
    currentAutomaticRoles.stream().filter(automaticRole -> {
        return !usedAutomaticRoles.contains(automaticRole.getId());
    }).forEach(automaticRole -> {
        // dirty flag automatic role only - will be processed after parent action ends
        IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
        stateDeleted.setEvent(event.getId());
        stateDeleted.setSuperOwnerId(cloned.getId());
        stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
        entityStateManager.saveState(automaticRole, stateDeleted);
    });
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) RoleTreeNodeEventType(eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent.RoleTreeNodeEventType) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) Lists(com.google.common.collect.Lists) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) RoleEventType(eu.bcvsolutions.idm.core.model.event.RoleEvent.RoleEventType) RoleTreeNodeEvent(eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) Description(org.springframework.context.annotation.Description) RoleProcessor(eu.bcvsolutions.idm.core.api.event.processor.RoleProcessor) Set(java.util.Set) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) Component(org.springframework.stereotype.Component) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) RoleTreeNodeEvent(eu.bcvsolutions.idm.core.model.event.RoleTreeNodeEvent) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 5 with IdmRoleTreeNodeFilter

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

the class DefaultAccTestHelper method cleaner.

/**
 * Manual delete of all automatic roles, sync, mappings. Because previous tests didn't make a delete well.
 */
@Override
public void cleaner() {
    // Delete all automatic roles.
    roleTreeNodeService.deleteAll(roleTreeNodeService.find(new IdmRoleTreeNodeFilter(), null).getContent());
    automaticRoleAttributeService.deleteAll(automaticRoleAttributeService.find(new IdmRoleTreeNodeFilter(), null).getContent());
    // Delete all syncs.
    syncConfigService.deleteAll(syncConfigService.find(new SysSyncConfigFilter(), null).getContent());
    // Delete all groups.
    systemGroupService.deleteAll(systemGroupService.find(new SysSystemGroupFilter(), null));
    // Delete all mappings.
    systemMappingService.deleteAll(systemMappingService.find(new SysSystemMappingFilter(), null).getContent());
    // Delete all uniform password definitions.
    uniformPasswordService.deleteAll(uniformPasswordService.find(new AccUniformPasswordFilter(), null).getContent());
}
Also used : IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) SysSystemGroupFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupFilter) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) AccUniformPasswordFilter(eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordFilter)

Aggregations

IdmRoleTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter)8 UUID (java.util.UUID)6 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)3 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)2 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)2 IdmAutomaticRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter)2 IdmAutomaticRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter)2 IdmContractPositionFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter)2 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)2 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)2 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)2 IdmRoleCompositionFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter)2 CoreEventProcessor (eu.bcvsolutions.idm.core.api.event.CoreEventProcessor)2 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)2 EventResult (eu.bcvsolutions.idm.core.api.event.EventResult)2