use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleAccountManagementBulkAction method processDto.
@Override
protected OperationResult processDto(IdmRoleDto dto) {
Assert.notNull(dto, "Role is required!");
Assert.notNull(dto.getId(), "Id of role is required!");
List<IdmIdentityRoleDto> successIdentityRoles = Lists.newArrayList();
Map<IdmIdentityRoleDto, Exception> failedIdentityRoles = Maps.newLinkedHashMap();
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(dto.getId());
// Load all identity roles for this roleId.
// Without check on IdentityRole UPDATE permissions. This operation is
// controlled by UPDATE right on this role!
List<IdmIdentityRoleDto> allIdentityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
allIdentityRoles.forEach(identityRole -> {
IdmIdentityDto identity = getEmbeddedIdentity(identityRole);
try {
// Execute account management for identity and exists assigned role
List<UUID> accountIds = accountManagementService.resolveUpdatedIdentityRoles(identity, identityRole);
// Execute provisioning
accountIds.forEach(accountId -> {
AccAccountDto account = accountService.get(accountId);
if (account != null) {
// Account could be null (was deleted).
LOG.debug("Call provisioning for identity [{}] and account [{}]", identity.getUsername(), account.getUid());
provisioningService.doProvisioning(account, identity);
}
});
successIdentityRoles.add(identityRole);
} catch (Exception ex) {
LOG.error("Call acm and provisioning for assigned role [{}], identity [{}] failed", identityRole.getId(), identity.getUsername(), ex);
//
failedIdentityRoles.put(identityRole, ex);
}
});
OperationResult operationResult = new OperationResult(OperationState.EXECUTED);
StringBuilder message = new StringBuilder();
if (!failedIdentityRoles.isEmpty()) {
operationResult = new OperationResult(OperationState.EXCEPTION);
//
message.append(MessageFormat.format("For the role [{0}], [{1}] of identity roles were FAILED acm or provisioning [{2}]. Assigned role UUIDs:\n", dto.getCode(), allIdentityRoles.size(), failedIdentityRoles.size()));
failedIdentityRoles.forEach((identityRole, ex) -> {
message.append('\n');
message.append(MessageFormat.format("[{0}], identity [{1}], exception:\n{2}", identityRole.getId(), getEmbeddedIdentity(identityRole).getUsername(), ex));
message.append('\n');
});
}
if (!successIdentityRoles.isEmpty()) {
message.append('\n');
message.append('\n');
message.append(MessageFormat.format("For the role [{0}], [{1}] of identity roles were call acm and provisioning [{2}]. Assigned role UUIDs:", dto.getCode(), allIdentityRoles.size(), successIdentityRoles.size()));
successIdentityRoles.forEach(identityRole -> {
message.append('\n');
message.append(MessageFormat.format("[{0}], identity [{1}]", identityRole.getId(), getEmbeddedIdentity(identityRole).getUsername()));
});
}
operationResult.setCause(message.toString());
return operationResult;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class ComplexHrProcessIntegrationTest method checkRoleAssigned.
// *********** Role checks **************
private void checkRoleAssigned(String contractId, Map<String, String> pattern) {
IdmIdentityContractFilter contractFilt = new IdmIdentityContractFilter();
// misused as unique contract identificer
contractFilt.setPosition(contractId);
List<IdmIdentityContractDto> contracts = identityContractService.find(contractFilt, null).getContent();
Assert.assertEquals(1, contracts.size());
IdmRoleDto roleDto = roleService.getByCode(pattern.get("code"));
Assert.assertNotNull(roleDto);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(contracts.get(0).getId());
identityRoleFilter.setRoleId(roleDto.getId());
List<IdmIdentityRoleDto> identityRoleDtos = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(1, identityRoleDtos.size());
IdmIdentityRoleDto identityRole = identityRoleDtos.get(0);
if (pattern.containsKey("directRole")) {
Assert.assertEquals(Boolean.parseBoolean(pattern.get("directRole")), identityRole.getDirectRole() == null);
}
if (pattern.containsKey("validTill")) {
String dateStr = pattern.get("validTill");
LocalDate date = dateStr == null ? null : LocalDate.parse(dateStr);
Assert.assertEquals(date, identityRole.getValidTill());
}
if (pattern.containsKey("validFrom")) {
String dateStr = pattern.get("validFrom");
LocalDate date = dateStr == null ? null : LocalDate.parse(dateStr);
Assert.assertEquals(date, identityRole.getValidFrom());
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleDeleteProcessor method checkWithoutForceDelete.
/**
* Check role can be deleted without force delete.
*
* @param role deleted role
* @throws ResultCodeException if not
*/
private void checkWithoutForceDelete(IdmRoleDto role) {
UUID roleId = role.getId();
// check assigned roles
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(roleId);
if (identityRoleService.count(identityRoleFilter) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_IDENTITY_ASSIGNED, ImmutableMap.of("role", role.getCode()));
}
//
// automatic roles by tree structure
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setRoleId(roleId);
if (roleTreeNodeService.count(filter) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_TREE_NODE, ImmutableMap.of("role", role.getCode()));
}
//
// related automatic roles by attribute
IdmAutomaticRoleFilter automaticRoleFilter = new IdmAutomaticRoleFilter();
automaticRoleFilter.setRoleId(roleId);
if (automaticRoleAttributeService.count(automaticRoleFilter) > 0) {
// some automatic role attribute has assigned this role
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_AUTOMATIC_ROLE_ASSIGNED, ImmutableMap.of("role", role.getCode()));
}
//
// business roles
IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
compositionFilter.setSubId(roleId);
if (roleCompositionService.count(compositionFilter) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_COMPOSITION, ImmutableMap.of("role", role.getCode()));
}
compositionFilter = new IdmRoleCompositionFilter();
compositionFilter.setSuperiorId(roleId);
if (roleCompositionService.count(compositionFilter) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_COMPOSITION, ImmutableMap.of("role", role.getCode()));
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleController method toFilter.
@Override
protected IdmIdentityRoleFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter(parameters);
// TODO: resolve codeable parameters automatically ...
filter.setIdentityId(getParameterConverter().toEntityUuid(parameters, IdmIdentityRoleFilter.PARAMETER_IDENTITY_ID, IdmIdentityDto.class));
filter.setRoleId(getParameterConverter().toEntityUuid(parameters, IdmIdentityRoleFilter.PARAMETER_ROLE_ID, IdmRoleDto.class));
//
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter 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