Search in sources :

Example 81 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class AutomaticRoleAttributeRuleDeleteProcessor method process.

@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
    IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
    // 
    List<IdmAutomaticRoleAttributeRuleDto> allRules = automactiRoleAttributeRuleService.findAllRulesForAutomaticRole(dto.getAutomaticRoleAttribute());
    // by default is skip value null => false
    if (!this.getBooleanProperty(SKIP_CHECK_LAST_RULE, event.getProperties())) {
        // it's last rule, remove all identity role
        if (allRules.size() == 1 && dto.getId().equals(allRules.get(0).getId())) {
            // before we start delete identity role, we check how many identities has the auto role
            // if doesn't exist identities that has the role, skip remove
            IdmIdentityFilter identityFilter = new IdmIdentityFilter();
            long totalElements = identityService.find(identityFilter, new PageRequest(0, 1)).getTotalElements();
            if (totalElements > 0) {
                UUID automaticRoleAttributeId = dto.getAutomaticRoleAttribute();
                removeAllRoles(automaticRoleAttributeId);
                // 
                // we also set concept to false
                IdmAutomaticRoleAttributeDto roleAttributeDto = automaticRoleAttributeRuleService.get(automaticRoleAttributeId);
                roleAttributeDto.setConcept(false);
                roleAttributeDto = automaticRoleAttributeRuleService.save(roleAttributeDto);
            }
        }
    }
    UUID automaticRuleId = dto.getId();
    // Find all automatic role requests and remove relation on rule
    if (automaticRuleId != null) {
        IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
        automaticRoleRequestFilter.setRuleId(automaticRuleId);
        ruleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
            request.setRule(null);
            ruleRequestService.save(request);
        });
    }
    // 
    automactiRoleAttributeRuleService.deleteInternal(dto);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 82 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class AutomaticRoleAttributeRuleSaveProcessor method process.

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

Example 83 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult 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 84 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class RoleDeleteProcessor method process.

@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
    IdmRoleDto role = event.getContent();
    // role assigned to identity could not be deleted
    if (identityRoleRepository.countByRole_Id(role.getId()) > 0) {
        throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_IDENTITY_ASSIGNED, ImmutableMap.of("role", role.getName()));
    }
    // 
    // automatic role attribute has assigned this role
    IdmAutomaticRoleFilter automaticRoleFilter = new IdmAutomaticRoleFilter();
    automaticRoleFilter.setRoleId(role.getId());
    long totalElements = automaticRoleAttributeService.find(automaticRoleFilter, new PageRequest(0, 1)).getTotalElements();
    if (totalElements > 0) {
        // some automatic role attribute has assigned this role
        throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_AUTOMATIC_ROLE_ASSIGNED, ImmutableMap.of("role", role.getName()));
    }
    // 
    // remove related automatic roles
    IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
    filter.setRoleId(role.getId());
    roleTreeNodeService.find(filter, null).forEach(roleTreeNode -> {
        try {
            roleTreeNodeService.delete(roleTreeNode);
        } catch (AcceptedException ex) {
            throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_TREE_NODE, ImmutableMap.of("role", role.getName(), "roleTreeNode", roleTreeNode.getId()));
        }
    });
    // Find all concepts and remove relation on role
    IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
    conceptRequestFilter.setRoleId(role.getId());
    conceptRoleRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
        IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
        String message = null;
        if (concept.getState().isTerminatedState()) {
            message = MessageFormat.format("Role [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", role.getName(), concept.getId());
        } else {
            message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested role [{1}] was deleted (not from this role request)!", concept.getId(), role.getName());
            concept.setState(RoleRequestState.CANCELED);
        }
        roleRequestService.addToLog(request, message);
        conceptRoleRequestService.addToLog(concept, message);
        concept.setRole(null);
        roleRequestService.save(request);
        conceptRoleRequestService.save(concept);
    });
    // remove all policies
    IdmAuthorizationPolicyFilter policyFilter = new IdmAuthorizationPolicyFilter();
    policyFilter.setRoleId(role.getId());
    authorizationPolicyService.find(policyFilter, null).forEach(dto -> {
        authorizationPolicyService.delete(dto);
    });
    // Find all automatic role requests and remove relation on automatic role
    UUID roleId = role.getId();
    if (roleId != null) {
        IdmAutomaticRoleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleRequestFilter();
        automaticRoleRequestFilter.setRoleId(roleId);
        automaticRoleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
            request.setRole(null);
            automaticRoleRequestService.save(request);
            automaticRoleRequestService.cancel(request);
        });
    }
    // 
    // remove role guarantees, sub roles and catalog works automatically by hibenate mapping
    service.deleteInternal(role);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmAutomaticRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmRoleTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID) IdmAutomaticRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 85 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult 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)

Aggregations

DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)91 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)12 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)11 UUID (java.util.UUID)11 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)10 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)7 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)7 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)6 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)5 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)5 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)5 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)5 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)5 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)4 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)4 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)4 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)4 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)4 ArrayList (java.util.ArrayList)4