use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class ChangeIdentityPermissionTest method testAccessIsAddedForOwnerAndImplementerToSubprocesses.
@Test
public void testAccessIsAddedForOwnerAndImplementerToSubprocesses() {
// reset approvers
getHelper().setConfigurationValue(APPROVE_BY_USERMANAGER_ENABLE, false);
getHelper().setConfigurationValue(APPROVE_BY_SECURITY_ENABLE, false);
getHelper().setConfigurationValue(APPROVE_BY_MANAGER_ENABLE, false);
getHelper().setConfigurationValue(APPROVE_BY_HELPDESK_ENABLE, false);
// role with guarantees and critical 2 => approve by guarantee
IdmRoleDto role = new IdmRoleDto();
role.setCode(getHelper().createName());
// default by configuration
role.setPriority(2);
IdmRoleDto roleOne = roleService.save(role);
role = new IdmRoleDto();
role.setCode(getHelper().createName());
// default by configuration
role.setPriority(2);
IdmRoleDto roleTwo = roleService.save(role);
//
IdmIdentityDto implementer = getHelper().createIdentity();
IdmIdentityDto applicant = getHelper().createIdentity();
IdmIdentityContractDto applicantContract = getHelper().getPrimeContract(applicant);
IdmIdentityDto guaranteeOne = getHelper().createIdentity();
IdmIdentityDto guaranteeTwo = getHelper().createIdentity();
//
getHelper().createRoleGuarantee(roleOne, guaranteeOne);
getHelper().createRoleGuarantee(roleTwo, guaranteeTwo);
//
// login as implementer
loginAsAdmin(implementer.getUsername());
//
IdmRoleRequestDto request = createRoleRequest(applicant);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(roleOne, applicantContract, request);
conceptRoleRequestService.save(concept);
concept = createRoleConcept(roleTwo, applicantContract, request);
conceptRoleRequestService.save(concept);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
Assert.assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
IdmRequestIdentityRoleFilter requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeCandidates(true);
requestIdentityRoleFilter.setRoleRequestId(request.getId());
requestIdentityRoleFilter.setIdentityId(applicant.getId());
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
Assert.assertEquals(2, requestIdentityRoles.size());
Assert.assertTrue(requestIdentityRoles.stream().anyMatch(rir -> rir.getRole().equals(roleOne.getId()) && rir.getCandidates().size() == 1 && rir.getCandidates().iterator().next().getId().equals(guaranteeOne.getId())));
Assert.assertTrue(requestIdentityRoles.stream().anyMatch(rir -> rir.getRole().equals(roleTwo.getId()) && rir.getCandidates().size() == 1 && rir.getCandidates().iterator().next().getId().equals(guaranteeTwo.getId())));
//
// check applicant and implemented can read process instance
getHelper().login(implementer);
List<WorkflowProcessInstanceDto> processes = workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getContent();
Assert.assertEquals(3, processes.size());
getHelper().login(applicant);
Assert.assertEquals(3, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
getHelper().login(guaranteeOne);
Assert.assertEquals(1, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
getHelper().login(guaranteeTwo);
Assert.assertEquals(1, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
//
// test identity links are created (=> access added)
processes.forEach(process -> {
List<IdentityLink> links = runtimeService.getIdentityLinksForProcessInstance(process.getProcessInstanceId());
Assert.assertTrue(links.stream().anyMatch(l -> l.getUserId().equals(implementer.getId().toString()) && l.getType().equals(IdentityLinkType.STARTER)));
Assert.assertTrue(links.stream().anyMatch(l -> l.getUserId().equals(applicant.getId().toString()) && l.getType().equals(IdentityLinkType.OWNER)));
});
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestIdentityRoleService method compileIdentityRolesWithConcepts.
/**
* Find concepts for given identity-roles. If some exists (in given request),
* then will be altered for concept metadata (operation, EAVs)
*
* @param requestIdentityRoles
* @param identityRoles
* @param filter
* @param permission
*/
private void compileIdentityRolesWithConcepts(List<IdmRequestIdentityRoleDto> requestIdentityRoles, List<IdmIdentityRoleDto> identityRoles, IdmRequestIdentityRoleFilter filter, BasePermission... permission) {
// Convert identity-roles to Set of IDs.
Set<UUID> identityRoleIds = identityRoles.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toSet());
// Find concepts by identity-roles IDs.
IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
conceptFilter.setIdentityRoleIds(identityRoleIds);
conceptFilter.setRoleRequestId(filter.getRoleRequestId());
List<IdmConceptRoleRequestDto> conceptsForThisPage = conceptRoleService.find(conceptFilter, null, permission).getContent();
//
conceptsForThisPage.stream().filter(//
concept -> ConceptRoleRequestOperation.ADD != concept.getOperation()).forEach(concept -> {
//
IdmRequestIdentityRoleDto requestIdentityRoleWithConcept = //
requestIdentityRoles.stream().filter(requestIdentityRole -> requestIdentityRole.getIdentityRole() != null && requestIdentityRole.getIdentityRole().equals(concept.getIdentityRole()) && requestIdentityRole.getId().equals(requestIdentityRole.getIdentityRole())).findFirst().orElse(//
null);
if (requestIdentityRoleWithConcept != null) {
requestIdentityRoleWithConcept.setOperation(concept.getOperation());
requestIdentityRoleWithConcept.setId(concept.getId());
requestIdentityRoleWithConcept.setValidFrom(concept.getValidFrom());
requestIdentityRoleWithConcept.setValidTill(concept.getValidTill());
requestIdentityRoleWithConcept.setRoleRequest(concept.getRoleRequest());
IdmFormInstanceDto formInstanceDto;
// For updated identity-role replace EAVs from the concept
if (ConceptRoleRequestOperation.UPDATE == concept.getOperation()) {
// Check on change of values is made only on ended request! 'Original' value is current value and in audit it was confusing (only 'new' value is show now).
formInstanceDto = conceptRoleService.getRoleAttributeValues(concept, !concept.getState().isTerminatedState());
this.addEav(requestIdentityRoleWithConcept, formInstanceDto);
}
}
});
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestIdentityRoleService method find.
@Override
public Page<IdmRequestIdentityRoleDto> find(IdmRequestIdentityRoleFilter filter, Pageable pageable, BasePermission... permission) {
LOG.debug(MessageFormat.format("Find idm-request-identity-roles by filter [{0}] ", filter));
Assert.notNull(filter, "Filter is required.");
if (pageable == null) {
// Page is null, so we set page to max value
pageable = PageRequest.of(0, Integer.MAX_VALUE);
}
// If is true, then we want to return only concepts (not assigned roles)
boolean returnOnlyChanges = filter.isOnlyChanges();
List<IdmRequestIdentityRoleDto> results = new ArrayList<>();
long total = 0;
int countConcepts = 0;
if (filter.getRoleRequestId() != null) {
if (!returnOnlyChanges) {
// We want to load only new added roles
filter.setOperation(ConceptRoleRequestOperation.ADD);
// We don`t want load ADD concepts with filled identityRoleId (such concepts were already executed )
filter.setIdentityRoleIsNull(true);
}
Page<IdmConceptRoleRequestDto> conceptsPage = conceptRoleService.find(filter, pageable, permission);
results.addAll(this.conceptsToRequestIdentityRoles(conceptsPage.getContent(), filter));
total = conceptsPage.getTotalElements();
countConcepts = results.size();
}
int pageSizeForAssignedRoles = pageable.getPageSize() - countConcepts;
long numberOfPagesWithConcepts = total / pageable.getPageSize();
int pageNumberForAssignedRoles = pageable.getPageNumber() - ((int) numberOfPagesWithConcepts);
if (!returnOnlyChanges && filter.getIdentityId() != null && pageSizeForAssignedRoles > 0 && pageNumberForAssignedRoles >= 0) {
IdmIdentityRoleFilter identityRoleFilter = toIdentityRoleFilter(filter);
PageRequest pageableForAssignedRoles = PageRequest.of(pageNumberForAssignedRoles, pageable.getPageSize(), pageable.getSort());
// TODO: On a task detail approver must have permission to read identity-roles. If don't have it, then no concept are show.
// Maybe identity-roles should be load without permission here (permission by request).
Page<IdmIdentityRoleDto> identityRolesPage = identityRoleService.find(identityRoleFilter, pageableForAssignedRoles, permission);
List<IdmIdentityRoleDto> identityRoles = identityRolesPage.getContent();
// Transform identity-roles to request-identity-roles
results.addAll(this.identityRolesToRequestIdentityRoles(identityRoles, filter));
total = total + identityRolesPage.getTotalElements();
if (filter.getRoleRequestId() != null && !identityRoles.isEmpty()) {
compileIdentityRolesWithConcepts(results, identityRoles, filter, permission);
}
}
PageRequest pageableRequest = PageRequest.of(pageable.getPageNumber(), Math.max(results.size(), pageable.getPageSize()), pageable.getSort());
return new PageImpl<>(results, pageableRequest, total);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class ChangeIdentityPermissionTest method testFindCandidatesWithSubprocess.
@Test
public void testFindCandidatesWithSubprocess() {
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
getHelper().waitForResult(null, 1, 1);
// approve only by help desk
configurationService.setValue(APPROVE_BY_USERMANAGER_ENABLE, "false");
configurationService.setValue(APPROVE_BY_SECURITY_ENABLE, "false");
configurationService.setValue(APPROVE_BY_MANAGER_ENABLE, "false");
configurationService.setValue(APPROVE_BY_HELPDESK_ENABLE, "true");
loginAsAdmin();
// helpdesk role and identity
IdmRoleDto helpdeskRole = getHelper().createRole();
IdmIdentityDto helpdeskIdentity = getHelper().createIdentity();
// add role directly
getHelper().createIdentityRole(helpdeskIdentity, helpdeskRole);
configurationService.setValue(APPROVE_BY_HELPDESK_ROLE, helpdeskRole.getCode());
IdmIdentityDto identity = identityService.getByUsername(InitTestDataProcessor.TEST_USER_1);
IdmIdentityDto guarantee = identityService.getByUsername(InitTestDataProcessor.TEST_USER_2);
// Guarantee
int priority = 500;
IdmRoleDto adminRole = roleConfiguration.getAdminRole();
adminRole.setPriority(priority);
getHelper().createRoleGuarantee(adminRole, guarantee);
adminRole = roleService.save(adminRole);
configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_MANAGER_KEY);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity.getId());
IdmRoleRequestDto request = createRoleRequest(identity);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(adminRole, contract, request);
concept = conceptRoleRequestService.save(concept);
IdmRequestIdentityRoleFilter requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeCandidates(true);
requestIdentityRoleFilter.setRoleRequestId(request.getId());
requestIdentityRoleFilter.setIdentityId(identity.getId());
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoles.size());
IdmRequestIdentityRoleDto requestIdentityRoleDto = requestIdentityRoles.get(0);
assertNull(requestIdentityRoleDto.getCandidates());
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCreatedAfter(now);
taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
Set<IdmIdentityDto> candidates = workflowProcessInstanceService.getApproversForProcess(request.getWfProcessId());
assertEquals(1, candidates.size());
candidates = workflowProcessInstanceService.getApproversForSubprocess(request.getWfProcessId());
assertEquals(0, candidates.size());
requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeCandidates(true);
requestIdentityRoleFilter.setRoleRequestId(request.getId());
requestIdentityRoleFilter.setIdentityId(identity.getId());
requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoles.size());
requestIdentityRoleDto = requestIdentityRoles.get(0);
assertNull(requestIdentityRoleDto.getCandidates());
IdmRoleRequestFilter filter = new IdmRoleRequestFilter();
filter.setIncludeApprovers(true);
IdmRoleRequestDto requestDto = roleRequestService.get(request.getId(), filter);
assertEquals(1, requestDto.getApprovers().size());
// HELPDESK
loginAsAdmin(helpdeskIdentity.getUsername());
taskFilter.setCandidateOrAssigned(helpdeskIdentity.getUsername());
checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
filter.setIncludeApprovers(false);
requestDto = roleRequestService.get(request.getId(), filter);
assertNull(requestDto.getApprovers());
// Subprocess - approve by Manager
request = roleRequestService.get(request.getId());
loginAsAdmin(guarantee.getUsername());
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
concept = conceptRoleRequestService.get(concept.getId());
String conceptWf = concept.getWfProcessId();
assertNotNull(conceptWf);
assertNotNull(workflowProcessInstanceService.get(conceptWf));
candidates = workflowProcessInstanceService.getApproversForProcess(request.getWfProcessId());
assertEquals(1, candidates.size());
IdmIdentityDto approversFromProcess = candidates.stream().findFirst().get();
candidates = workflowProcessInstanceService.getApproversForSubprocess(request.getWfProcessId());
assertEquals(1, candidates.size());
IdmIdentityDto approversFromSubProcess = candidates.stream().findFirst().get();
assertEquals(approversFromProcess.getId(), approversFromSubProcess.getId());
requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeCandidates(true);
requestIdentityRoleFilter.setRoleRequestId(request.getId());
requestIdentityRoleFilter.setIdentityId(identity.getId());
requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoles.size());
requestIdentityRoleDto = requestIdentityRoles.get(0);
assertEquals(1, requestIdentityRoleDto.getCandidates().size());
requestIdentityRoleFilter.setIncludeCandidates(false);
requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoles.size());
requestIdentityRoleDto = requestIdentityRoles.get(0);
assertNull(requestIdentityRoleDto.getCandidates());
filter = new IdmRoleRequestFilter();
filter.setIncludeApprovers(true);
requestDto = roleRequestService.get(request.getId(), filter);
assertEquals(1, requestDto.getApprovers().size());
filter.setIncludeApprovers(false);
requestDto = roleRequestService.get(request.getId(), filter);
assertNull(requestDto.getApprovers());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestIdentityRoleService method save.
@Override
@Transactional
public IdmRequestIdentityRoleDto save(IdmRequestIdentityRoleDto dto, BasePermission... permission) {
LOG.debug(MessageFormat.format("Save idm-request-identity-role [{0}] ", dto));
Assert.notNull(dto, "DTO is required.");
// We don`t know if is given DTO identity-role or role-concept.
if (dto.getId() != null && dto.getId().equals(dto.getIdentityRole())) {
// Given DTO is identity-role -> create UPDATE concept
IdmIdentityRoleDto identityRole = identityRoleService.get(dto.getId());
Assert.notNull(identityRole, "Identity role is required.");
IdmIdentityContractDto identityContractDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.identityContract.getName(), IdmIdentityContractDto.class);
UUID requestId = dto.getRoleRequest();
IdmRoleRequestDto request = null;
if (requestId == null) {
request = this.createRequest(identityContractDto.getIdentity());
requestId = request.getId();
}
IdmConceptRoleRequestDto conceptRoleRequest = createConcept(identityRole, identityContractDto, requestId, identityRole.getRole(), identityContractDto.getValidFrom(), identityContractDto.getValidTill(), ConceptRoleRequestOperation.UPDATE);
conceptRoleRequest.setValidFrom(dto.getValidFrom());
conceptRoleRequest.setValidTill(dto.getValidTill());
conceptRoleRequest.setRoleSystem(dto.getRoleSystem());
conceptRoleRequest.setEavs(dto.getEavs());
// Create concept with EAVs
conceptRoleRequest = conceptRoleService.save(conceptRoleRequest, permission);
if (request != null) {
// Add request to concept. Will be used on the FE (prevent loading of request).
conceptRoleRequest.getEmbedded().put(IdmConceptRoleRequest_.roleRequest.getName(), request);
}
return this.conceptToRequestIdentityRole(conceptRoleRequest, null);
} else if (dto.getId() == null && dto.getIdentityRole() == null) {
// Given DTO does not have ID neither identity-role ID -> create ADD concept
Assert.notNull(dto.getIdentityContract(), "Contract is required.");
Set<UUID> roles = Sets.newHashSet();
if (dto.getRole() != null) {
roles.add(dto.getRole());
}
if (dto.getRoles() != null) {
roles.addAll(dto.getRoles());
}
Assert.notEmpty(roles, "Roles cannot be empty!");
IdmIdentityContractDto identityContractDto = identityContractService.get(dto.getIdentityContract());
UUID requestId = dto.getRoleRequest();
IdmRoleRequestDto request = null;
if (requestId == null) {
request = this.createRequest(identityContractDto.getIdentity());
requestId = request.getId();
}
List<IdmConceptRoleRequestDto> concepts = Lists.newArrayList();
UUID finalRequestId = requestId;
IdmRoleRequestDto finalRequest = request;
roles.forEach(role -> {
IdmConceptRoleRequestDto conceptRoleRequest = createConcept(null, identityContractDto, finalRequestId, role, dto.getValidFrom(), dto.getValidTill(), ConceptRoleRequestOperation.ADD);
conceptRoleRequest.setEavs(dto.getEavs());
conceptRoleRequest.setRoleSystem(dto.getRoleSystem());
// Create concept with EAVs
conceptRoleRequest = conceptRoleService.save(conceptRoleRequest);
if (finalRequest != null) {
// Add request to concept. Will be used on the FE (prevent loading of request).
conceptRoleRequest.getEmbedded().put(IdmConceptRoleRequest_.roleRequest.getName(), finalRequest);
}
concepts.add(conceptRoleRequest);
});
// Beware more then one concepts could be created, but only first will be returned!
return this.conceptToRequestIdentityRole(concepts.get(0), null);
} else {
// Try to find role-concept
IdmConceptRoleRequestDto roleConceptDto = conceptRoleService.get(dto.getId());
if (roleConceptDto != null) {
dto.setState(roleConceptDto.getState());
if (ConceptRoleRequestOperation.UPDATE == roleConceptDto.getOperation()) {
// Given DTO is concept -> update exists UPDATE concept
return this.conceptToRequestIdentityRole(conceptRoleService.save(dto, permission), null);
}
if (ConceptRoleRequestOperation.ADD == roleConceptDto.getOperation()) {
// Given DTO is concept -> update exists ADD concept
return this.conceptToRequestIdentityRole(conceptRoleService.save(dto, permission), null);
}
}
}
return null;
}
Aggregations