use of eu.bcvsolutions.idm.acc.domain.AssignedRoleDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testConvertToAssignedRoleDto.
@Test
public void testConvertToAssignedRoleDto() {
IdmRoleDto role = helper.createRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role, LocalDate.now(), LocalDate.now().plusDays(1));
AssignedRoleDto result = IdentityProvisioningExecutor.convertToAssignedRoleDto(identityRole);
assertNotNull(result);
assertEquals(identityRole.getId(), result.getId());
assertEquals(identityRole.getValidFrom(), result.getValidFrom());
assertEquals(identityRole.getValidTill(), result.getValidTill());
assertEquals(identityRole.getIdentityContract(), result.getIdentityContract().getId());
assertEquals(identityRole.getRole(), result.getRole().getId());
assertEquals(identityRole.getDirectRole(), identityRole.getDirectRole() != null ? result.getDirectRole().getId() : null);
assertEquals(identityRole.getContractPosition(), identityRole.getContractPosition() != null ? result.getContractPosition().getId() : null);
assertEquals(identityRole.getRoleComposition(), identityRole.getRoleComposition() != null ? result.getRoleComposition().getId() : null);
assertEquals(identityRole.getAutomaticRole(), identityRole.getAutomaticRole() != null ? result.getRoleTreeNode().getId() : null);
}
use of eu.bcvsolutions.idm.acc.domain.AssignedRoleDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningExecutor method getAttributeValue.
@Override
protected Object getAttributeValue(String uid, IdmIdentityDto dto, AttributeMapping attribute, SysSystemDto system, MappingContext mappingContext) {
if (attribute instanceof SysRoleSystemAttributeDto) {
SysRoleSystemAttributeDto roleSystemAttributeDto = (SysRoleSystemAttributeDto) attribute;
if (roleSystemAttributeDto.isSkipValueIfExcluded() && (AttributeMappingStrategyType.MERGE == roleSystemAttributeDto.getStrategyType() || AttributeMappingStrategyType.AUTHORITATIVE_MERGE == roleSystemAttributeDto.getStrategyType())) {
// Get ID of the role
Assert.notNull(roleSystemAttributeDto.getRoleSystem(), "SysRoleSystem cannot be null!");
SysRoleSystemDto roleSystemDto = DtoUtils.getEmbedded(roleSystemAttributeDto, SysRoleSystemAttribute_.roleSystem.getName(), SysRoleSystemDto.class, (SysRoleSystemDto) null);
if (roleSystemDto == null) {
roleSystemDto = roleSystemService.get(roleSystemAttributeDto.getId());
}
UUID roleId = roleSystemDto.getRole();
Assert.notNull(roleId, "Role cannot be null!");
// Find count of NOT excluded contracts for this identity and role
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(dto.getId());
contractFilter.setExcluded(Boolean.FALSE);
contractFilter.setRoleId(roleId);
// If exists some not excluded contract, then value will be not skipped!
long countOfNotExcludedContracts = identityContractService.count(contractFilter);
if (countOfNotExcludedContracts == 0) {
contractFilter.setExcluded(Boolean.TRUE);
// For skip the value must exist at least one excluded contract
long countOfexcludedContracts = identityContractService.count(contractFilter);
if (countOfexcludedContracts >= 0) {
return null;
}
}
}
}
// identity-roles). That list will be input for that fields.
if (//
attribute != null && (//
ASSIGNED_ROLES_FIELD.equals(attribute.getIdmPropertyName()) || //
ASSIGNED_ROLES_FOR_SYSTEM_FIELD.equals(attribute.getIdmPropertyName()))) {
//
assertNotNull(dto.getId());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(dto.getId());
identityRoleFilter.setValid(Boolean.TRUE);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
List<IdmIdentityRoleDto> identityRolesToProcess;
if (ASSIGNED_ROLES_FOR_SYSTEM_FIELD.equals(attribute.getIdmPropertyName())) {
// For ASSIGNED_ROLES_FOR_SYSTEM_FIELD we will convert only identity-roles for
// that identity and given system
assertNotNull(system.getId());
List<IdmIdentityRoleDto> identityRolesForSystem = Lists.newArrayList();
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setIdentityId(dto.getId());
identityAccountFilter.setSystemId(system.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(identityAccountFilter, null).getContent();
// Filtering only identity-roles for that system
identityAccounts.forEach(identityAccount -> {
identityRolesForSystem.addAll(//
identityRoles.stream().filter(//
identityRole -> identityRole.getId().equals(identityAccount.getIdentityRole())).collect(//
Collectors.toList()));
});
identityRolesToProcess = identityRolesForSystem;
} else {
// For ASSIGNED_ROLES_FIELD we will convert all identity-roles for that identity
identityRolesToProcess = identityRoles;
}
List<AssignedRoleDto> assignedRoles = new ArrayList<>();
identityRolesToProcess.forEach(identityRole -> {
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
identityRole.getEavs().clear();
identityRole.getEavs().add(formInstanceDto);
// Convert identityRole to AssignedRoleDto
assignedRoles.add(IdentityProvisioningExecutor.convertToAssignedRoleDto(identityRole));
});
return attributeMappingService.transformValueToResource(uid, assignedRoles, attribute, dto);
}
// For user-type (projection) will be attribute value IdmFormProjectionDto.
if (attribute != null && dto != null && dto.getFormProjection() != null && IdmIdentity_.formProjection.getName().equals(attribute.getIdmPropertyName())) {
BaseDto projection = lookupService.lookupEmbeddedDto(dto, IdmIdentity_.formProjection);
return attributeMappingService.transformValueToResource(uid, projection, attribute, dto);
}
// Default transformation of Identity state enum to string
if (attribute != null && dto != null && IDENTITY_STATE_IDM_NAME.equals(attribute.getIdmPropertyName())) {
String state = dto.getState().toString();
return attributeMappingService.transformValueToResource(uid, state, attribute, dto);
}
return super.getAttributeValue(uid, dto, attribute, system, mappingContext);
}
use of eu.bcvsolutions.idm.acc.domain.AssignedRoleDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningExecutor method convertToAssignedRoleDto.
public static AssignedRoleDto convertToAssignedRoleDto(IdmIdentityRoleDto identityRole) {
if (identityRole == null) {
return null;
}
AssignedRoleDto dto = new AssignedRoleDto();
dto.setId(identityRole.getId());
dto.setExternalId(identityRole.getExternalId());
dto.setValidFrom(identityRole.getValidFrom());
dto.setValidTill(identityRole.getValidTill());
dto.setRole(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role, IdmRoleDto.class, null));
dto.setIdentityContract(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.identityContract, IdmIdentityContractDto.class, null));
dto.setContractPosition(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.contractPosition, IdmContractPositionDto.class, null));
dto.setDirectRole(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.directRole, IdmIdentityRoleDto.class, null));
dto.setRoleTreeNode(DtoUtils.getEmbedded(identityRole, IdmIdentityRoleDto.PROPERTY_ROLE_TREE_NODE, AbstractIdmAutomaticRoleDto.class, null));
dto.setRoleComposition(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.roleComposition, IdmRoleCompositionDto.class, null));
UUID definition = dto.getRole().getIdentityRoleAttributeDefinition();
if (definition != null) {
// Definition for role attributes exists
IdmFormInstanceDto formInstanceDto = //
identityRole.getEavs().stream().filter(//
formInstance -> definition.equals(formInstance.getFormDefinition().getId())).findFirst().orElse(null);
if (formInstanceDto != null) {
List<IdmFormValueDto> values = formInstanceDto.getValues();
// Search all attributes
values.stream().map(//
IdmFormValueDto::getFormAttribute).distinct().forEach(attribute -> {
List<IdmFormValueDto> formValues = // Search all values for one attribute
values.stream().filter(//
value -> attribute.equals(value.getFormAttribute())).collect(//
Collectors.toList());
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(formValues.get(0), IdmFormValue_.formAttribute, IdmFormAttributeDto.class);
dto.getAttributes().put(formAttributeDto.getCode(), //
formValues.stream().map(// Value is always list
IdmFormValueDto::getValue).collect(//
Collectors.toList()));
});
}
}
return dto;
}
Aggregations