use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method compileAtributeForStrategy.
/**
* Compile given attribute for strategy
*
* @param strategy
* @param defaultAttribute
* @param overloadingAttributes
*
* @return
*/
protected List<AttributeMapping> compileAtributeForStrategy(AttributeMappingStrategyType strategy, AttributeMapping defaultAttribute, List<SysRoleSystemAttributeDto> overloadingAttributes) {
List<AttributeMapping> finalAttributes = new ArrayList<>();
List<SysRoleSystemAttributeDto> attributesOrdered = overloadingAttributes.stream().filter(roleSystemAttribute -> {
// Search attribute override same schema attribute
SysSystemAttributeMappingDto attributeMapping = DtoUtils.getEmbedded(roleSystemAttribute, SysRoleSystemAttribute_.systemAttributeMapping.getName(), SysSystemAttributeMappingDto.class);
return attributeMapping.equals(defaultAttribute);
}).sorted((att1, att2) -> {
// Sort attributes by role priority
IdmRoleDto role1 = this.getRole(att1);
IdmRoleDto role2 = this.getRole(att2);
return Integer.compare(role2.getPriority(), role1.getPriority());
}).collect(Collectors.toList());
// We have some overloaded attributes
if (!attributesOrdered.isEmpty()) {
List<SysRoleSystemAttributeDto> attributesOrderedGivenStrategy = attributesOrdered.stream().filter(attribute -> {
return strategy == attribute.getStrategyType();
}).collect(Collectors.toList());
// We do not have overloaded attributes for given strategy
if (attributesOrderedGivenStrategy.isEmpty()) {
return finalAttributes;
}
// First element have role with max priority
IdmRoleDto roleForSetMaxPriority = this.getRole((AttributeMapping) attributesOrderedGivenStrategy.get(0));
int maxPriority = roleForSetMaxPriority.getPriority();
// We will search for attribute with highest priority (and role
// name)
Optional<SysRoleSystemAttributeDto> highestPriorityAttributeOptional = attributesOrderedGivenStrategy.stream().filter(attribute -> {
IdmRoleDto roleDto = this.getRole(attribute);
// Filter attributes by max priority
return maxPriority == roleDto.getPriority();
}).sorted((att1, att2) -> {
// Second filtering, if we have same priority, then
// we will sort by role name
IdmRoleDto roleDto1 = this.getRole(att1);
IdmRoleDto roleDto2 = this.getRole(att2);
//
return roleDto2.getCode().compareTo(roleDto1.getCode());
}).findFirst();
if (highestPriorityAttributeOptional.isPresent()) {
SysRoleSystemAttributeDto highestPriorityAttribute = highestPriorityAttributeOptional.get();
// overloaded attributes
if (strategy == AttributeMappingStrategyType.AUTHORITATIVE_MERGE || strategy == AttributeMappingStrategyType.MERGE) {
attributesOrderedGivenStrategy.forEach(attribute -> {
// Disabled attribute will be skipped
if (!attribute.isDisabledDefaultAttribute()) {
// Default values (values from schema attribute
// handling)
attribute.setSchemaAttribute(defaultAttribute.getSchemaAttribute());
attribute.setTransformFromResourceScript(defaultAttribute.getTransformFromResourceScript());
// Common properties (for MERGE strategy) will be
// set from MERGE attribute with highest priority
attribute.setSendAlways(highestPriorityAttribute.isSendAlways());
attribute.setSendOnlyIfNotNull(highestPriorityAttribute.isSendOnlyIfNotNull());
// Add modified attribute to final list
finalAttributes.add(attribute);
}
});
return finalAttributes;
}
// We will search for disabled overloaded attribute
Optional<SysRoleSystemAttributeDto> disabledOverloadedAttOptional = attributesOrderedGivenStrategy.stream().filter(attribute -> {
// Filter attributes by max priority
IdmRoleDto roleDto = this.getRole(attribute);
return maxPriority == roleDto.getPriority();
}).filter(attribute -> {
// overloaded attribute
return attribute.isDisabledDefaultAttribute();
}).findFirst();
if (disabledOverloadedAttOptional.isPresent()) {
// priority
return finalAttributes;
}
// Disabled attribute will be skipped
if (!highestPriorityAttribute.isDisabledDefaultAttribute()) {
// Default values (values from schema attribute handling)
highestPriorityAttribute.setSchemaAttribute(defaultAttribute.getSchemaAttribute());
highestPriorityAttribute.setCached(defaultAttribute.isCached());
highestPriorityAttribute.setTransformFromResourceScript(defaultAttribute.getTransformFromResourceScript());
// Add modified attribute to final list
finalAttributes.add(highestPriorityAttribute);
return finalAttributes;
}
}
}
if (!defaultAttribute.isDisabledAttribute() && strategy == defaultAttribute.getStrategyType()) {
finalAttributes.add(defaultAttribute);
}
return finalAttributes;
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method resolveAdditionalPasswordChangeAttributes.
private List<AttributeMapping> resolveAdditionalPasswordChangeAttributes(AccAccountDto account, DTO dto, SysSystemDto system, SystemEntityType entityType) {
SysSystemMappingDto mapping = getMapping(system, entityType);
if (mapping == null) {
return Collections.<AttributeMapping>emptyList();
}
//
// All additional mapped attributes from system, witch has to be send on
// password change
SysSystemAttributeMappingFilter attributeFilter = new SysSystemAttributeMappingFilter();
attributeFilter.setSystemMappingId(mapping.getId());
attributeFilter.setSendOnPasswordChange(Boolean.TRUE);
// we want only active attributes
attributeFilter.setDisabledAttribute(Boolean.FALSE);
List<? extends AttributeMapping> additionalPasswordChangeAttributes = attributeMappingService.find(attributeFilter, null).getContent();
//
// All role system attributes (overloading) for this uid and same system
List<SysRoleSystemAttributeDto> roleSystemAttributesAll = findOverloadingAttributes(dto, system, account, entityType);
//
// Final list of attributes use for provisioning
List<AttributeMapping> results = compileAttributes(additionalPasswordChangeAttributes, roleSystemAttributesAll, entityType);
//
return results == null ? Collections.<AttributeMapping>emptyList() : results;
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class CrossDomainAdUserConnectorTypeTest method createOverriddenLdapGroupAttribute.
private void createOverriddenLdapGroupAttribute(SysSystemAttributeMappingDto ldapGroupsAttribute, SysRoleSystemDto roleSystem, String script) {
// Creates overridden ldapGroup merge attribute.
SysRoleSystemAttributeDto ldapGroupsRoleSystemAttribute = new SysRoleSystemAttributeDto();
ldapGroupsRoleSystemAttribute.setSystemAttributeMapping(ldapGroupsAttribute.getId());
ldapGroupsRoleSystemAttribute.setRoleSystem(roleSystem.getId());
ldapGroupsRoleSystemAttribute.setEntityAttribute(ldapGroupsAttribute.isEntityAttribute());
ldapGroupsRoleSystemAttribute.setSchemaAttribute(ldapGroupsAttribute.getSchemaAttribute());
ldapGroupsRoleSystemAttribute.setExtendedAttribute(ldapGroupsAttribute.isExtendedAttribute());
ldapGroupsRoleSystemAttribute.setName(ldapGroupsAttribute.getName());
ldapGroupsRoleSystemAttribute.setStrategyType(ldapGroupsAttribute.getStrategyType());
ldapGroupsRoleSystemAttribute.setIdmPropertyName(ldapGroupsAttribute.getIdmPropertyName());
ldapGroupsRoleSystemAttribute.setUid(ldapGroupsAttribute.isUid());
ldapGroupsRoleSystemAttribute.setTransformScript(script);
roleSystemAttributeService.save(ldapGroupsRoleSystemAttribute);
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class IdentityAccountManagementTest method initData.
private void initData() {
// create test system
SysSystemDto system = helper.createTestResourceSystem(true, SYSTEM_NAME);
//
// Create test identity for provisioning test
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(IDENTITY_USERNAME);
identity.setFirstName(IDENTITY_USERNAME);
identity.setLastName(IDENTITY_USERNAME);
identity.setEmail(IDENTITY_EMAIL);
identity = identityService.save(identity);
// Create mapped attributes to schema
SysSystemMappingDto systemMapping = helper.getDefaultMapping(system);
SysSystemAttributeMappingDto attributeHandlingLastName = schemaAttributeHandlingService.findBySystemMappingAndName(systemMapping.getId(), helper.getSchemaColumnName(TestHelper.ATTRIBUTE_MAPPING_LASTNAME));
SysSystemAttributeMappingDto attributeHandlingFirstName = schemaAttributeHandlingService.findBySystemMappingAndName(systemMapping.getId(), helper.getSchemaColumnName(TestHelper.ATTRIBUTE_MAPPING_FIRSTNAME));
SysSystemAttributeMappingDto attributeHandlingUserName = schemaAttributeHandlingService.findBySystemMappingAndName(systemMapping.getId(), TestHelper.ATTRIBUTE_MAPPING_NAME);
// username is transformed
attributeHandlingUserName.setTransformToResourceScript("return \"" + "x" + IDENTITY_USERNAME + "\";");
attributeHandlingUserName = schemaAttributeHandlingService.save(attributeHandlingUserName);
/*
* Create role with link on system (default)
*/
IdmRoleDto roleDefault = new IdmRoleDto();
roleDefault.setCode(ROLE_DEFAULT);
roleDefault = roleService.save(roleDefault);
SysRoleSystemDto roleSystemDefault = new SysRoleSystemDto();
roleSystemDefault.setRole(roleDefault.getId());
roleSystemDefault.setSystem(system.getId());
roleSystemDefault.setSystemMapping(systemMapping.getId());
roleSystemDefault = roleSystemService.save(roleSystemDefault);
/*
* Create role with link on system (overloading last name attribute)
*/
IdmRoleDto roleOverloadingLastName = new IdmRoleDto();
roleOverloadingLastName.setCode(ROLE_OVERLOADING_LAST_NAME);
roleOverloadingLastName = roleService.save(roleOverloadingLastName);
SysRoleSystemDto roleSystemLastName = new SysRoleSystemDto();
roleSystemLastName.setRole(roleOverloadingLastName.getId());
roleSystemLastName.setSystem(system.getId());
roleSystemLastName.setSystemMapping(systemMapping.getId());
roleSystemLastName = roleSystemService.save(roleSystemLastName);
// Attribute for overloading last name attribute
SysRoleSystemAttributeDto attributeLastName = new SysRoleSystemAttributeDto();
attributeLastName.setEntityAttribute(true);
attributeLastName.setIdmPropertyName("email");
attributeLastName.setName("Overloaded lastName with email");
attributeLastName.setRoleSystem(roleSystemLastName.getId());
attributeLastName.setSystemAttributeMapping(attributeHandlingLastName.getId());
attributeLastName = roleSystemAttributeService.save(attributeLastName);
/*
* Create role with link on system (overloading password attribute)
*/
IdmRoleDto roleOverloadingPassword = new IdmRoleDto();
// Since 9.3.0 password can't be overridden
roleOverloadingPassword.setCode(ROLE_OVERLOADING_PASSWORD);
roleOverloadingPassword = roleService.save(roleOverloadingPassword);
SysRoleSystemDto roleSystemPassword = new SysRoleSystemDto();
roleSystemPassword.setRole(roleOverloadingPassword.getId());
roleSystemPassword.setSystem(system.getId());
roleSystemPassword.setSystemMapping(systemMapping.getId());
roleSystemPassword = roleSystemService.save(roleSystemPassword);
/*
* Create role with link on system (overloading (disable) first name
* attribute)
*/
IdmRoleDto roleOverloadingFirstName = new IdmRoleDto();
roleOverloadingFirstName.setCode(ROLE_OVERLOADING_FIRST_NAME);
roleOverloadingFirstName = roleService.save(roleOverloadingFirstName);
SysRoleSystemDto roleSystemFirstName = new SysRoleSystemDto();
roleSystemFirstName.setRole(roleOverloadingFirstName.getId());
roleSystemFirstName.setSystem(system.getId());
roleSystemFirstName.setSystemMapping(systemMapping.getId());
roleSystemFirstName = roleSystemService.save(roleSystemFirstName);
// Attribute for overloading first name attribute (disable him)
SysRoleSystemAttributeDto attributeFirstName = new SysRoleSystemAttributeDto();
attributeFirstName.setDisabledDefaultAttribute(true);
attributeFirstName.setName("Disable first name");
attributeFirstName.setRoleSystem(roleSystemFirstName.getId());
attributeFirstName.setSystemAttributeMapping(attributeHandlingFirstName.getId());
attributeFirstName = roleSystemAttributeService.save(attributeFirstName);
/*
* Create role with link on system (overloading name attribute ...
* create Y account)
*/
IdmRoleDto roleOverloadingName = new IdmRoleDto();
roleOverloadingName.setCode(ROLE_OVERLOADING_Y_ACCOUNT);
roleOverloadingName = roleService.save(roleOverloadingName);
SysRoleSystemDto roleSystemName = new SysRoleSystemDto();
roleSystemName.setRole(roleOverloadingName.getId());
roleSystemName.setSystem(system.getId());
roleSystemName.setSystemMapping(systemMapping.getId());
roleSystemName = roleSystemService.save(roleSystemName);
// Attribute for overloading first name attribute (disable him)
SysRoleSystemAttributeDto attributeName = new SysRoleSystemAttributeDto();
attributeName.setUid(true);
attributeName.setEntityAttribute(true);
attributeName.setIdmPropertyName("username");
attributeName.setName("Account with Y-prefix name");
attributeName.setTransformScript("return \"y\" + attributeValue ;");
attributeName.setRoleSystem(roleSystemName.getId());
attributeName.setSystemAttributeMapping(attributeHandlingUserName.getId());
attributeName = roleSystemAttributeService.save(attributeName);
}
use of eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method createMappingIdmPath.
/**
* Creates a list of attribute mapping info from which an error originates
* Contains: system name / mapping or role name / mapped attribute name
*
* @param attributeMapping
* @return
*/
private List<String> createMappingIdmPath(AttributeMapping attributeMapping) {
List<String> path = new ArrayList<>();
// attribute name
path.add(String.format("Attr: %s", attributeMapping.getName()));
// role and system mapping name
SysSystemAttributeMappingDto sysMapping = null;
if (attributeMapping instanceof SysRoleSystemAttributeDto) {
SysRoleSystemAttributeDto mapping = (SysRoleSystemAttributeDto) attributeMapping;
// get role name
SysRoleSystemDto roleSystem = DtoUtils.getEmbedded(mapping, SysRoleSystemAttribute_.roleSystem, SysRoleSystemDto.class, null);
// mapping name and role name are not be available in case of script pre-evaluation during saving
if (roleSystem != null) {
IdmRoleDto roleDto = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.role, IdmRoleDto.class);
path.add(String.format("Role: %s", roleDto.getCode()));
sysMapping = DtoUtils.getEmbedded(mapping, SysRoleSystemAttribute_.systemAttributeMapping, SysSystemAttributeMappingDto.class, null);
}
} else if (attributeMapping instanceof SysSystemAttributeMappingDto) {
sysMapping = (SysSystemAttributeMappingDto) attributeMapping;
}
if (sysMapping != null) {
String mappingName = DtoUtils.getEmbedded(sysMapping, SysSystemAttributeMapping_.systemMapping, SysSystemMappingDto.class).getName();
path.add(String.format("Mapping: %s", mappingName));
}
// system name
path.add(String.format("System: %s", getSystemFromAttributeMapping(attributeMapping).getCode()));
return path;
}
Aggregations