Search in sources :

Example 6 with IdmRoleRequestFilter

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

the class IdmRequestIdentityRoleServiceIntegrationTest method testAssignRoles.

@Test
@Transactional
public void testAssignRoles() {
    IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmRoleDto role = this.getHelper().createRole();
    IdmRoleDto roleTwo = this.getHelper().createRole();
    IdmRoleDto roleThree = this.getHelper().createRole();
    Set<UUID> roles = Sets.newSet(role.getId(), roleTwo.getId(), roleThree.getId());
    // Create request for new identity-role
    IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
    dto.setIdentityContract(contract.getId());
    dto.setRole(role.getId());
    dto.setRoles(Sets.newSet(roleTwo.getId(), roleThree.getId()));
    dto.setValidFrom(LocalDate.now().minusDays(1));
    dto.setValidTill(LocalDate.now().plusDays(10));
    IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
    Assert.assertNotNull(createdRequestIdentityRole);
    // Request must been created
    Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
    Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
    IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest());
    Assert.assertNotNull(request);
    // Concepts are empty, because the request does not return them be default
    Assert.assertEquals(0, request.getConceptRoles().size());
    request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Concepts are not empty now
    Assert.assertEquals(3, request.getConceptRoles().size());
    // Applicant must be ours identity
    Assert.assertEquals(contract.getIdentity(), request.getApplicant());
    request.getConceptRoles().forEach(concept -> {
        Assert.assertEquals(contract.getId(), concept.getIdentityContract());
        Assert.assertTrue(roles.contains(concept.getRole()));
        Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
        Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
    });
    this.getHelper().executeRequest(request, false, true);
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(3, identityRoles.size());
    identityRoles.forEach(identityRole -> {
        Assert.assertTrue(roles.contains(identityRole.getRole()));
        Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), identityRole.getValidFrom());
        Assert.assertEquals(createdRequestIdentityRole.getValidTill(), identityRole.getValidTill());
    });
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with IdmRoleRequestFilter

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

the class IdmRequestIdentityRoleServiceIntegrationTest method testUpdateAddingConcept.

@Test
@Transactional
public void testUpdateAddingConcept() {
    IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmRoleDto role = this.getHelper().createRole();
    // Create request for new identity-role
    IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
    dto.setIdentityContract(contract.getId());
    dto.setRole(role.getId());
    IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
    // We want to update created concept -> update validity
    createdRequestIdentityRole.setValidFrom(LocalDate.now().minusDays(1));
    createdRequestIdentityRole.setValidTill(LocalDate.now().plusDays(10));
    createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
    Assert.assertNotNull(createdRequestIdentityRole);
    // Request must been created
    Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
    Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
    Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
    IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Concepts are not empty now
    Assert.assertEquals(1, request.getConceptRoles().size());
    // Applicant must be ours identity
    Assert.assertEquals(contract.getIdentity(), request.getApplicant());
    IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
    Assert.assertEquals(contract.getId(), concept.getIdentityContract());
    Assert.assertEquals(role.getId(), concept.getRole());
    Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
    Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
    Assert.assertEquals(ConceptRoleRequestOperation.ADD, concept.getOperation());
    this.getHelper().executeRequest(request, false, true);
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(1, identityRoles.size());
    Assert.assertEquals(role.getId(), identityRoles.get(0).getRole());
    Assert.assertEquals(LocalDate.now().minusDays(1), identityRoles.get(0).getValidFrom());
    Assert.assertEquals(LocalDate.now().plusDays(10), identityRoles.get(0).getValidTill());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) 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) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with IdmRoleRequestFilter

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

the class IdmIdentityController method checkDeferredRequest.

/**
 * Check deferred result - using default implementation from long-polling-manager.
 *
 * @param deferredResult
 * @param subscriber
 */
private void checkDeferredRequest(DeferredResult<OperationResultDto> deferredResult, LongPollingSubscriber subscriber) {
    Assert.notNull(deferredResult, "Deferred result is required.");
    Assert.notNull(subscriber.getEntityId(), "Subscriber identifier is required.");
    IdmRoleRequestFilter filter = new IdmRoleRequestFilter();
    filter.setApplicantId(subscriber.getEntityId());
    longPollingManager.baseCheckDeferredResult(deferredResult, subscriber, filter, roleRequestService, true);
}
Also used : IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter)

Example 9 with IdmRoleRequestFilter

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

the class IdmRoleRequestController method startRequest.

@ResponseBody
@RequestMapping(value = "/{backendId}/start", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_UPDATE + "')")
@ApiOperation(value = "Start role request. Returns request doesn't contains concepts (from version 9.7.0!).", nickname = "startRoleRequest", response = IdmRoleRequestDto.class, tags = { IdmRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_UPDATE, description = "") }) })
public ResponseEntity<?> startRequest(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmRoleRequestDto requestDto = service.get(backendId, new IdmRoleRequestFilter(true), IdmBasePermission.READ);
    // Validate
    service.validate(requestDto);
    // Start request
    Map<String, Serializable> variables = new HashMap<>();
    variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.TRUE);
    RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, requestDto, variables);
    event.setPriority(PriorityType.HIGH);
    // 
    requestDto = service.startRequest(event);
    if (!requestDto.getState().isTerminatedState()) {
        throw new AcceptedException();
    }
    ResourceSupport resource = toResource(requestDto);
    ResponseEntity<ResourceSupport> response = new ResponseEntity<>(resource, HttpStatus.OK);
    return response;
}
Also used : Serializable(java.io.Serializable) ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) ResourceSupport(org.springframework.hateoas.ResourceSupport) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) 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 10 with IdmRoleRequestFilter

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

the class IdmRoleRequestController method get.

@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_READ + "')")
@ApiOperation(value = "Role request detail. Returns request doesn't contains concepts (from version 9.7.0!).", nickname = "getRoleRequest", response = IdmRoleRequestDto.class, tags = { IdmRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = "") }) })
public ResponseEntity<?> get(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    // 
    IdmRoleRequestFilter filter = new IdmRoleRequestFilter();
    filter.setIncludeApprovers(true);
    IdmRoleRequestDto requestDto = getService().get(backendId, filter, IdmBasePermission.READ);
    if (requestDto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    ResourceSupport resource = toResource(requestDto);
    if (resource == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    return new ResponseEntity<>(resource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ResourceSupport(org.springframework.hateoas.ResourceSupport) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) 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)

Aggregations

IdmRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter)27 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)21 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)19 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)16 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)15 Transactional (org.springframework.transaction.annotation.Transactional)15 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)13 IdmRequestIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto)11 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)10 Serializable (java.io.Serializable)8 UUID (java.util.UUID)8 RoleRequestState (eu.bcvsolutions.idm.core.api.domain.RoleRequestState)6 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)6 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)5 IdmRoleRequestService (eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService)5 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)5 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)5