Search in sources :

Example 6 with ResolvedIncompatibleRoleDto

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

the class IdmIdentityControllerRestTest method testGetIncompatibleRolesWithoutRemovedInConcept.

@Test
public void testGetIncompatibleRolesWithoutRemovedInConcept() throws Exception {
    IdmIdentityDto applicant = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto roleOne = getHelper().createRole();
    IdmRoleDto roleTwo = getHelper().createRole();
    IdmRoleDto roleThree = getHelper().createRole();
    IdmRoleDto roleFour = getHelper().createRole();
    IdmRoleDto roleFive = getHelper().createRole();
    IdmRoleDto roleSix = getHelper().createRole();
    // assign roles
    getHelper().createIdentityRole(applicant, roleOne);
    getHelper().createIdentityRole(applicant, roleTwo);
    getHelper().createIdentityRole(applicant, roleThree);
    getHelper().createIdentityRole(applicant, roleFour);
    getHelper().createIdentityRole(applicant, roleFive);
    // create incompatible roles definition
    getHelper().createIncompatibleRole(roleOne, roleTwo);
    getHelper().createIncompatibleRole(roleThree, roleFour);
    getHelper().createIncompatibleRole(roleFive, roleSix);
    // 
    String response = getMockMvc().perform(get(String.format("%s/incompatible-roles", getDetailUrl(applicant.getId()))).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    // 
    Set<IdmIncompatibleRoleDto> incompatibleRoles = toDtos(response, ResolvedIncompatibleRoleDto.class).stream().map(ResolvedIncompatibleRoleDto::getIncompatibleRole).collect(Collectors.toSet());
    Assert.assertEquals(2, incompatibleRoles.size());
    Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
        return ir.getSuperior().equals(roleOne.getId()) && ir.getSub().equals(roleTwo.getId());
    }));
    Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
        return ir.getSuperior().equals(roleThree.getId()) && ir.getSub().equals(roleFour.getId());
    }));
}
Also used : MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) StringUtils(org.apache.commons.lang3.StringUtils) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IdmProfileService(eu.bcvsolutions.idm.core.api.service.IdmProfileService) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) Set(java.util.Set) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) UUID(java.util.UUID) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) Collectors(java.util.stream.Collectors) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMvcRequestBuilders.patch(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PanelDto(eu.bcvsolutions.idm.core.api.dto.PanelDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) FilterManager(eu.bcvsolutions.idm.core.api.repository.filter.FilterManager) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmPasswordService(eu.bcvsolutions.idm.core.api.service.IdmPasswordService) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmFormProjectionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormProjectionService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdentityFormValueEvaluator(eu.bcvsolutions.idm.core.security.evaluator.eav.IdentityFormValueEvaluator) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) Matchers(org.hamcrest.Matchers) MultiValueMap(org.springframework.util.MultiValueMap) IOException(java.io.IOException) Test(org.junit.Test) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) URLEncoder(java.net.URLEncoder) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SelfIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.SelfIdentityEvaluator) Ignore(org.junit.Ignore) PrivateIdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.PrivateIdentityConfiguration) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdentityDisableBulkAction(eu.bcvsolutions.idm.core.bulk.action.impl.IdentityDisableBulkAction) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) InputStream(java.io.InputStream) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 7 with ResolvedIncompatibleRoleDto

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

the class IdmRoleControllerRestTest method testGetIncompatibleRoles.

@Test
public void testGetIncompatibleRoles() throws Exception {
    IdmRoleDto roleOne = getHelper().createRole();
    IdmRoleDto roleTwo = getHelper().createRole();
    IdmRoleDto roleThree = getHelper().createRole();
    IdmRoleDto roleFour = getHelper().createRole();
    IdmRoleDto roleFive = getHelper().createRole();
    IdmRoleDto roleSix = getHelper().createRole();
    // create incompatible roles definition
    getHelper().createIncompatibleRole(roleTwo, roleFive);
    getHelper().createIncompatibleRole(roleFive, roleSix);
    // 
    // create role composition
    getHelper().createRoleComposition(roleOne, roleTwo);
    getHelper().createRoleComposition(roleOne, roleThree);
    getHelper().createRoleComposition(roleTwo, roleFour);
    getHelper().createRoleComposition(roleThree, roleFive);
    // 
    String response = getMockMvc().perform(get(String.format("%s/incompatible-roles", getDetailUrl(roleOne.getId()))).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    // 
    Set<IdmIncompatibleRoleDto> incompatibleRoles = toDtos(response, ResolvedIncompatibleRoleDto.class).stream().map(ResolvedIncompatibleRoleDto::getIncompatibleRole).collect(Collectors.toSet());
    Assert.assertEquals(1, incompatibleRoles.size());
    Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
        return ir.getSuperior().equals(roleTwo.getId()) && ir.getSub().equals(roleFive.getId());
    }));
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) Collectors(java.util.stream.Collectors) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) RoleCanBeRequestedEvaluator(eu.bcvsolutions.idm.core.security.evaluator.role.RoleCanBeRequestedEvaluator) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 8 with ResolvedIncompatibleRoleDto

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

the class IdentityIncompatibleRoleReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    // prepare temp file for json stream
    File temp = getAttachmentManager().createTempFile();
    // 
    try (FileOutputStream outputStream = new FileOutputStream(temp)) {
        // write into json stream
        JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
        try {
            // json will be array of identities
            jGenerator.writeStartArray();
            // form instance has useful methods to transform form values
            Pageable pageable = PageRequest.of(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
            // 
            counter = 0L;
            do {
                Page<IdmIdentityDto> identities = identityService.find(null, pageable, IdmBasePermission.READ);
                if (count == null) {
                    count = identities.getTotalElements();
                }
                boolean canContinue = true;
                for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
                    IdmIdentityDto identity = i.next();
                    // search assigned roles
                    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
                    filter.setIdentityId(identity.getId());
                    // direct roles only
                    filter.setDirectRole(Boolean.TRUE);
                    List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null, IdmBasePermission.READ).getContent();
                    // search incompatible roles
                    Set<ResolvedIncompatibleRoleDto> incompatibleRoles = incompatibleRoleService.resolveIncompatibleRoles(identityRoles.stream().map(ir -> ir.getRole()).collect(Collectors.toList()));
                    for (ResolvedIncompatibleRoleDto resolvedIncompatibleRole : incompatibleRoles) {
                        // add item into report
                        RptIdentityIncompatibleRoleDto reportItem = new RptIdentityIncompatibleRoleDto();
                        reportItem.setIdentity(identity);
                        reportItem.setDirectRole(resolvedIncompatibleRole.getDirectRole());
                        reportItem.setIncompatibleRole(resolvedIncompatibleRole.getIncompatibleRole());
                        // dtos in embedded cannot be parsed from json automatically as objects => aaet them into report dto directly
                        IdmRoleDto superior = DtoUtils.getEmbedded(resolvedIncompatibleRole.getIncompatibleRole(), IdmIncompatibleRole_.superior);
                        IdmRoleDto sub = DtoUtils.getEmbedded(resolvedIncompatibleRole.getIncompatibleRole(), IdmIncompatibleRole_.sub);
                        reportItem.setSuperior(superior);
                        reportItem.setSub(sub);
                        // 
                        getMapper().writeValue(jGenerator, reportItem);
                    }
                    // supports cancel report generating (report extends long running task)
                    ++counter;
                    canContinue = updateState();
                }
                // iterate while next page of identities is available
                pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
            } while (pageable != null);
            // 
            // close array of identities
            jGenerator.writeEndArray();
        } finally {
            // close json stream
            jGenerator.close();
        }
        // save create temp file with array of identities in json as attachment
        return createAttachment(report, new FileInputStream(temp));
    } catch (IOException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    } finally {
        FileUtils.deleteQuietly(temp);
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) FileInputStream(java.io.FileInputStream) RptIdentityIncompatibleRoleDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityIncompatibleRoleDto) Pageable(org.springframework.data.domain.Pageable) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) File(java.io.File)

Example 9 with ResolvedIncompatibleRoleDto

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

the class DefaultIdmRoleRequestService method getIncompatibleRoles.

@Override
public Set<ResolvedIncompatibleRoleDto> getIncompatibleRoles(IdmRoleRequestDto request, IdmBasePermission... permissions) {
    // Currently assigned roles
    IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
    identityRoleFilter.setIdentityId(request.getApplicant());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null, permissions).getContent();
    // Roles from concepts
    IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
    conceptFilter.setRoleRequestId(request.getId());
    List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.find(conceptFilter, null, permissions).getContent();
    Set<UUID> removedIdentityRoleIds = new HashSet<>();
    // We don't want calculate incompatible roles for ended or disapproved concepts
    List<IdmConceptRoleRequestDto> conceptsForCheck = // 
    concepts.stream().filter(concept -> {
        // role can be deleted in the mean time
        return concept.getRole() != null;
    }).filter(// 
    concept -> // 
    RoleRequestState.CONCEPT == concept.getState() || RoleRequestState.IN_PROGRESS == concept.getState() || RoleRequestState.APPROVED == concept.getState() || // 
    RoleRequestState.EXECUTED == concept.getState()).collect(Collectors.toList());
    Set<IdmRoleDto> roles = new HashSet<>();
    conceptsForCheck.stream().filter(concept -> {
        boolean isDelete = concept.getOperation() == ConceptRoleRequestOperation.REMOVE;
        if (isDelete) {
            // removed role fixes the incompatibility
            removedIdentityRoleIds.add(concept.getIdentityRole());
        }
        return !isDelete;
    }).forEach(concept -> roles.add(DtoUtils.getEmbedded(concept, IdmConceptRoleRequest_.role)));
    identityRoles.stream().filter(identityRole -> !removedIdentityRoleIds.contains(identityRole.getId())).forEach(identityRole -> roles.add(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role)));
    // We want to returns only incompatibilities caused by new added roles
    Set<ResolvedIncompatibleRoleDto> incompatibleRoles = incompatibleRoleService.resolveIncompatibleRoles(Lists.newArrayList(roles));
    return // 
    incompatibleRoles.stream().filter(incompatibleRole -> {
        return // 
        conceptsForCheck.stream().anyMatch(concept -> concept.getOperation() == ConceptRoleRequestOperation.ADD && (concept.getRole().equals(incompatibleRole.getDirectRole().getId()) || concept.getRole().equals(incompatibleRole.getIncompatibleRole().getSuperior()) || concept.getRole().equals(incompatibleRole.getIncompatibleRole().getSub())));
    // 
    }).collect(Collectors.toSet());
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SiemLoggerManager(eu.bcvsolutions.idm.core.api.audit.service.SiemLoggerManager) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Predicate(javax.persistence.criteria.Predicate) IdmConceptRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest_) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Loggable(eu.bcvsolutions.idm.core.api.domain.Loggable) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) Set(java.util.Set) IdentityRoleEvent(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) Serializable(java.io.Serializable) IdmRoleRequestRepository(eu.bcvsolutions.idm.core.model.repository.IdmRoleRequestRepository) IOUtils(org.apache.commons.io.IOUtils) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) Session(org.hibernate.Session) BooleanUtils(org.apache.commons.lang3.BooleanUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) Root(javax.persistence.criteria.Root) WorkflowHistoricProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricProcessInstanceService) DuplicateRolesDto(eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractEventableDtoService(eu.bcvsolutions.idm.core.api.service.AbstractEventableDtoService) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) IdmIdentityRoleThinService(eu.bcvsolutions.idm.core.api.service.thin.IdmIdentityRoleThinService) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) IdmRoleRequestByIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) ByteArrayInputStream(org.fusesource.hawtbuf.ByteArrayInputStream) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Objects(com.google.common.base.Objects) ImmutableMap(com.google.common.collect.ImmutableMap) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleCompositionService(eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService) IdmRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) List(java.util.List) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) LocalDate(java.time.LocalDate) 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) ValueGeneratorManager(eu.bcvsolutions.idm.core.api.service.ValueGeneratorManager) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) Propagation(org.springframework.transaction.annotation.Propagation) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdentityRoleEventType(eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent.IdentityRoleEventType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmRoleComposition_(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) PROPERTY_STATE(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.PROPERTY_STATE) ApplicationContext(org.springframework.context.ApplicationContext) IdmIncompatibleRoleService(eu.bcvsolutions.idm.core.api.service.IdmIncompatibleRoleService) IdmFormValue_(eu.bcvsolutions.idm.core.eav.entity.IdmFormValue_) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 10 with ResolvedIncompatibleRoleDto

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

the class IdmRoleRequestControllerRestTest method testGetIncompatibleRoles.

@Test
public void testGetIncompatibleRoles() throws Exception {
    IdmRoleRequestDto roleRequest = createDto();
    IdmRoleDto roleOne = getHelper().createRole();
    IdmRoleDto roleTwo = getHelper().createRole();
    IdmRoleDto roleThree = getHelper().createRole();
    IdmRoleDto roleFour = getHelper().createRole();
    IdmRoleDto roleFive = getHelper().createRole();
    IdmRoleDto roleSix = getHelper().createRole();
    // assign roles
    IdmIdentityDto applicant = identityService.get(roleRequest.getApplicant());
    getHelper().createIdentityRole(applicant, roleOne);
    getHelper().createIdentityRole(applicant, roleTwo);
    getHelper().createIdentityRole(applicant, roleThree);
    // create incompatible roles definition
    getHelper().createIncompatibleRole(roleOne, roleTwo);
    getHelper().createIncompatibleRole(roleThree, roleFour);
    getHelper().createIncompatibleRole(roleOne, roleSix);
    // 
    // create concepts
    IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
    concept.setRoleRequest(roleRequest.getId());
    concept.setIdentityContract(getHelper().getPrimeContract(applicant).getId());
    concept.setRole(roleFour.getId());
    concept.setOperation(ConceptRoleRequestOperation.ADD);
    conceptRoleRequestService.save(concept);
    concept = new IdmConceptRoleRequestDto();
    concept.setRoleRequest(roleRequest.getId());
    concept.setIdentityContract(getHelper().getPrimeContract(applicant).getId());
    concept.setRole(roleFive.getId());
    concept.setOperation(ConceptRoleRequestOperation.ADD);
    conceptRoleRequestService.save(concept);
    // 
    String response = getMockMvc().perform(get(String.format("%s/incompatible-roles", getDetailUrl(roleRequest.getId()))).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    // 
    Set<IdmIncompatibleRoleDto> incompatibleRoles = toDtos(response, ResolvedIncompatibleRoleDto.class).stream().map(ResolvedIncompatibleRoleDto::getIncompatibleRole).collect(Collectors.toSet());
    Assert.assertEquals(1, incompatibleRoles.size());
    Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
        return ir.getSuperior().equals(roleThree.getId()) && ir.getSub().equals(roleFour.getId());
    }));
}
Also used : IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) MultiValueMap(org.springframework.util.MultiValueMap) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Collectors(java.util.stream.Collectors) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Aggregations

ResolvedIncompatibleRoleDto (eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto)16 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)15 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)12 IdmIncompatibleRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto)10 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)9 Test (org.junit.Test)9 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)8 List (java.util.List)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 Lists (com.google.common.collect.Lists)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)6 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)6 Assert (org.junit.Assert)6 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)5 RoleRequestState (eu.bcvsolutions.idm.core.api.domain.RoleRequestState)5 RoleRequestedByType (eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType)5 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)5