use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleCompositionService method removeSubRoles.
@Override
@Transactional
public void removeSubRoles(EntityEvent<IdmIdentityRoleDto> event, BasePermission... permission) {
Assert.notNull(event, "Event is required.");
IdmIdentityRoleDto directRole = event.getContent();
Assert.notNull(directRole, "Direct role is required.");
Assert.notNull(directRole.getId(), "Direct role identifier is required.");
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setDirectRoleId(directRole.getId());
//
identityRoleService.find(filter, null).forEach(subIdentityRole -> {
IdentityRoleEvent subEvent = new IdentityRoleEvent(IdentityRoleEventType.DELETE, subIdentityRole);
//
identityRoleService.publish(subEvent, event, permission);
// Notes identity-accounts to ACM
notingIdentityAccountForDelayedAcm(event, subEvent);
});
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityRoleService method siemLog.
/**
* Method provides specific logic for role assignment siem logging.
*/
@Override
protected void siemLog(EntityEvent<IdmIdentityRoleDto> event, String status, String detail) {
if (event == null) {
return;
}
IdmIdentityRoleDto dto = event.getContent();
String operationType = event.getType().name();
String action = siemLoggerManager.buildAction(SiemLoggerManager.ROLE_ASSIGNMENT_LEVEL_KEY, operationType);
if (siemLoggerManager.skipLogging(action)) {
return;
}
IdmIdentityContractDto contractDto = lookupService.lookupEmbeddedDto(dto, IdmIdentityRole_.identityContract.getName());
IdmRoleDto subjectDto = lookupService.lookupEmbeddedDto(dto, IdmIdentityRole_.role.getName());
IdmIdentityDto targetDto = lookupService.lookupEmbeddedDto(contractDto, IdmIdentityContract_.identity.getName());
String transactionUuid = Objects.toString(dto.getTransactionId(), "");
siemLog(action, status, targetDto, subjectDto, transactionUuid, detail);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method removePermissionViaRoleRequestTest.
@Test
@Transactional
public void removePermissionViaRoleRequestTest() {
this.addPermissionViaRoleRequestTest();
IdmIdentityDto testA = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleA = getHelper().createRole(100);
IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
getHelper().createIdentityRole(testA, roleA);
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);
getHelper().startRequestInternal(request, true, 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.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesWithParameterAttachment.
@Test
@Transactional
public void testCopyRolesWithParameterAttachment() {
long countBefore = attachmentManager.find(null).getTotalElements();
String attributeCode = "attr-" + System.currentTimeMillis();
// Prepare identity, role and parameters
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = getHelper().createRole();
IdmFormAttributeDto attribute = new IdmFormAttributeDto(attributeCode);
attribute.setPersistentType(PersistentType.ATTACHMENT);
IdmFormDefinitionDto definition = formService.createDefinition(IdmIdentityRole.class, FormService.DEFAULT_DEFINITION_CODE, ImmutableList.of(attribute));
role.setIdentityRoleAttributeDefinition(definition.getId());
role = roleService.save(role);
final IdmRoleDto roleFinal = role;
definition.getFormAttributes().forEach(attr -> {
roleFormAttributeService.addAttributeToSubdefintion(roleFinal, attr);
});
attribute = formService.getAttribute(definition, attributeCode);
assertNotNull(attribute);
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
IdmIdentityRoleDto identityRoleDto = this.getHelper().createIdentityRole(identityContact, role);
// Add attachment to identity role
String originalContent = "test-content-" + System.currentTimeMillis();
IdmAttachmentDto attachment = prepareAttachment(originalContent);
attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachment = attachmentManager.saveAttachment(null, attachment);
List<IdmFormInstanceDto> eavs = identityRoleDto.getEavs();
IdmFormInstanceDto formInstanceDto = eavs.get(0);
IdmFormValueDto newValue = new IdmFormValueDto(attribute);
newValue.setShortTextValue(attachment.getName());
newValue.setUuidValue(attachment.getId());
formInstanceDto.setValues(Lists.newArrayList(newValue));
identityRoleDto.setEavs(Lists.newArrayList(formInstanceDto));
identityRoleDto = identityRoleService.save(identityRoleDto);
IdmFormInstanceDto identityRoleValues = identityRoleService.getRoleAttributeValues(identityRoleDto);
identityRoleValues = identityRoleService.getRoleAttributeValues(identityRoleDto);
List<IdmFormValueDto> values = identityRoleValues.getValues();
assertEquals(1, values.size());
IdmFormValueDto originalValue = values.get(0);
// Assign roles by identity
IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityContractDto identityContractDto = getHelper().createContract(identityDto);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(identityContractDto);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(identityContractDto.getId());
requestByIdentityDto.setRoleRequest(createdRequest.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setCopyRoleParameters(true);
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(1, concepts.size());
IdmConceptRoleRequestDto concept = concepts.stream().filter(cntp -> {
return cntp.getRole().equals(roleFinal.getId());
}).findAny().orElse(null);
assertNotNull(concept);
IdmFormInstanceDto formInstance = conceptRoleRequestService.getRoleAttributeValues(concept, false);
values = formInstance.getValues();
assertEquals(1, values.size());
IdmFormValueDto copyValue = values.get(0);
assertEquals(originalValue.getPersistentType(), copyValue.getPersistentType());
assertEquals(originalValue.getFormAttribute(), copyValue.getFormAttribute());
assertNotEquals(originalValue.getUuidValue(), copyValue.getUuidValue());
assertEquals(countBefore + 2, attachmentManager.find(null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto 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);
}
}
Aggregations