Search in sources :

Example 6 with IdmConceptRoleRequestFilter

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

the class RemoveAutomaticRoleTaskExecutor method end.

@Override
protected Boolean end(Boolean result, Exception ex) {
    Boolean ended = super.end(result, ex);
    // 
    if (BooleanUtils.isTrue(ended)) {
        IdmRoleDto role = DtoUtils.getEmbedded(getAutomaticRole(), IdmRoleTreeNode_.role, IdmRoleDto.class);
        // 
        long assignedRoles = identityRoleService.findByAutomaticRole(getAutomaticRoleId(), new PageRequest(0, 1)).getTotalElements();
        if (assignedRoles != 0) {
            LOG.debug("Remove role [{}] by automatic role [{}] is not complete, some roles [{}] remains assigned to identities.", role.getCode(), getAutomaticRole().getId(), assignedRoles);
            return ended;
        }
        // 
        LOG.debug("Remove role [{}] by automatic role [{}]", role.getCode(), getAutomaticRole().getId());
        try {
            // 
            // Find all concepts and remove relation on role tree
            IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
            conceptRequestFilter.setAutomaticRole(getAutomaticRoleId());
            // 
            List<IdmConceptRoleRequestDto> concepts = conceptRequestService.find(conceptRequestFilter, null).getContent();
            for (IdmConceptRoleRequestDto concept : concepts) {
                IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
                String message = null;
                if (concept.getState().isTerminatedState()) {
                    message = MessageFormat.format("Role tree node [{0}] (reqested in concept [{1}]) was deleted (not from this role request)!", getAutomaticRoleId(), concept.getId());
                } else {
                    message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested RoleTreeNode [{1}] was deleted (not from this role request)!", concept.getId(), getAutomaticRoleId());
                    concept.setState(RoleRequestState.CANCELED);
                }
                roleRequestService.addToLog(request, message);
                conceptRequestService.addToLog(concept, message);
                concept.setAutomaticRole(null);
                roleRequestService.save(request);
                conceptRequestService.save(concept);
            }
            // Find all automatic role requests and remove relation on automatic role
            if (automaticRoleId != null) {
                IdmAutomaticRoleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleRequestFilter();
                automaticRoleRequestFilter.setAutomaticRoleId(automaticRoleId);
                automaticRoleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
                    request.setAutomaticRole(null);
                    automaticRoleRequestService.save(request);
                // WFs cannot be cancel here, because this method can be called from the same WF
                // automaticRoleRequestService.cancel(request);
                });
            }
            // by default is this allowed
            if (this.isDeleteEntity()) {
                // delete entity
                if (getAutomaticRole() instanceof IdmRoleTreeNodeDto) {
                    roleTreeNodeService.deleteInternalById(getAutomaticRole().getId());
                } else {
                    // remove all rules
                    automaticRoleAttributeRuleService.deleteAllByAttribute(getAutomaticRole().getId());
                    automaticRoleAttributeService.deleteInternalById(getAutomaticRole().getId());
                }
            }
            // 
            LOG.debug("End: Remove role [{}] by automatic role [{}].", role.getCode(), getAutomaticRole().getId());
        // 
        } catch (Exception O_o) {
            LOG.debug("Remove role [{}] by automatic role [{}] failed", role.getCode(), getAutomaticRole().getId(), O_o);
            // 
            IdmLongRunningTaskDto task = longRunningTaskService.get(getLongRunningTaskId());
            ResultModel resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", getLongRunningTaskId(), "taskType", task.getTaskType(), "instanceId", task.getInstanceId()));
            saveResult(resultModel, OperationState.EXCEPTION, O_o);
        }
    }
    // 
    return ended;
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmAutomaticRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 7 with IdmConceptRoleRequestFilter

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

the class IdentityContractDeleteProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto contract = event.getContent();
    // 
    // delete referenced roles
    identityRoleService.findAllByContract(contract.getId()).forEach(identityRole -> {
        identityRoleService.delete(identityRole);
    });
    // Find all concepts and remove relation on role
    IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
    conceptRequestFilter.setIdentityContractId(contract.getId());
    conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
        IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
        String message = null;
        if (concept.getState().isTerminatedState()) {
            message = MessageFormat.format("IdentityContract [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", contract.getId(), concept.getId());
        } else {
            message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityContract [{1}] was deleted (not from this role request)!", concept.getId(), contract.getId());
            concept.setState(RoleRequestState.CANCELED);
        }
        roleRequestService.addToLog(request, message);
        conceptRequestService.addToLog(concept, message);
        concept.setIdentityContract(null);
        roleRequestService.save(request);
        conceptRequestService.save(concept);
    });
    // delete contract guarantees
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setIdentityContractId(contract.getId());
    contractGuaranteeService.find(filter, null).forEach(guarantee -> {
        contractGuaranteeService.delete(guarantee);
    });
    // delete identity contract
    service.deleteInternal(contract);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter)

Example 8 with IdmConceptRoleRequestFilter

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

the class IdentityRoleDeleteProcessor method process.

@Override
public EventResult<IdmIdentityRoleDto> process(EntityEvent<IdmIdentityRoleDto> event) {
    IdmIdentityRoleDto identityRole = event.getContent();
    // Find all concepts and remove relation on identity role
    IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
    conceptRequestFilter.setIdentityRoleId(identityRole.getId());
    conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
        IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
        String message = null;
        if (concept.getState().isTerminatedState()) {
            message = MessageFormat.format("IdentityRole [{0}] (reqested in concept [{1}]) was deleted (not from this role request)!", identityRole.getId(), concept.getId());
        } else {
            message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityRole [{1}] was deleted (not from this role request)!", concept.getId(), identityRole.getId());
            concept.setState(RoleRequestState.CANCELED);
        }
        roleRequestService.addToLog(request, message);
        conceptRequestService.addToLog(concept, message);
        concept.setIdentityRole(null);
        roleRequestService.save(request);
        conceptRequestService.save(concept);
    });
    // 
    // remove all IdentityRoleValidRequest for this role
    List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityRoleId(identityRole.getId());
    identityRoleValidRequestService.deleteAll(validRequests);
    // 
    // Delete identity role
    service.deleteInternal(identityRole);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmIdentityRoleValidRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleValidRequestDto)

Example 9 with IdmConceptRoleRequestFilter

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

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

the class RoleRequestByIdentityEvaluatorIntegrationTest method testCanReadRoleRequestByIdentity.

@Test
public void testCanReadRoleRequestByIdentity() {
    IdmIdentityDto identityOne = helper.createIdentity();
    IdmIdentityDto identityTwo = helper.createIdentity();
    // create policy
    IdmRoleDto role = helper.createRole();
    helper.createUuidPolicy(role.getId(), identityOne.getId(), IdmBasePermission.READ);
    helper.createIdentityRole(identityTwo, role);
    helper.createIdentityRole(identityTwo, roleService.getByCode(InitDemoData.DEFAULT_ROLE_NAME));
    IdmRoleRequestDto roleRequest = helper.assignRoles(helper.getPrimeContract(identityOne.getId()), role);
    // 
    try {
        loginService.login(new LoginDto(identityTwo.getUsername(), identityTwo.getPassword()));
        // 
        Page<IdmRoleRequestDto> roleRequests = roleRequestService.find(null, IdmBasePermission.READ);
        assertEquals(1, roleRequests.getTotalElements());
        // 
        IdmRoleRequestDto read = roleRequestService.get(roleRequest.getId(), IdmBasePermission.READ);
        assertEquals(roleRequest, read);
        // 
        IdmConceptRoleRequestFilter filter = new IdmConceptRoleRequestFilter();
        filter.setRoleRequestId(roleRequest.getId());
        Page<IdmConceptRoleRequestDto> concepts = conceptRoleRequestController.find(filter, null, IdmBasePermission.READ);
        assertEquals(1, concepts.getTotalElements());
    } finally {
        logout();
    }
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmConceptRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter)10 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)6 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 Test (org.junit.Test)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)2 IdmAutomaticRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleRequestFilter)2 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)2 UUID (java.util.UUID)2 PageRequest (org.springframework.data.domain.PageRequest)2 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)1 EntityAccountDto (eu.bcvsolutions.idm.acc.dto.EntityAccountDto)1 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)1 RoleRequestState (eu.bcvsolutions.idm.core.api.domain.RoleRequestState)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)1