use of eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method createConcept.
/**
* Method create {@link IdmConceptRoleRequestDto}
*
* @param roleRequest
* @param contract
* @param roleId
* @param operation
* @return
*/
private IdmConceptRoleRequestDto createConcept(IdmRoleRequestDto roleRequest, IdmIdentityContractDto contract, UUID roleId, ConceptRoleRequestOperation operation) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setRoleRequest(roleRequest.getId());
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(roleId);
conceptRoleRequest.setOperation(operation);
return conceptRoleRequestService.save(conceptRoleRequest);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method removePermissionViaRoleRequestTest.
@Test
@Transactional()
public void removePermissionViaRoleRequestTest() {
this.addPermissionViaRoleRequestTest();
IdmIdentityDto testA = identityService.getByUsername(USER_TEST_A);
IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(testA.getId());
request.setExecuteImmediately(true);
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request = roleRequestService.save(request);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(testA.getId());
Assert.assertEquals(1, identityRoles.size());
IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
conceptA.setRoleRequest(request.getId());
conceptA.setRole(identityRoles.get(0).getRole());
conceptA.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptA.setIdentityContract(contractA.getId());
conceptA.setIdentityRole(identityRoles.get(0).getId());
conceptA = conceptRoleRequestService.save(conceptA);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, request.getState());
identityRoles = identityRoleService.findAllByIdentity(testA.getId());
Assert.assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method notRightForExecuteImmediatelyExceptionTest.
@Test(expected = RoleRequestException.class)
@Transactional()
public void notRightForExecuteImmediatelyExceptionTest() {
this.logout();
// Log as user without right for immediately execute role request (without approval)
Collection<GrantedAuthority> authorities = IdmAuthorityUtils.toAuthorities(moduleService.getAvailablePermissions()).stream().filter(authority -> {
return !CoreGroupPermission.ROLE_REQUEST_EXECUTE.equals(authority.getAuthority()) && !CoreGroupPermission.ROLE_REQUEST_ADMIN.equals(authority.getAuthority()) && !IdmGroupPermission.APP_ADMIN.equals(authority.getAuthority());
}).collect(Collectors.toList());
SecurityContextHolder.getContext().setAuthentication(new IdmJwtAuthentication(new IdmIdentityDto(USER_TEST_A), null, authorities, "test"));
IdmIdentityDto testA = identityService.getByUsername(USER_TEST_A);
IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(testA.getId());
request.setExecuteImmediately(true);
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request = roleRequestService.save(request);
Assert.assertEquals(RoleRequestState.CONCEPT, request.getState());
IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
conceptA.setRoleRequest(request.getId());
conceptA.setOperation(ConceptRoleRequestOperation.ADD);
conceptA.setRole(roleA.getId());
conceptA.setIdentityContract(contractA.getId());
conceptA = conceptRoleRequestService.save(conceptA);
Assert.assertEquals(RoleRequestState.CONCEPT, conceptA.getState());
// We expect exception state (we don`t have right for execute without approval)
roleRequestService.startRequestInternal(request.getId(), true);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method changePermissionViaRoleRequestTest.
@Test
@Transactional()
public void changePermissionViaRoleRequestTest() {
this.addPermissionViaRoleRequestTest();
IdmIdentityDto testA = identityService.getByUsername(USER_TEST_A);
IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(testA.getId());
request.setExecuteImmediately(true);
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request = roleRequestService.save(request);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(testA.getId());
Assert.assertEquals(1, identityRoles.size());
LocalDate validFrom = new LocalDate().minusDays(1);
IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
conceptA.setRoleRequest(request.getId());
conceptA.setRole(identityRoles.get(0).getRole());
conceptA.setOperation(ConceptRoleRequestOperation.UPDATE);
conceptA.setValidFrom(validFrom);
conceptA.setValidTill(null);
conceptA.setIdentityContract(contractA.getId());
conceptA.setIdentityRole(identityRoles.get(0).getId());
conceptA = conceptRoleRequestService.save(conceptA);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, request.getState());
identityRoles = identityRoleService.findAllByIdentity(testA.getId());
Assert.assertEquals(1, identityRoles.size());
Assert.assertEquals(validFrom, identityRoles.get(0).getValidFrom());
Assert.assertEquals(null, identityRoles.get(0).getValidTill());
Assert.assertEquals(contractA.getId(), identityRoles.get(0).getIdentityContract());
Assert.assertEquals(roleA.getId(), identityRoles.get(0).getRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto in project CzechIdMng by bcvsolutions.
the class SelfRoleRequestEvaluatorIntegrationTest method testCanReadSelfRoleRequest.
@Test
public void testCanReadSelfRoleRequest() {
IdmRoleDto role = roleService.getByCode(InitDemoData.DEFAULT_ROLE_NAME);
// prepare identity
IdmIdentityDto identity = helper.createIdentity();
// assign role request
IdmRoleRequestDto roleRequest = helper.assignRoles(helper.getPrimeContract(identity.getId()), role);
//
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
//
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();
}
}
Aggregations