Search in sources :

Example 11 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRoleWithApproval.

@Test
public void testCreateAutomaticAttributeRoleWithApproval() {
    IdmRoleDto role = prepareRole();
    IdmIdentityDto identity = helper.createIdentity();
    IdmIdentityDto guaranteeIdentity = helper.createIdentity();
    IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
    guarantee.setRole(role.getId());
    guarantee.setGuarantee(guaranteeIdentity.getId());
    role.getGuarantees().add(guarantee);
    role = roleService.save(role);
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(role.getName());
    IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
    rule.setAttributeName(IdmIdentity_.username.getName());
    rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
    rule.setValue(identity.getUsername());
    // Create automatic role via manager
    try {
        automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, false, rule);
    } catch (AcceptedException ex) {
        // The request is in approval
        Assert.assertNotNull(ex.getIdentifier());
        UUID requestId = UUID.fromString(ex.getIdentifier());
        loginAsNoAdmin(guaranteeIdentity.getUsername());
        try {
            completeTasksFromUsers(guaranteeIdentity.getUsername(), "approve");
        } catch (ResultCodeException e) {
            fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
        } catch (Exception e) {
            fail("Some problem: " + e.getLocalizedMessage());
        }
        IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
        Assert.assertEquals(RequestState.EXECUTED, request.getState());
        Assert.assertNotNull(request.getAutomaticRole());
        automaticRole = automaticRoleAttributeService.get(request.getAutomaticRole());
        Assert.assertNotNull(automaticRole);
        Assert.assertEquals(role.getId(), automaticRole.getRole());
        return;
    }
    fail("Automatic role request have to be approving by gurantee!");
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 12 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRole.

@Test
public void testCreateAutomaticAttributeRole() {
    IdmRoleDto role = prepareRole();
    IdmIdentityDto guaranteeIdentity = helper.createIdentity();
    IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
    guarantee.setRole(role.getId());
    guarantee.setGuarantee(guaranteeIdentity.getId());
    role.getGuarantees().add(guarantee);
    role = roleService.save(role);
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setState(RequestState.EXECUTED);
    request.setOperation(RequestOperationType.ADD);
    request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
    request.setExecuteImmediately(true);
    request.setName(role.getName());
    request.setRole(role.getId());
    request = roleRequestService.save(request);
    Assert.assertEquals(RequestState.CONCEPT, request.getState());
    IdmIdentityDto identity = helper.createIdentity();
    IdmAutomaticRoleAttributeRuleRequestDto rule = new IdmAutomaticRoleAttributeRuleRequestDto();
    rule.setRequest(request.getId());
    rule.setOperation(RequestOperationType.ADD);
    rule.setAttributeName(IdmIdentity_.username.getName());
    rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
    rule.setValue(identity.getUsername());
    rule = ruleRequestService.save(rule);
    request = roleRequestService.startRequestInternal(request.getId(), true);
    // Recalculate
    Assert.assertNotNull(request.getAutomaticRole());
    this.recalculateSync(request.getAutomaticRole());
    request = roleRequestService.get(request.getId());
    Assert.assertEquals(RequestState.EXECUTED, request.getState());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertFalse(identityRoles.isEmpty());
    Assert.assertEquals(role.getId(), identityRoles.get(0).getRole());
    Assert.assertNotNull(identityRoles.get(0).getRoleTreeNode());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 13 with IdmAutomaticRoleRequestDto

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

the class AutomaticRoleRequestApprovalProcessor method process.

@Override
public EventResult<IdmAutomaticRoleRequestDto> process(EntityEvent<IdmAutomaticRoleRequestDto> event) {
    IdmAutomaticRoleRequestDto dto = event.getContent();
    boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
    // Find approval process (by role priority)
    String wfDefinition = findWfDefinition(dto);
    // If none process definition was found, then is request approved;
    if (Strings.isNullOrEmpty(wfDefinition)) {
        LOG.info("None approval process definition was found, request [{}] for automatic role is approved.", dto);
        return new DefaultEventResult<>(event, this);
    }
    boolean supports = this.supportsAutomaticRole(wfDefinition);
    if (!supports) {
        LOG.info("Approval process definition [{}] does not supports approving for automatic role. Default approval process will be used [{}]. Automatic role request [{}]", wfDefinition, DEFAULT_WF_PROCESS_NAME, dto);
        wfDefinition = DEFAULT_WF_PROCESS_NAME;
    }
    boolean approved = service.startApprovalProcess(dto, checkRight, event, wfDefinition);
    DefaultEventResult<IdmAutomaticRoleRequestDto> result = new DefaultEventResult<>(event, this);
    result.setSuspended(!approved);
    return result;
}
Also used : IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 14 with IdmAutomaticRoleRequestDto

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

the class DefaultAutomaticRoleManager method changeAutomaticRoleRules.

@Override
public IdmAutomaticRoleAttributeDto changeAutomaticRoleRules(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... newRules) {
    Assert.notNull(automaticRole);
    Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setOperation(RequestOperationType.UPDATE);
    request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
    request.setExecuteImmediately(executeImmediately);
    request.setAutomaticRole(automaticRole.getId());
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    final IdmAutomaticRoleRequestDto createdRequest = roleRequestService.save(request);
    ArrayList<IdmAutomaticRoleAttributeRuleDto> rules = Lists.newArrayList(newRules);
    if (rules != null) {
        // Creates request for change or add rule
        rules.forEach(rule -> {
            IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
            ruleRequest.setRequest(createdRequest.getId());
            ruleRequest.setOperation(rule.getId() != null ? RequestOperationType.UPDATE : RequestOperationType.ADD);
            ruleRequest.setAttributeName(rule.getAttributeName());
            ruleRequest.setComparison(rule.getComparison());
            ruleRequest.setType(rule.getType());
            ruleRequest.setFormAttribute(rule.getFormAttribute());
            ruleRequest.setValue(rule.getValue());
            ruleRequest.setRule(rule.getId());
            ruleRequest = ruleRequestService.save(ruleRequest);
        });
    }
    IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
    ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
    List<IdmAutomaticRoleAttributeRuleDto> currentRules = ruleService.find(ruleFilter, null).getContent();
    currentRules.stream().filter(currentRule -> {
        return rules == null || !rules.contains(currentRule);
    }).forEach(ruleToDelete -> {
        // Creates request for remove rule
        IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
        ruleRequest.setRequest(createdRequest.getId());
        ruleRequest.setOperation(RequestOperationType.REMOVE);
        ruleRequest.setAttributeName(ruleToDelete.getAttributeName());
        ruleRequest.setComparison(ruleToDelete.getComparison());
        ruleRequest.setType(ruleToDelete.getType());
        ruleRequest.setFormAttribute(ruleToDelete.getFormAttribute());
        ruleRequest.setValue(ruleToDelete.getValue());
        ruleRequest.setRule(ruleToDelete.getId());
        ruleRequest = ruleRequestService.save(ruleRequest);
    });
    IdmAutomaticRoleRequestDto executedRequest = roleRequestService.startRequestInternal(createdRequest.getId(), true);
    if (RequestState.EXECUTED == executedRequest.getState()) {
        UUID createdAutomaticRoleId = executedRequest.getAutomaticRole();
        Assert.notNull(createdAutomaticRoleId);
        return automaticRoleAttributeService.get(executedRequest.getAutomaticRole());
    }
    if (RequestState.IN_PROGRESS == executedRequest.getState()) {
        throw new AcceptedException(executedRequest.getId().toString());
    }
    if (RequestState.EXCEPTION == executedRequest.getState()) {
        throw new CoreException(executedRequest.getResult().getCause());
    }
    return null;
}
Also used : RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) ArrayList(java.util.ArrayList) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) Lists(com.google.common.collect.Lists) IdmAutomaticRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) Service(org.springframework.stereotype.Service) AutomaticRoleRequestType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleAttributeRuleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleRequestService) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) Assert(org.springframework.util.Assert) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) UUID(java.util.UUID)

Example 15 with IdmAutomaticRoleRequestDto

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

the class DefaultIdmAutomaticRoleRequestService method startRequest.

@Override
@Transactional
public IdmAutomaticRoleRequestDto startRequest(UUID requestId, boolean checkRight) {
    IdmAutomaticRoleRequestDto request = get(requestId);
    Assert.notNull(request, "Request is required!");
    // Validation on exist some rule
    if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType() && RequestOperationType.REMOVE != request.getOperation()) {
        IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
        ruleFilter.setRoleRequestId(requestId);
        List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
        if (ruleConcepts.isEmpty()) {
            throw new RoleRequestException(CoreResultCode.AUTOMATIC_ROLE_REQUEST_START_WITHOUT_RULE, ImmutableMap.of("request", request.getName()));
        }
    }
    try {
        IdmAutomaticRoleRequestService service = this.getIdmAutomaticRoleRequestService();
        if (!(service instanceof DefaultIdmAutomaticRoleRequestService)) {
            throw new CoreException("We expects instace of DefaultIdmAutomaticRoleRequestService!");
        }
        return ((DefaultIdmAutomaticRoleRequestService) service).startRequestNewTransactional(requestId, checkRight);
    } catch (Exception ex) {
        LOG.error(ex.getLocalizedMessage(), ex);
        request = get(requestId);
        Throwable exceptionToLog = resolveException(ex);
        // TODO: I set only cause of exception, not code and properties. If are
        // properties set, then request cannot be save!
        request.setResult(new OperationResultDto.Builder(OperationState.EXCEPTION).setCause(exceptionToLog).build());
        request.setState(RequestState.EXCEPTION);
        return save(request);
    }
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdmAutomaticRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Transactional(org.springframework.transaction.annotation.Transactional)

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