use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testExecuteConcurentRoleRequests.
@Test
public void testExecuteConcurentRoleRequests() {
// prepare two requests with assigned roles
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
IdmRoleDto role = getHelper().createRole();
//
for (int i = 0; i < 10; i++) {
getHelper().createIdentityRole(contract, role);
}
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findValidRoles(identity.getId(), null).getContent();
Assert.assertEquals(10, assignedRoles.size());
//
IdmRoleRequestDto requestOne = createDeleteRoleRequest(contract, assignedRoles);
IdmRoleRequestDto requestTwo = createDeleteRoleRequest(contract, assignedRoles);
//
// execute request in two threads
FutureTask<?> taskOne = new FutureTask<Boolean>(() -> {
roleRequestService.startRequest(requestOne.getId(), false);
return true;
});
FutureTask<?> taskTwo = new FutureTask<Boolean>(() -> {
roleRequestService.startRequest(requestTwo.getId(), false);
return true;
});
executor.execute(taskOne);
executor.execute(taskTwo);
//
while (true) {
if (taskOne.isDone() && taskTwo.isDone()) {
break;
}
}
//
IdmRoleRequestDto executedRequestOne = roleRequestService.get(requestOne, new IdmRoleRequestFilter(true));
IdmRoleRequestDto executedRequestTwo = roleRequestService.get(requestTwo, new IdmRoleRequestFilter(true));
// One of requests ends with exception, but can be read => referential integrity is ok
Assert.assertTrue(executedRequestOne.getState().isTerminatedState());
Assert.assertTrue(executedRequestTwo.getState().isTerminatedState());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class DefaultLongPollingManagerTest method checkDeferredRequest.
private void checkDeferredRequest(DeferredResult<OperationResultDto> deferredResult, LongPollingSubscriber subscriber) {
Assert.notNull(deferredResult, "Deffered result is required.");
Assert.notNull(subscriber.getEntityId(), "Entity 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 IdentityDeleteProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto identity = event.getContent();
UUID identityId = identity.getId();
Assert.notNull(identityId, "Identity ID is required!");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
// delete contract slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setIdentity(identityId);
contractSliceService.find(sliceFilter, null).forEach(guarantee -> {
contractSliceService.delete(guarantee);
});
// delete contract slice guarantees
IdmContractSliceGuaranteeFilter sliceGuaranteeFilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteeFilter.setGuaranteeId(identityId);
contractSliceGuaranteeService.find(sliceGuaranteeFilter, null).forEach(guarantee -> {
contractSliceGuaranteeService.delete(guarantee);
});
//
// contracts
identityContractService.findAllByIdentity(identityId).forEach(identityContract -> {
// when identity is deleted, then HR processes has to be skipped (prevent to update deleted identity, when contract is removed)
Map<String, Serializable> properties = new HashMap<>();
properties.put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
// propagate force attribute
properties.put(PROPERTY_FORCE_DELETE, forceDelete);
// prepare event
IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.DELETE, identityContract, properties);
contractEvent.setPriority(PriorityType.HIGH);
//
identityContractService.publish(contractEvent);
});
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setGuaranteeId(identityId);
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// remove role guarantee
IdmRoleGuaranteeFilter roleGuaranteeFilter = new IdmRoleGuaranteeFilter();
roleGuaranteeFilter.setGuarantee(identityId);
roleGuaranteeService.find(roleGuaranteeFilter, null).forEach(roleGuarantee -> {
roleGuaranteeService.delete(roleGuarantee);
});
// remove password
passwordProcessor.deletePassword(identity);
// delete password history for identity
passwordHistoryService.deleteAllByIdentity(identityId);
// disable related tokens - tokens has to be disabled to prevent their usage (when tokens are deleted, then token is recreated)
tokenManager.disableTokens(identity);
//
// delete all identity's profiles
IdmProfileFilter profileFilter = new IdmProfileFilter();
profileFilter.setIdentityId(identityId);
profileService.find(profileFilter, null).forEach(profile -> {
profileService.delete(profile);
});
// remove all IdentityRoleValidRequest for this identity
List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityId(identityId);
identityRoleValidRequestService.deleteAll(validRequests);
//
// delete all identity's delegations - delegate
IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegateId(identityId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
//
// delete all identity's delegations - delegator
delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegatorId(identityId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
// deletes identity
if (forceDelete) {
LOG.debug("Identity [{}] should be deleted by caller after all asynchronus processes are completed.", identityId);
//
// dirty flag only - will be processed after asynchronous events ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(identity, stateDeleted);
//
// set disabled (automatically)
identity.setState(IdentityState.DISABLED);
service.saveInternal(identity);
} else {
// delete all role requests where is this identity applicant
IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
roleRequestFilter.setApplicantId(identityId);
roleRequestService.find(roleRequestFilter, null).forEach(request -> {
roleRequestService.delete(request);
});
//
service.deleteInternal(identity);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method deleteInternal.
@Override
@Transactional
public void deleteInternal(IdmRoleRequestDto dto) {
Assert.notNull(dto, "DTO is required.");
Assert.notNull(dto.getId(), "DTO identifier is required.");
// Find all request where is this request duplicated and remove relation
IdmRoleRequestFilter conceptRequestFilter = new IdmRoleRequestFilter();
conceptRequestFilter.setDuplicatedToRequestId(dto.getId());
this.find(conceptRequestFilter, null).getContent().forEach(duplicant -> {
duplicant.setDuplicatedToRequest(null);
if (RoleRequestState.DUPLICATED == duplicant.getState()) {
duplicant.setState(RoleRequestState.CONCEPT);
duplicant.setDuplicatedToRequest(null);
}
String message = MessageFormat.format("Duplicated request [{0}] was deleted!", dto.getId());
this.addToLog(duplicant, message);
this.save(duplicant);
});
// Stop connected WF process
cancelWF(dto);
// We have to delete all concepts for this request
IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
conceptFilter.setRoleRequestId(dto.getId());
//
conceptRoleRequestService.find(conceptFilter, null).getContent().forEach(concept -> conceptRoleRequestService.delete(concept));
super.deleteInternal(dto);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method executeRequest.
@Override
@Transactional
public IdmRoleRequestDto executeRequest(UUID requestId) {
// We can`t catch and log exception to request, because this transaction will be
// marked as to rollback.
// We can`t run this method in new transaction, because changes on request
// (state modified in WF for example) is in uncommited transaction!
//
// prepare request event
Assert.notNull(requestId, "Role request ID is required!");
IdmRoleRequestDto request = this.get(requestId, new IdmRoleRequestFilter(true));
Assert.notNull(request, "Role request is required!");
RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, request);
//
return this.executeRequestInternal(event);
}
Aggregations