Search in sources :

Example 16 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestService method toDto.

@Override
public IdmAutomaticRoleRequestDto toDto(IdmAutomaticRoleRequest entity, IdmAutomaticRoleRequestDto dto) {
    IdmAutomaticRoleRequestDto requestDto = super.toDto(entity, dto);
    if (requestDto != null && requestDto.getWfProcessId() != null) {
        WorkflowProcessInstanceDto processDto = workflowProcessInstanceService.get(requestDto.getWfProcessId(), false);
        // TODO: create trimmed variant in workflow process instance service
        if (processDto != null) {
            processDto.setProcessVariables(null);
        }
        requestDto.getEmbedded().put(IdmRoleRequestDto.WF_PROCESS_FIELD, processDto);
    }
    return requestDto;
}
Also used : IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)

Example 17 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestService method startRequestInternal.

@Override
@Transactional
public IdmAutomaticRoleRequestDto startRequestInternal(UUID requestId, boolean checkRight) {
    LOG.debug("Start role request [{}]", requestId);
    Assert.notNull(requestId, "Role request ID is required!");
    // Load request ... check right for read
    IdmAutomaticRoleRequestDto request = get(requestId);
    Assert.notNull(request, "Role request DTO is required!");
    Assert.isTrue(RequestState.CONCEPT == request.getState() || RequestState.DUPLICATED == request.getState() || RequestState.EXCEPTION == request.getState(), "Only role request with CONCEPT or EXCEPTION or DUPLICATED state can be started!");
    // Request will be set on in progress state
    request.setState(RequestState.IN_PROGRESS);
    request.setResult(new OperationResultDto.Builder(OperationState.RUNNING).build());
    IdmAutomaticRoleRequestDto savedRequest = this.save(request);
    // Throw event
    Map<String, Serializable> variables = new HashMap<>();
    variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, checkRight);
    return entityEventManager.process(new AutomaticRoleRequestEvent(AutomaticRoleRequestEventType.EXECUTE, savedRequest, variables)).getContent();
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AutomaticRoleRequestEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleRequestEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestService method executeRequestInternal.

private IdmAutomaticRoleRequestDto executeRequestInternal(UUID requestId) {
    Assert.notNull(requestId, "Role request ID is required!");
    IdmAutomaticRoleRequestDto request = this.get(requestId);
    Assert.notNull(request, "Role request is required!");
    IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
    ruleFilter.setRoleRequestId(requestId);
    List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
    UUID automaticRoleId = request.getAutomaticRole();
    if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType()) {
        // Automatic role by attributes
        if (RequestOperationType.REMOVE == request.getOperation()) {
            // Remove automatic role by attributes
            Assert.notNull(automaticRoleId, "Id of automatic role in the request (for delete) is required!");
            automaticRoleAttributeService.delete(automaticRoleAttributeService.get(automaticRoleId));
            request.setAutomaticRole(null);
        } else {
            // Add new or update (rules) for automatic role by attributes
            IdmAutomaticRoleAttributeDto automaticRole = null;
            if (automaticRoleId != null) {
                automaticRole = automaticRoleAttributeService.get(automaticRoleId);
            } else {
                automaticRole = new IdmAutomaticRoleAttributeDto();
                automaticRole = initAttributeAutomaticRole(request, automaticRole);
                automaticRole = automaticRoleAttributeService.save(automaticRole);
                request.setAutomaticRole(automaticRole.getId());
            }
            UUID roleId = automaticRole.getRole() != null ? automaticRole.getRole() : request.getRole();
            Assert.notNull(roleId, "Id of role is required in the automatic role request!");
            IdmRoleDto role = roleService.get(request.getRole());
            Assert.notNull(role, "Role is required in the automatic role request!");
            // Before we do any change, we have to sets the automatic role to concept state
            automaticRole.setConcept(true);
            automaticRoleAttributeService.save(automaticRole);
            // Realize changes for rules
            realizeAttributeRules(request, automaticRole, ruleConcepts);
            // Sets automatic role as no concept -> execute recalculation this role
            automaticRole.setConcept(false);
            automaticRoleAttributeService.recalculate(automaticRoleAttributeService.save(automaticRole).getId());
        }
    } else if (AutomaticRoleRequestType.TREE == request.getRequestType()) {
        // Automatic role by node in a tree
        if (RequestOperationType.REMOVE == request.getOperation()) {
            // Remove tree automatic role
            Assert.notNull(automaticRoleId, "Id of automatic role in the request (for delete) is required!");
            // Recount (remove) assigned roles ensures LRT during delete
            automaticRoleTreeService.delete(automaticRoleTreeService.get(automaticRoleId));
            request.setAutomaticRole(null);
        } else if (RequestOperationType.ADD == request.getOperation()) {
            // Create new tree automatic role
            IdmRoleTreeNodeDto treeAutomaticRole = new IdmRoleTreeNodeDto();
            treeAutomaticRole = initTreeAutomaticRole(request, treeAutomaticRole);
            // Recount of assigned roles ensures LRT after save
            treeAutomaticRole = automaticRoleTreeService.save(treeAutomaticRole);
            request.setAutomaticRole(treeAutomaticRole.getId());
        } else {
            // Update is not supported
            throw new ResultCodeException(CoreResultCode.METHOD_NOT_ALLOWED, "Tree automatic role update is not supported");
        }
    }
    request.setState(RequestState.EXECUTED);
    request.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
    return this.save(request);
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UUID(java.util.UUID) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 19 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestService method createTreeAutomaticRole.

@Override
public IdmRoleTreeNodeDto createTreeAutomaticRole(IdmRoleTreeNodeDto automaticRole) {
    Assert.notNull(automaticRole);
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setName(automaticRole.getName());
    request.setTreeNode(automaticRole.getTreeNode());
    request.setRecursionType(automaticRole.getRecursionType());
    request.setRole(automaticRole.getRole());
    request.setRequestType(AutomaticRoleRequestType.TREE);
    request.setOperation(RequestOperationType.ADD);
    request.setResult(new OperationResultDto.Builder(OperationState.CREATED).build());
    request = this.save(request);
    IdmAutomaticRoleRequestDto result = this.getIdmAutomaticRoleRequestService().startRequest(request.getId(), true);
    if (RequestState.EXECUTED == result.getState()) {
        UUID createdAutomaticRoleId = result.getAutomaticRole();
        Assert.notNull(createdAutomaticRoleId);
        return automaticRoleTreeService.get(createdAutomaticRoleId);
    }
    if (RequestState.IN_PROGRESS == result.getState()) {
        throw new AcceptedException();
    }
    if (RequestState.EXCEPTION == result.getState()) {
        throw new AcceptedException();
    }
    return null;
}
Also used : IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Example 20 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestService method realizeAttributeRules.

/**
 * Execute change of the request for attribute automatic role
 *
 * @param request
 * @param automaticRoleId
 * @param ruleConcepts
 */
private void realizeAttributeRules(IdmAutomaticRoleRequestDto request, IdmAutomaticRoleAttributeDto automaticRole, List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts) {
    // Create new rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.ADD == concept.getOperation();
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
        rule.setAutomaticRoleAttribute(automaticRole.getId());
        rule = automaticRoleRuleService.save(convertConceptRuleToRule(concept, rule));
        // Save created identity role id
        concept.setRule(rule.getId());
        automaticRoleRuleRequestService.save(concept);
    });
    // Update rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.UPDATE == concept.getOperation();
    }).filter(concept -> {
        return concept.getRule() != null;
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = automaticRoleRuleService.get(concept.getRule());
        rule = automaticRoleRuleService.save(convertConceptRuleToRule(concept, rule));
        // Save created identity role id
        concept.setRule(rule.getId());
        automaticRoleRuleRequestService.save(concept);
    });
    // Delete rule
    ruleConcepts.stream().filter(concept -> {
        return RequestOperationType.REMOVE == concept.getOperation();
    }).filter(concept -> {
        return concept.getRule() != null;
    }).forEach(concept -> {
        IdmAutomaticRoleAttributeRuleDto rule = automaticRoleRuleService.get(concept.getRule());
        if (rule != null) {
            concept.setRule(rule.getId());
            automaticRoleRuleRequestService.save(concept);
            // Finally delete of the rule
            automaticRoleRuleService.delete(rule);
        }
    });
}
Also used : RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AutomaticRoleRequestEventType(eu.bcvsolutions.idm.core.model.event.AutomaticRoleRequestEvent.AutomaticRoleRequestEventType) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) Predicate(javax.persistence.criteria.Predicate) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) IdmAutomaticRole_(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRole_) IdmAutomaticRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest_) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ImmutableMap(com.google.common.collect.ImmutableMap) IdmAutomaticRoleAttributeRuleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleRequestService) Collection(java.util.Collection) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Serializable(java.io.Serializable) List(java.util.List) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) HashMap(java.util.HashMap) IdmAutomaticRoleRequestRepository(eu.bcvsolutions.idm.core.model.repository.IdmAutomaticRoleRequestRepository) IdmRoleTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmRoleTreeNode) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmAutomaticRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) AutomaticRoleRequestType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Root(javax.persistence.criteria.Root) AutomaticRoleRequestEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleRequestEvent) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Throwables(com.google.common.base.Throwables) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) IdmAutomaticRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleRequest) ApplicationContext(org.springframework.context.ApplicationContext) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) IdmAutomaticRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) IdmAutomaticRoleAttribute(eu.bcvsolutions.idm.core.model.entity.IdmAutomaticRoleAttribute) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)

Aggregations

IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)21 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)13 UUID (java.util.UUID)12 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)8 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)7 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)7 IdmAutomaticRoleAttributeRuleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 IdmRoleGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto)7 Test (org.junit.Test)7 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)6 IdmAutomaticRoleRequestService (eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 AutomaticRoleRequestType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType)3 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)3 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)3