use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testExecuteRoleRequestValueAsync.
@Test
public void testExecuteRoleRequestValueAsync() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
IdmRoleDto role = createRoleWithAttributes(true);
IdmFormDefinitionDto definition = formService.getDefinition(role.getIdentityRoleAttributeDefinition());
IdmFormAttributeDto ipAttributeDto = //
definition.getFormAttributes().stream().filter(//
attribute -> IP.equals(attribute.getCode())).findFirst().get();
//
try {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
// Add value
IdmFormValueDto formValue = new IdmFormValueDto(ipAttributeDto);
formValue.setStringValue(getHelper().createName());
formValue.setPersistentType(PersistentType.TEXT);
formValue.setFormAttribute(ipAttributeDto.getId());
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(definition);
formInstance.getValues().add(formValue);
// Create request
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(identity.getId());
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request.setExecuteImmediately(true);
request = roleRequestService.save(request);
// Create concept
IdmConceptRoleRequestDto conceptRole = new IdmConceptRoleRequestDto();
conceptRole.setIdentityContract(identityContact.getId());
conceptRole.setRole(role.getId());
conceptRole.setOperation(ConceptRoleRequestOperation.ADD);
conceptRole.setRoleRequest(request.getId());
conceptRole.getEavs().add(formInstance);
conceptRole = conceptRoleRequestService.save(conceptRole);
// Start request
Map<String, Serializable> variables = new HashMap<>();
variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.FALSE);
RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, request, variables);
event.setPriority(PriorityType.HIGH);
//
request = roleRequestService.startRequest(event);
UUID requestId = request.getId();
getHelper().waitForResult(res -> {
return roleRequestService.get(requestId).getState() != RoleRequestState.EXECUTED;
}, 500, 50);
IdmRoleRequestDto roleRequestDto = roleRequestService.get(request);
assertEquals(RoleRequestState.EXECUTED, roleRequestDto.getState());
conceptRole = conceptRoleRequestService.get(conceptRole.getId());
assertEquals(RoleRequestState.EXECUTED, conceptRole.getState());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(identityContact.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRoleDto);
assertNotNull(formInstanceDto);
List<IdmFormValueDto> values = formInstanceDto.getValues();
assertEquals(1, values.size());
assertEquals(formValue.getValue(), values.get(0).getValue());
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
// cleanup form definition
getHelper().deleteIdentity(identity.getId());
getHelper().deleteRole(role.getId());
formService.deleteDefinition(definition);
}
}
use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testClearIdOfAttributeValue.
@Test
public /**
* If EAV value of concept is send with ID (from FE), then have to be cleared for new concept!
*/
void testClearIdOfAttributeValue() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
IdmRoleDto role = createRoleWithAttributes(true);
IdmFormDefinitionDto definition = formService.getDefinition(role.getIdentityRoleAttributeDefinition());
IdmFormAttributeDto ipAttributeDto = //
definition.getFormAttributes().stream().filter(//
attribute -> IP.equals(attribute.getCode())).findFirst().get();
//
// Add value
String valueOne = getHelper().createName();
IdmFormValueDto formValue = new IdmFormValueDto(ipAttributeDto);
// Set ID = simulation sending ID from FE.
formValue.setId(UUID.randomUUID());
formValue.setStringValue(valueOne);
formValue.setPersistentType(PersistentType.TEXT);
formValue.setFormAttribute(ipAttributeDto.getId());
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(definition);
formInstance.getValues().add(formValue);
// Create requestTwo
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(identity.getId());
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request.setExecuteImmediately(true);
request = roleRequestService.save(request);
// Create concept
IdmConceptRoleRequestDto conceptRole = new IdmConceptRoleRequestDto();
conceptRole.setIdentityContract(identityContact.getId());
conceptRole.setRole(role.getId());
conceptRole.setOperation(ConceptRoleRequestOperation.ADD);
conceptRole.setRoleRequest(request.getId());
conceptRole.getEavs().add(formInstance);
conceptRole = conceptRoleRequestService.save(conceptRole);
// Start requestOne
Map<String, Serializable> variables = new HashMap<>();
variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.FALSE);
RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, request, variables);
event.setPriority(PriorityType.HIGH);
//
request = roleRequestService.startRequest(event);
IdmRoleRequestDto roleRequestDtoOne = roleRequestService.get(request);
assertEquals(RoleRequestState.EXECUTED, roleRequestDtoOne.getState());
conceptRole = conceptRoleRequestService.get(conceptRole.getId());
assertEquals(RoleRequestState.EXECUTED, conceptRole.getState());
IdmRequestIdentityRoleFilter requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeEav(true);
requestIdentityRoleFilter.setOnlyChanges(true);
requestIdentityRoleFilter.setIdentityId(identity.getId());
requestIdentityRoleFilter.setRoleRequestId(roleRequestDtoOne.getId());
List<IdmRequestIdentityRoleDto> requestIdentityRoleDtos = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoleDtos.size());
IdmRequestIdentityRoleDto requestIdentityRoleDto = requestIdentityRoleDtos.get(0);
assertEquals(1, requestIdentityRoleDto.getEavs().size());
assertEquals(1, requestIdentityRoleDto.getEavs().get(0).getValues().size());
assertEquals(valueOne, requestIdentityRoleDto.getEavs().get(0).getValues().get(0).getValue());
// Create second request for same role with EAV value with same ID.
String valueTwo = getHelper().createName();
IdmFormValueDto formValueTwo = new IdmFormValueDto(ipAttributeDto);
// Set ID = simulation sending same ID from FE.
formValueTwo.setId(formValue.getId());
formValueTwo.setStringValue(valueTwo);
formValueTwo.setPersistentType(PersistentType.TEXT);
formValueTwo.setFormAttribute(ipAttributeDto.getId());
IdmFormInstanceDto formInstanceTwo = new IdmFormInstanceDto();
formInstanceTwo.setFormDefinition(definition);
formInstanceTwo.getValues().add(formValueTwo);
// Create requestTwo
IdmRoleRequestDto requestTwo = new IdmRoleRequestDto();
requestTwo.setApplicant(identity.getId());
requestTwo.setRequestedByType(RoleRequestedByType.MANUALLY);
requestTwo.setExecuteImmediately(true);
requestTwo = roleRequestService.save(requestTwo);
// Create concept
IdmConceptRoleRequestDto conceptRoleTwo = new IdmConceptRoleRequestDto();
conceptRoleTwo.setIdentityContract(identityContact.getId());
conceptRoleTwo.setRole(role.getId());
conceptRoleTwo.setOperation(ConceptRoleRequestOperation.ADD);
conceptRoleTwo.setRoleRequest(requestTwo.getId());
conceptRoleTwo.getEavs().add(formInstanceTwo);
conceptRoleTwo = conceptRoleRequestService.save(conceptRoleTwo);
// Start requestTwo
variables = new HashMap<>();
variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.FALSE);
event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, requestTwo, variables);
event.setPriority(PriorityType.HIGH);
//
requestTwo = roleRequestService.startRequest(event);
IdmRoleRequestDto roleRequestDtoTwo = roleRequestService.get(requestTwo);
assertEquals(RoleRequestState.EXECUTED, roleRequestDtoTwo.getState());
conceptRoleTwo = conceptRoleRequestService.get(conceptRoleTwo.getId());
assertEquals(RoleRequestState.EXECUTED, conceptRoleTwo.getState());
requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeEav(true);
requestIdentityRoleFilter.setOnlyChanges(true);
requestIdentityRoleFilter.setIdentityId(identity.getId());
requestIdentityRoleFilter.setRoleRequestId(roleRequestDtoTwo.getId());
requestIdentityRoleDtos = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoleDtos.size());
requestIdentityRoleDto = requestIdentityRoleDtos.get(0);
assertEquals(1, requestIdentityRoleDto.getEavs().size());
assertEquals(1, requestIdentityRoleDto.getEavs().get(0).getValues().size());
assertEquals(valueTwo, requestIdentityRoleDto.getEavs().get(0).getValues().get(0).getValue());
// Check again requestOne!
requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeEav(true);
requestIdentityRoleFilter.setIdentityId(identity.getId());
requestIdentityRoleFilter.setOnlyChanges(true);
requestIdentityRoleFilter.setRoleRequestId(roleRequestDtoOne.getId());
requestIdentityRoleDtos = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoleDtos.size());
requestIdentityRoleDto = requestIdentityRoleDtos.get(0);
assertEquals(1, requestIdentityRoleDto.getEavs().size());
assertEquals(1, requestIdentityRoleDto.getEavs().get(0).getValues().size());
assertEquals(valueOne, requestIdentityRoleDto.getEavs().get(0).getValues().get(0).getValue());
// cleanup form definition
getHelper().deleteIdentity(identity.getId());
getHelper().deleteRole(role.getId());
formService.deleteDefinition(definition);
}
use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.
the class IdentityAutomaticRoleProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
//
IdmIdentityDto identity = event.getContent();
UUID identityId = identity.getId();
//
// both by default
AutomaticRoleAttributeRuleType type = null;
if (identity.getEavs().isEmpty()) {
// identity is saved together with eavs.
type = AutomaticRoleAttributeRuleType.IDENTITY;
}
if (CoreEventType.EAV_SAVE.name().equals(event.getParentType())) {
type = AutomaticRoleAttributeRuleType.IDENTITY_EAV;
}
//
List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
//
for (IdmIdentityContractDto contract : identityContractService.findAllByIdentity(identityId)) {
UUID contractId = contract.getId();
Set<AbstractIdmAutomaticRoleDto> allNewPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(true, type, contractId);
Set<AbstractIdmAutomaticRoleDto> allNotPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(false, type, contractId);
// Iterate over newly passed
for (AbstractIdmAutomaticRoleDto autoRole : allNewPassedAutomaticRoleForContract) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contract.getId());
concept.setValidFrom(contract.getValidFrom());
concept.setValidTill(contract.getValidTill());
concept.setRole(autoRole.getRole());
concept.setAutomaticRole(autoRole.getId());
concept.setOperation(ConceptRoleRequestOperation.ADD);
concepts.add(concept);
}
// Iterate over newly not passed
for (AbstractIdmAutomaticRoleDto autoRole : allNotPassedAutomaticRoleForContract) {
//
// Find all identity roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setAutomaticRoleId(autoRole.getId());
filter.setIdentityContractId(contractId);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
//
for (IdmIdentityRoleDto identityRole : identityRoles) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contractId);
concept.setRole(autoRole.getRole());
concept.setAutomaticRole(autoRole.getId());
concept.setIdentityRole(identityRole.getId());
concept.setOperation(ConceptRoleRequestOperation.REMOVE);
concepts.add(concept);
}
}
//
}
// Execute concepts
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(identityId);
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), event);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.
the class IdentityContractExpirationTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmIdentityContractDto contract) {
LOG.info("Remove roles by expired identity contract [{}]. Contract ended for expiration less than [{}]", contract.getId(), expiration);
//
try {
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityContractId(contract.getId());
filter.setDirectRole(Boolean.TRUE);
// remove all referenced roles (automatic roles are included)
List<IdmIdentityRoleDto> expiredRoles = identityRoleService.find(filter, null).getContent();
if (expiredRoles.isEmpty()) {
// nothing to do
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
//
UUID identityId = contract.getIdentity();
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setState(RoleRequestState.CONCEPT);
// without approval
roleRequest.setExecuteImmediately(true);
roleRequest.setApplicant(identityId);
roleRequest.setRequestedByType(RoleRequestedByType.AUTOMATICALLY);
roleRequest = roleRequestService.save(roleRequest);
//
for (IdmIdentityRoleDto identityRole : expiredRoles) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setRoleRequest(roleRequest.getId());
conceptRoleRequestService.save(conceptRoleRequest);
}
//
// start event with skip check authorities
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
requestEvent.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
// prevent to start asynchronous event before previous update event is completed.
requestEvent.setSuperOwnerId(identityId);
//
roleRequestService.startRequestInternal(requestEvent);
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
LOG.error("Removing roles of expired contract [{}] failed", contract.getId(), ex);
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build());
}
}
use of eu.bcvsolutions.idm.core.model.event.RoleRequestEvent in project CzechIdMng by bcvsolutions.
the class AddNewRoleCompositionTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmRoleDto superiorRole) {
try {
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleId(superiorRole.getId());
//
identityRoleService.find(filter, null).forEach(identityRole -> {
IdmIdentityContractDto contract = lookupService.lookupEmbeddedDto(identityRole, IdmIdentityRole_.identityContract);
// find direct sub roles - other sub roles will be processed by role request automatically
IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
compositionFilter.setSuperiorId(identityRole.getRole());
compositionFilter.setId(roleCompositionId);
//
List<IdmConceptRoleRequestDto> concepts = roleCompositionService.find(compositionFilter, null).stream().map(subRole -> {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
// from concept
conceptRoleRequest.setValidFrom(identityRole.getValidFrom());
conceptRoleRequest.setValidTill(identityRole.getValidTill());
conceptRoleRequest.setIdentityContract(identityRole.getIdentityContract());
conceptRoleRequest.setContractPosition(identityRole.getContractPosition());
// from assigned (~changed) sub role
conceptRoleRequest.setRole(subRole.getSub());
conceptRoleRequest.setDirectRole(identityRole.getId());
conceptRoleRequest.setRoleComposition(subRole.getId());
//
return conceptRoleRequest;
}).collect(Collectors.toList());
//
if (!concepts.isEmpty()) {
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(contract.getIdentity());
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
}
});
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.ROLE_COMPOSITION_ASSIGN_ROLE_FAILED, ImmutableMap.of("role", superiorRole.getCode()))).setCause(ex).build());
}
}
Aggregations