use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method testCreateConnectorConfiguration.
@Test
public void testCreateConnectorConfiguration() {
// TODO: test system will be moved here, after UI eav form implementation
@SuppressWarnings("deprecation") IcConnectorKey connectorKey = systemService.getTestConnectorKey();
// create connector instance impl with connector key
IcConnectorInstance connectorInstance = new IcConnectorInstanceImpl(null, connectorKey, false);
IcConnectorConfiguration conf = icConfigurationAggregatorService.getConnectorConfiguration(connectorInstance);
IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(connectorInstance);
assertEquals(conf.getConfigurationProperties().getProperties().size(), savedFormDefinition.getFormAttributes().size());
assertEquals(conf.getConfigurationProperties().getProperties().get(3).getDisplayName(), savedFormDefinition.getFormAttributes().get(3).getName());
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class RoleSynchronizationExecutor method resolveAssignRole.
private boolean resolveAssignRole(boolean isNew, SynchronizationContext context, IdmRoleDto roleDto, SysSyncRoleConfigDto config, SysSyncItemLogDto logItem, IcConnectorObject connectorObject, SysSystemAttributeMappingDto memberOfAttributeDto, SysSchemaObjectClassDto schemaObjectClassDto) {
// Find attribute for get members (DNs)
SysSystemAttributeMappingDto roleMembersAttributeDto = context.getMappedAttributes().stream().filter(attribute -> !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && ROLE_MEMBERS_FIELD.equals(attribute.getIdmPropertyName())).findFirst().orElse(null);
Assert.notNull(roleMembersAttributeDto, "Mapped attribute with role's members was not found. Please create it!");
if (!isNew && AttributeMappingStrategyType.CREATE == roleMembersAttributeDto.getStrategyType()) {
addToItemLog(logItem, "The attribute with role's members has strategy set to 'Set only for new entity'. Role isn't new, so resolving controlling an assignment of roles to users by the external system will be skipped for this role.");
} else {
addToItemLog(logItem, "Controlling an assignment of roles to users by the external system is activated.");
Object membersObj = this.getValueByMappedAttribute(roleMembersAttributeDto, connectorObject.getAttributes(), context);
if (membersObj == null) {
membersObj = Lists.newArrayList();
}
if (membersObj instanceof String) {
membersObj = Lists.newArrayList(membersObj);
}
Assert.isInstanceOf(List.class, membersObj, "The value from attribute with role's members must be List of Strings!");
@SuppressWarnings("unchecked") List<String> members = (List<String>) membersObj;
SysRoleSystemDto roleSystemDto = findRoleSystemDto(roleDto, memberOfAttributeDto, schemaObjectClassDto);
if (roleSystemDto == null) {
addToItemLog(logItem, "Relation between this role and system was not found. Assigning of role to users will be skip for this role.");
return false;
}
SysRoleSystemAttributeDto memberAttribute = findMemberAttribute(memberOfAttributeDto, schemaObjectClassDto, roleSystemDto);
if (memberAttribute == null) {
addToItemLog(logItem, "The member attribute between this role and system was not found. Assigning of role to users will be skip for this role.");
return false;
}
// Find identities with this role.
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(roleDto.getId());
List<IdmIdentityRoleDto> existsIdentityRoleDtos = identityRoleService.find(identityRoleFilter, null).getContent();
// Get cache with users (DN vs UID).
Map<String, String> usersUidCache = getUserUidCache();
SysSchemaAttributeDto memberIdentifierAttribute = lookupService.lookupEmbeddedDto(config, SysSyncRoleConfig_.memberIdentifierAttribute);
Assert.notNull(memberIdentifierAttribute, "User identifier attribute cannot be null!");
Set<String> membersUid = Sets.newHashSet();
Set<UUID> membersContractIds = Sets.newHashSet();
// Call user system for every member (if isn't already in the cache).
SysSystemDto userSystemDto = systemService.get(roleSystemDto.getSystem());
IcConnectorConfiguration icConfig = systemService.getConnectorConfiguration(userSystemDto);
IcConnectorInstance connectorInstance = systemService.getConnectorInstance(userSystemDto);
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
if (icConfig instanceof IcConnectorConfigurationImpl) {
// Enable pooling - a performance reason.
IcConnectorConfigurationImpl icConfigImpl = (IcConnectorConfigurationImpl) icConfig;
icConfigImpl.setConnectorPoolingSupported(true);
}
final int[] count = { 0 };
for (String member : members) {
if (!transformDnToUid(config, usersUidCache, memberIdentifierAttribute, membersUid, icConfig, connectorInstance, objectClass, count, member)) {
return false;
}
}
count[0] = 0;
membersUid.forEach(uid -> assignMissingIdentityRoles(roleDto, config, logItem, existsIdentityRoleDtos, membersContractIds, userSystemDto, count, uid, context));
if (!checkForCancelAndFlush(config)) {
return false;
}
// Remove redundant identity roles.
List<IdmIdentityRoleDto> redundantIdentityRoles = existsIdentityRoleDtos.stream().filter(existsIdentityRole -> !membersContractIds.contains(existsIdentityRole.getIdentityContract())).collect(Collectors.toList());
count[0] = 0;
redundantIdentityRoles.forEach(redundantIdentityRole -> removeRedundantIdentityRoles(roleDto, config, logItem, count, redundantIdentityRole));
}
return true;
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method getOperationOptionsForSystem.
/**
* Creates configuration for operation options by EAV values
*
* @param connectorInstance
* @param system
*/
private Map<String, Object> getOperationOptionsForSystem(IcConnectorInstance connectorInstance, SysSystemDto system) {
IdmFormDefinitionDto formDefinition = getOperationOptionsConnectorFormDefinition(connectorInstance);
if (formDefinition == null) {
return Collections.emptyMap();
}
IdmFormInstanceDto formInstance = getFormService().getFormInstance(system, formDefinition);
if (formInstance == null) {
return Collections.emptyMap();
}
Map<String, List<IdmFormValueDto>> optionToValues = formInstance.toValueMap();
return optionToValues.keySet().stream().filter(key -> !optionToValues.get(key).isEmpty()).collect(Collectors.toMap(key -> key, key -> {
List<IdmFormValueDto> values = optionToValues.get(key);
//
return values.size() > 1 ? toArray(values, formDefinition.getMappedAttributeByCode(key).getPersistentType()) : values.get(0).getValue();
}));
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method getConnectorConfiguration.
@Override
@Transactional
public IcConnectorConfiguration getConnectorConfiguration(SysSystemDto system) {
Assert.notNull(system, "System is required.");
if (system.getConnectorKey() == null) {
return null;
}
IcConnectorConfiguration connectorConfig = null;
// load connector properties, different between local and remote
IcConnectorInstance connectorInstance = getConnectorInstance(system);
connectorConfig = icConfigurationFacade.getConnectorConfiguration(connectorInstance);
// load filled form values
IdmFormDefinitionDto formDefinition = getConnectorFormDefinition(connectorInstance);
IdmFormInstanceDto formInstance = getFormService().getFormInstance(system, formDefinition);
Map<String, List<IdmFormValueDto>> attributeValues = formInstance.toValueMap();
// fill connector configuration from form values
IcConnectorConfigurationImpl configuration = null;
if (SysSystemService.CONNECTOR_FRAMEWORK_CZECHIDM.equals(connectorInstance.getConnectorKey().getFramework())) {
// For CzechIdM connector framework is needs system ID (exactly for virtual systems).
configuration = new IcConnectorConfigurationCzechIdMImpl();
((IcConnectorConfigurationCzechIdMImpl) configuration).setSystemId(system.getId());
} else {
configuration = new IcConnectorConfigurationImpl();
}
// Create configuration for pool
fillPoolingConnectorConfiguration(configuration, connectorInstance, system);
// Load operation options
configuration.setOperationOptions(getOperationOptionsForSystem(connectorInstance, system));
IcConfigurationProperties properties = new IcConfigurationPropertiesImpl();
configuration.setConfigurationProperties(properties);
//
for (short seq = 0; seq < connectorConfig.getConfigurationProperties().getProperties().size(); seq++) {
IcConfigurationProperty propertyConfig = connectorConfig.getConfigurationProperties().getProperties().get(seq);
IdmFormAttributeDto formAttribute = formInstance.getMappedAttributeByCode(propertyConfig.getName());
List<IdmFormValueDto> eavAttributeValues = attributeValues.get(formAttribute.getCode());
// create property instance from configuration
IcConfigurationProperty property = formPropertyManager.toConnectorProperty(propertyConfig, eavAttributeValues);
if (property.getValue() != null) {
// only filled values to configuration
properties.getProperties().add(property);
}
}
return configuration;
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method duplicate.
@Override
@Transactional
public SysSystemDto duplicate(UUID id) {
SysSystemDto originalSystem = this.get(id);
Asserts.notNull(originalSystem, "System must be found!");
// Clone and save system
SysSystemDto clone = this.clone(id);
String name = MessageFormat.format("{0}{1}", "Copy-of-", clone.getName());
name = this.duplicateName(name, 0);
clone.setName(name);
// Set as inactive system
clone.setDisabled(true);
SysSystemDto system = this.save(clone);
// Cache old and new IDs
Map<UUID, UUID> schemaAttributesCache = new HashMap<UUID, UUID>();
Map<UUID, UUID> mappedAttributesCache = new HashMap<UUID, UUID>();
// Duplicate connector configuration values in EAV
IcConnectorInstance connectorInstance = getConnectorInstance(originalSystem);
if (connectorInstance != null && connectorInstance.getConnectorKey() != null && connectorInstance.getConnectorKey().getFramework() != null) {
IdmFormDefinitionDto formDefinition = getConnectorFormDefinition(connectorInstance);
List<IdmFormValueDto> originalFormValues = this.getFormService().getValues(id, SysSystem.class, formDefinition);
SysSystem systemEntity = getEntity(system.getId());
originalFormValues.stream().forEach(value -> {
systemFormValueService.duplicate(value.getId(), systemEntity);
});
}
// Duplicate schema
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(id);
objectClassService.find(objectClassFilter, null).getContent().stream().forEach(schema -> {
UUID originalSchemaId = schema.getId();
SysSchemaObjectClassDto duplicatedSchema = this.duplicateSchema(originalSchemaId, system, schemaAttributesCache);
// Duplicate mapped attributes
SysSystemMappingFilter systemMappingFilter = new SysSystemMappingFilter();
systemMappingFilter.setSystemId(id);
systemMappingService.find(systemMappingFilter, null).getContent().stream().filter(mapping -> {
// Find mapping for this schema
return mapping.getObjectClass().equals(originalSchemaId);
}).forEach(mapping -> {
final UUID originalMappingId = mapping.getId();
SysSystemMappingDto duplicatedMapping = systemMappingService.duplicateMapping(originalMappingId, duplicatedSchema, schemaAttributesCache, mappedAttributesCache, false);
// Duplicate sync configs
List<AbstractSysSyncConfigDto> syncConfigs = findSyncConfigs(id);
syncConfigs.stream().filter(syncConfig -> {
// Find configuration of sync for this mapping
return syncConfig.getSystemMapping().equals(originalMappingId);
}).forEach(syncConfig -> {
UUID syncConfigId = syncConfig.getId();
duplicateSyncConf(syncConfigId, duplicatedMapping, mappedAttributesCache);
});
});
});
return system;
}
Aggregations