Search in sources :

Example 41 with IdmRoleRequestDto

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

the class RoleRequestApprovalProcessor method process.

@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
    IdmRoleRequestDto dto = event.getContent();
    boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
    // 
    String wfDefinition = getConfigurationValue(PROPERTY_WF);
    if (Strings.isNullOrEmpty(wfDefinition)) {
        wfDefinition = DEFAULT_WF_PROCESS_NAME;
    }
    boolean approved = service.startApprovalProcess(dto, checkRight, event, wfDefinition);
    DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
    result.setSuspended(!approved);
    return result;
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 42 with IdmRoleRequestDto

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

the class RoleRequestRealizationProcessor method process.

@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
    IdmRoleRequestDto dto = event.getContent();
    event.setContent(service.executeRequest(dto.getId()));
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 43 with IdmRoleRequestDto

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

the class DefaultIdmRoleRequestService method startRequestInternal.

@Override
@Transactional
public IdmRoleRequestDto 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
    IdmRoleRequestDto request = get(requestId);
    Assert.notNull(request, "Role request DTO is required!");
    Assert.isTrue(RoleRequestState.CONCEPT == request.getState() || RoleRequestState.DUPLICATED == request.getState() || RoleRequestState.EXCEPTION == request.getState(), "Only role request with CONCEPT or EXCEPTION or DUPLICATED state can be started!");
    IdmRoleRequestDto duplicant = validateOnDuplicity(request);
    if (duplicant != null) {
        request.setState(RoleRequestState.DUPLICATED);
        request.setDuplicatedToRequest(duplicant.getId());
        this.addToLog(request, MessageFormat.format("This request [{0}] is duplicated to another change permissions request [{1}]", request.getId(), duplicant.getId()));
        return this.save(request);
    }
    // Duplicant is fill, but request is not duplicated (maybe in past)
    if (request.getDuplicatedToRequest() != null) {
        request.setDuplicatedToRequest(null);
    }
    // Check on same applicants in all role concepts
    boolean identityNotSame = this.get(request.getId()).getConceptRoles().stream().anyMatch(concept -> {
        // get contract dto from embedded map
        IdmIdentityContractDto contract = (IdmIdentityContractDto) concept.getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
        if (contract == null) {
            // If is contract from concept null, then contract via identity role must works
            contract = (IdmIdentityContractDto) identityRoleService.get(concept.getIdentityRole()).getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
        }
        return !request.getApplicant().equals(contract.getIdentity());
    });
    if (identityNotSame) {
        throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_APPLICANTS_NOT_SAME, ImmutableMap.of("request", request, "applicant", request.getApplicant()));
    }
    // Convert whole request to JSON and persist (without logs and embedded data)
    try {
        IdmRoleRequestDto requestOriginal = get(requestId);
        trimRequest(requestOriginal);
        request.setOriginalRequest(objectMapper.writeValueAsString(requestOriginal));
    } catch (JsonProcessingException e) {
        throw new RoleRequestException(CoreResultCode.BAD_REQUEST, e);
    }
    // Request will be set on in progress state
    request.setState(RoleRequestState.IN_PROGRESS);
    IdmRoleRequestDto savedRequest = this.save(request);
    // Throw event
    Map<String, Serializable> variables = new HashMap<>();
    variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, checkRight);
    return entityEventManager.process(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, savedRequest, variables)).getContent();
}
Also used : RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) Serializable(java.io.Serializable) HashMap(java.util.HashMap) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with IdmRoleRequestDto

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

the class DefaultIdmRoleRequestService method executeRequestInternal.

private IdmRoleRequestDto executeRequestInternal(UUID requestId) {
    Assert.notNull(requestId, "Role request ID is required!");
    IdmRoleRequestDto request = this.get(requestId);
    Assert.notNull(request, "Role request is required!");
    List<IdmConceptRoleRequestDto> concepts = request.getConceptRoles();
    IdmIdentityDto identity = identityService.get(request.getApplicant());
    boolean identityNotSame = concepts.stream().anyMatch(concept -> {
        // get contract dto from embedded map
        IdmIdentityContractDto contract = (IdmIdentityContractDto) concept.getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
        return !identity.getId().equals(contract.getIdentity());
    });
    if (identityNotSame) {
        throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_APPLICANTS_NOT_SAME, ImmutableMap.of("request", request, "applicant", identity.getUsername()));
    }
    // Create new identity role
    concepts.stream().filter(concept -> {
        return ConceptRoleRequestOperation.ADD == concept.getOperation();
    }).filter(concept -> {
        // approval event disabled)
        return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
    }).forEach(concept -> {
        IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
        identityRole = identityRoleService.save(convertConceptRoleToIdentityRole(conceptRoleRequestService.get(concept.getId()), identityRole));
        // Save created identity role id
        concept.setIdentityRole(identityRole.getId());
        concept.setState(RoleRequestState.EXECUTED);
        IdmRoleDto roleDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role, IdmRoleDto.class);
        String message = MessageFormat.format("Role [{0}] was added to applicant. Requested in concept [{1}].", roleDto.getCode(), concept.getId());
        conceptRoleRequestService.addToLog(concept, message);
        conceptRoleRequestService.addToLog(request, message);
        conceptRoleRequestService.save(concept);
    });
    // Update identity role
    concepts.stream().filter(concept -> {
        return ConceptRoleRequestOperation.UPDATE == concept.getOperation();
    }).filter(concept -> {
        // approval event disabled)
        return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
    }).forEach(concept -> {
        IdmIdentityRoleDto identityRole = identityRoleService.get(concept.getIdentityRole());
        identityRole = identityRoleService.save(convertConceptRoleToIdentityRole(conceptRoleRequestService.get(concept.getId()), identityRole));
        // Save created identity role id
        concept.setIdentityRole(identityRole.getId());
        concept.setState(RoleRequestState.EXECUTED);
        IdmRoleDto roleDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role, IdmRoleDto.class);
        String message = MessageFormat.format("Role [{0}] was changed. Requested in concept [{1}].", roleDto.getCode(), concept.getId());
        conceptRoleRequestService.addToLog(concept, message);
        conceptRoleRequestService.addToLog(request, message);
        conceptRoleRequestService.save(concept);
    });
    // Delete identity role
    concepts.stream().filter(concept -> {
        return ConceptRoleRequestOperation.REMOVE == concept.getOperation();
    }).filter(concept -> {
        // approval event disabled)
        return RoleRequestState.APPROVED == concept.getState() || RoleRequestState.CONCEPT == concept.getState();
    }).filter(concept -> {
        return concept.getIdentityRole() != null;
    }).forEach(concept -> {
        IdmIdentityRoleDto identityRole = identityRoleService.get(concept.getIdentityRole());
        if (identityRole != null) {
            concept.setState(RoleRequestState.EXECUTED);
            // we have to remove relation on
            concept.setIdentityRole(null);
            // deleted identityRole
            String message = MessageFormat.format("IdentityRole [{0}] (reqested in concept [{1}]) was deleted (from this role request).", identityRole.getId(), concept.getId());
            conceptRoleRequestService.addToLog(concept, message);
            conceptRoleRequestService.addToLog(request, message);
            conceptRoleRequestService.save(concept);
            identityRoleService.delete(identityRole);
        }
    });
    request.setState(RoleRequestState.EXECUTED);
    return this.save(request);
}
Also used : IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) Predicate(javax.persistence.criteria.Predicate) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Loggable(eu.bcvsolutions.idm.core.api.domain.Loggable) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest) UUID(java.util.UUID) Serializable(java.io.Serializable) IdmRoleRequestRepository(eu.bcvsolutions.idm.core.model.repository.IdmRoleRequestRepository) List(java.util.List) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) Optional(java.util.Optional) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) 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) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Root(javax.persistence.criteria.Root) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DateTime(org.joda.time.DateTime) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Throwables(com.google.common.base.Throwables) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) ApplicationContext(org.springframework.context.ApplicationContext) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 45 with IdmRoleRequestDto

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

the class DefaultIdmRoleRequestService method toDto.

@Override
public IdmRoleRequestDto toDto(IdmRoleRequest entity, IdmRoleRequestDto dto) {
    IdmRoleRequestDto requestDto = super.toDto(entity, dto);
    // Set concepts to request DTO
    if (requestDto != null) {
        requestDto.setConceptRoles(conceptRoleRequestService.findAllByRoleRequest(requestDto.getId()));
    }
    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 : WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Aggregations

IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)69 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)54 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)52 Test (org.junit.Test)52 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)51 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)49 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)37 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)35 List (java.util.List)27 ArrayList (java.util.ArrayList)26 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)24 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)24 Transactional (org.springframework.transaction.annotation.Transactional)20 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)9 IdmConceptRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter)9 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)8 IdmRoleGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto)7 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)7