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());
});
}
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());
}
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);
}
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;
}
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);
}
Aggregations