use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultUniformPasswordManager method generateUniformPassword.
@Override
@Transactional
public GuardedString generateUniformPassword(UUID entityIdentifier, Class<? extends AbstractDto> entityType, UUID transactionId) {
Assert.notNull(transactionId, "Transaction cannot be null!");
Assert.notNull(entityIdentifier, "Entity identifier cannot be null!");
Assert.notNull(entityType, "Entity type cannot be null!");
IdmEntityStateDto entityStateDto = this.getEntityState(entityIdentifier, entityType, transactionId);
if (entityStateDto != null) {
GuardedString password = getPassword(entityStateDto);
if (password == null || password.getValue().length == 0) {
// TODO: how to generate password for all system policies.
password = new GuardedString(passwordPolicyService.generatePasswordByDefault());
confidentialStorage.saveGuardedString(entityStateDto, UNIFORM_PASSWORD_KEY, password);
}
// The uniform password was used, we need to mark it.
Map<String, Object> parameters = entityStateDto.getResult().getModel().getParameters();
HashMap<String, Object> newParameters = Maps.newHashMap(parameters);
newParameters.put(PASSWORD_USED, Boolean.TRUE);
entityStateDto.getResult().setModel(new DefaultResultModel(CoreResultCode.IDENTITY_UNIFORM_PASSWORD, newParameters));
entityStateManager.saveState(null, entityStateDto);
return password;
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class IdentityContractDeleteProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto contract = event.getContent();
UUID contractId = contract.getId();
Assert.notNull(contractId, "Contract must have a ID!");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
// check contract can be deleted - cannot be deleted, when is controlled by slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(contractId);
if (contractSliceService.find(sliceFilter, null).getTotalElements() > 0) {
// Cannot be enforced => contract cannot be deleted at all.
throw new ResultCodeException(CoreResultCode.CONTRACT_IS_CONTROLLED_CANNOT_BE_DELETED, ImmutableMap.of("contractId", contractId));
}
//
// Find all concepts and remove relation on contract
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setIdentityContractId(contractId);
conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("IdentityContract [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", contractId, concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityContract [{1}] was deleted (not from this role request)!", concept.getId(), contractId);
// Cancel concept and WF
concept = conceptRequestService.cancel(concept);
}
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
roleRequestService.save(request);
conceptRequestService.save(concept);
});
//
// delete referenced roles
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>();
identityRoleService.findAllByContract(contractId).forEach(identityRole -> {
// but automatic roles has to be removed in the same request.
if (identityRole.getDirectRole() == null) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
// ignore not found
conceptRoleRequest.setIdentityContract(contractId);
//
concepts.add(conceptRoleRequest);
}
});
if (forceDelete) {
// ~ async with force
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setApplicant(contract.getIdentity());
roleRequest.setConceptRoles(concepts);
//
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
requestEvent.setPriority(PriorityType.HIGH);
//
roleRequestService.startConcepts(requestEvent, event);
} else {
// ~ sync
roleRequestService.executeConceptsImmediate(contract.getIdentity(), concepts);
}
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contractId);
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// delete contract positions
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setIdentityContractId(contractId);
contractPositionService.find(positionFilter, null).forEach(position -> {
contractPositionService.delete(position);
});
//
// delete all contract's delegations
IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegatorContractId(contractId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
// delete identity contract
if (forceDelete) {
LOG.debug("Contract [{}] should be deleted by caller after all asynchronus processes are completed.", contractId);
//
// 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(contract, stateDeleted);
//
// set disabled
contract.setState(ContractState.DISABLED);
service.saveInternal(contract);
} else {
service.deleteInternal(contract);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class EntityStateSaveProcessor method process.
@Override
public EventResult<IdmEntityStateDto> process(EntityEvent<IdmEntityStateDto> event) {
IdmEntityStateDto entity = event.getContent();
entity = service.saveInternal(entity);
event.setContent(entity);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method createDirtyState.
/**
* Create new dirty state for contract slice
*
* @param slice
* @param parameters
* @return
*/
private IdmEntityStateDto createDirtyState(IdmContractSliceDto slice) {
Map<String, Object> transformedMarameters = new HashMap<String, Object>();
transformedMarameters.put("entityId", slice.getId());
DefaultResultModel resultModel = new DefaultResultModel(CoreResultCode.DIRTY_STATE, transformedMarameters);
IdmEntityStateDto dirtyState = new IdmEntityStateDto();
dirtyState.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(resultModel).build());
return entityStateManager.saveState(slice, dirtyState);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testAcceptedException.
@Test
public void testAcceptedException() {
try {
getHelper().enableAsynchronousProcessing();
//
IdmEntityEventDto event = new IdmEntityEventDto();
AcceptedContent content = new AcceptedContent();
content.setId(UUID.randomUUID());
event.setContent(content);
event.setOwnerId(content.getId());
event.setOwnerType(manager.getOwnerType(content));
event = manager.saveEvent(event);
manager.executeEvent(event);
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerId(content.getId());
filter.setStates(Lists.newArrayList(OperationState.EXECUTED));
//
// wait for execute event
getHelper().waitForResult(res -> {
return entityEventService.find(filter, PageRequest.of(0, 1)).getContent().isEmpty();
}, 500, 20);
//
event = manager.getEvent(event.getId());
Assert.assertEquals(OperationState.EXECUTED, event.getResult().getState());
Assert.assertEquals(CoreResultCode.ACCEPTED.name(), event.getResult().getCode());
//
// check state is executed too
IdmEntityStateFilter stateFilter = new IdmEntityStateFilter();
stateFilter.setEventId(event.getId());
List<IdmEntityStateDto> states = entityStateManager.findStates(content, null).getContent();
Assert.assertFalse(states.isEmpty());
Assert.assertTrue(states.stream().allMatch(s -> s.getResult().getState() == OperationState.EXECUTED && s.getResult().getCode().equals(CoreResultCode.ACCEPTED.name())));
} finally {
getHelper().disableAsynchronousProcessing();
}
}
Aggregations