Search in sources :

Example 61 with IdmIdentityRoleFilter

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

the class IdmIdentityController method roles.

@ResponseBody
@RequestMapping(value = "/{backendId}/roles", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Assigned roles to identity", nickname = "getIdentityRoles", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public Resources<?> roles(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable String backendId) {
    IdmIdentityDto identity = getDto(backendId);
    if (identity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(identity.getId());
    Page<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null, IdmBasePermission.READ);
    // 
    return toResources(identityRoles, IdmIdentityRoleDto.class);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 62 with IdmIdentityRoleFilter

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

the class ChangeIdentityPermissionTest method addSuperAdminRoleWithSubprocessDisapproveTest.

@Test
@Transactional
public void addSuperAdminRoleWithSubprocessDisapproveTest() {
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    IdmIdentityDto test1 = identityService.getByUsername(InitTestData.TEST_USER_1);
    IdmIdentityDto test2 = identityService.getByUsername(InitTestData.TEST_USER_2);
    // Guarantee
    int priority = 500;
    IdmRoleDto adminRole = roleService.getByCode(InitTestData.TEST_ADMIN_ROLE);
    adminRole.setPriority(priority);
    IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
    guarantee.setRole(adminRole.getId());
    guarantee.setGuarantee(test2.getId());
    adminRole.getGuarantees().add(guarantee);
    adminRole = roleService.save(adminRole);
    configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_GUARANTEE_KEY);
    IdmIdentityContractDto contract = identityContractService.getPrimeContract(test1.getId());
    IdmRoleRequestDto request = createRoleRequest(test1);
    request = roleRequestService.save(request);
    IdmConceptRoleRequestDto concept = createRoleConcept(adminRole, contract, request);
    concept = conceptRoleRequestService.save(concept);
    roleRequestService.startRequestInternal(request.getId(), true);
    request = roleRequestService.get(request.getId());
    assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
    WorkflowFilterDto taskFilter = new WorkflowFilterDto();
    taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
    List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    assertEquals(0, tasks.size());
    // HELPDESK - must be skipped
    // MANAGER
    loginAsAdmin(InitTestData.TEST_USER_2);
    taskFilter.setCandidateOrAssigned(InitTestData.TEST_USER_2);
    checkAndCompleteOneTask(taskFilter, InitTestData.TEST_USER_1, "approve");
    // USER MANAGER
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskFilter, InitTestData.TEST_USER_1, "approve");
    // Subprocess - approve by GUARANTEE
    loginAsAdmin(InitTestData.TEST_USER_2);
    taskFilter.setCandidateOrAssigned(InitTestData.TEST_USER_2);
    checkAndCompleteOneTask(taskFilter, InitTestData.TEST_USER_1, "disapprove");
    // SECURITY
    request = roleRequestService.get(request.getId());
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
    checkAndCompleteOneTask(taskFilter, InitTestData.TEST_USER_1, "approve");
    request = roleRequestService.get(request.getId());
    assertEquals(RoleRequestState.EXECUTED, request.getState());
    assertNotNull(request.getWfProcessId());
    concept = conceptRoleRequestService.get(concept.getId());
    assertNotNull(concept.getWfProcessId());
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(test1.getId());
    Page<IdmIdentityRoleDto> page = identityRoleService.find(filter, null);
    assertEquals(0, page.getSize());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with IdmIdentityRoleFilter

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

the class IdmIdentityRoleControllerRestTest method testFindByText.

@Test
public void testFindByText() {
    // username
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityRoleDto createIdentityRole = getHelper().createIdentityRole(identity, getHelper().createRole());
    IdmIdentityDto other = getHelper().createIdentity();
    getHelper().createIdentityRole(other, getHelper().createRole());
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setText(identity.getUsername());
    List<IdmIdentityRoleDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(createIdentityRole.getId())));
}
Also used : IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdentityRoleByRoleEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.IdentityRoleByRoleEvaluator) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) RoleCanBeRequestedEvaluator(eu.bcvsolutions.idm.core.security.evaluator.role.RoleCanBeRequestedEvaluator) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Set(java.util.Set) Test(org.junit.Test) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Ignore(org.junit.Ignore) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) LocalDate(java.time.LocalDate) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 64 with IdmIdentityRoleFilter

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

the class IdmIdentityRoleControllerRestTest method findByContractPosition.

@Test
public void findByContractPosition() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity.getId());
    IdmContractPositionDto contractPositionOne = getHelper().createContractPosition(contract);
    IdmContractPositionDto contractPositionOther = getHelper().createContractPosition(contract);
    IdmIdentityRoleDto one = getHelper().createIdentityRole(contractPositionOne, getHelper().createRole());
    // other
    getHelper().createIdentityRole(contractPositionOther, getHelper().createRole());
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(identity.getId());
    filter.setContractPositionId(contractPositionOne.getId());
    List<IdmIdentityRoleDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(one.getId())));
}
Also used : IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdentityRoleByRoleEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.IdentityRoleByRoleEvaluator) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) RoleCanBeRequestedEvaluator(eu.bcvsolutions.idm.core.security.evaluator.role.RoleCanBeRequestedEvaluator) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Set(java.util.Set) Test(org.junit.Test) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Ignore(org.junit.Ignore) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) LocalDate(java.time.LocalDate) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 65 with IdmIdentityRoleFilter

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

the class IdmIdentityRoleControllerRestTest method testFindByRoleId.

@Test
public void testFindByRoleId() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmRoleDto roleOne = getHelper().createRole();
    IdmRoleDto roleTwo = getHelper().createRole();
    IdmIdentityRoleDto createIdentityRole = getHelper().createIdentityRole(identity, roleOne);
    getHelper().createIdentityRole(identity, roleTwo);
    // 
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setRoleId(roleOne.getId());
    List<IdmIdentityRoleDto> results = find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(createIdentityRole.getId())));
}
Also used : IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdentityRoleByRoleEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.IdentityRoleByRoleEvaluator) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) RoleCanBeRequestedEvaluator(eu.bcvsolutions.idm.core.security.evaluator.role.RoleCanBeRequestedEvaluator) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Set(java.util.Set) Test(org.junit.Test) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Ignore(org.junit.Ignore) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) LocalDate(java.time.LocalDate) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Aggregations

IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)116 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)85 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)84 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)81 Test (org.junit.Test)72 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)67 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)46 UUID (java.util.UUID)41 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)39 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)38 List (java.util.List)38 Autowired (org.springframework.beans.factory.annotation.Autowired)38 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)33 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)31 LocalDate (java.time.LocalDate)31 Assert (org.junit.Assert)28 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)27 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)25 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)25 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)25