use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method convertMappingAttribute.
/**
* Convert schema attribute handling to Form attribute
*
* @param entity
* @return
*/
private IdmFormAttributeDto convertMappingAttribute(AttributeMapping entity) {
SysSchemaAttributeDto schemaAttribute = getSchemaAttribute(entity);
IdmFormAttributeDto attributeDefinition = new IdmFormAttributeDto();
attributeDefinition.setCode(entity.getIdmPropertyName());
attributeDefinition.setName(entity.getName());
attributeDefinition.setPersistentType(formPropertyManager.getPersistentType(schemaAttribute.getClassType()));
attributeDefinition.setRequired(schemaAttribute.isRequired());
attributeDefinition.setMultiple(schemaAttribute.isMultivalued());
attributeDefinition.setReadonly(!schemaAttribute.isUpdateable());
attributeDefinition.setConfidential(entity.isConfidentialAttribute());
// attribute can be deleted
attributeDefinition.setUnmodifiable(false);
// We want to use short text as default (but only on this place)
if (PersistentType.TEXT == attributeDefinition.getPersistentType()) {
attributeDefinition.setPersistentType(PersistentType.SHORTTEXT);
}
SysSystemDto system = getSystemFromSchemaAttribute(schemaAttribute);
//
attributeDefinition.setDescription(MessageFormat.format("Generated by schema attribute {0} in resource {1}. Created by SYSTEM.", schemaAttribute.getName(), system.getName()));
return attributeDefinition;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method duplicateSchema.
/**
* Duplication of schema attributes. Is not in attribute schema service, because we need use IDs cache (Old vs New IDs)
* @param id
* @param system
* @param schemaAttributesIds
* @return
*/
private SysSchemaObjectClassDto duplicateSchema(UUID id, SysSystemDto system, Map<UUID, UUID> schemaAttributesIds) {
Assert.notNull(id, "Id of duplication schema, must be filled!");
Assert.notNull(system, "Parent system must be filled!");
SysSchemaObjectClassDto clonedSchema = objectClassService.clone(id);
clonedSchema.setSystem(system.getId());
SysSchemaObjectClassDto schema = objectClassService.save(clonedSchema);
SysSchemaAttributeFilter schemaAttributesFilter = new SysSchemaAttributeFilter();
schemaAttributesFilter.setObjectClassId(id);
attributeService.find(schemaAttributesFilter, null).forEach(schemaAttribute -> {
UUID originalSchemaAttributId = schemaAttribute.getId();
SysSchemaAttributeDto clonedAttribut = attributeService.clone(originalSchemaAttributId);
clonedAttribut.setObjectClass(schema.getId());
clonedAttribut = attributeService.save(clonedAttribut);
// Put original and new id to cache
schemaAttributesIds.put(originalSchemaAttributId, clonedAttribut.getId());
});
return schema;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method generateSchema.
@Override
@Transactional
public List<SysSchemaObjectClassDto> generateSchema(SysSystemDto system) {
Assert.notNull(system, "System is required.");
Assert.notNull(system.getId(), "System identifier is required.");
// Find connector identification persisted in system
IcConnectorKey connectorKey = system.getConnectorKey();
if (connectorKey == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Find connector configuration persisted in system
IcConnectorConfiguration connectorConfig = getConnectorConfiguration(system);
if (connectorConfig == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Call IC module and find schema for given connector key and
// configuration
IcSchema icSchema = null;
try {
icSchema = icConfigurationFacade.getSchema(getConnectorInstance(system), connectorConfig);
} catch (Exception ex) {
throw new ResultCodeException(AccResultCode.CONNECTOR_SCHEMA_GENERATION_EXCEPTION, ImmutableMap.of("system", system.getName(), "exception", ex.getLocalizedMessage()), ex);
}
if (icSchema == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_SCHEMA_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Load existing object class from system
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(system.getId());
List<SysSchemaObjectClassDto> sysObjectClassesInSystem = null;
Page<SysSchemaObjectClassDto> page = objectClassService.find(objectClassFilter, null);
sysObjectClassesInSystem = page.getContent();
// Convert IC schema to ACC entities
List<IcObjectClassInfo> declaredObjectClasses = icSchema.getDeclaredObjectClasses();
List<SysSchemaObjectClassDto> sysObjectClasses = new ArrayList<>(declaredObjectClasses.size());
List<SysSchemaAttributeDto> sysAttributes = new ArrayList<>();
for (IcObjectClassInfo objectClass : declaredObjectClasses) {
// __ACCOUNT__ and __GROUP__
if (!(objectClass.getType().startsWith("__") && objectClass.getType().endsWith("__"))) {
continue;
}
SysSchemaObjectClassDto sysObjectClass = null;
// values from resource
if (sysObjectClassesInSystem != null) {
Optional<SysSchemaObjectClassDto> objectClassSame = sysObjectClassesInSystem.stream().filter(objectClassInSystem -> {
//
return objectClassInSystem.getObjectClassName().equals(objectClass.getType());
}).findFirst();
if (objectClassSame.isPresent()) {
sysObjectClass = objectClassSame.get();
}
}
// Convert IC object class to ACC (if is null, then will be created
// new instance)
sysObjectClass = convertIcObjectClassInfo(objectClass, sysObjectClass);
sysObjectClass.setSystem(system.getId());
// object class may not exist
sysObjectClass = schemaObjectClassService.save(sysObjectClass);
sysObjectClasses.add(sysObjectClass);
List<SysSchemaAttributeDto> attributesInSystem = null;
// Load existing attributes for existing object class in system
if (sysObjectClass.getId() != null) {
SysSchemaAttributeFilter attFilter = new SysSchemaAttributeFilter();
attFilter.setSystemId(system.getId());
attFilter.setObjectClassId(sysObjectClass.getId());
Page<SysSchemaAttributeDto> attributesInSystemPage = attributeService.find(attFilter, null);
attributesInSystem = attributesInSystemPage.getContent();
}
for (IcAttributeInfo attribute : objectClass.getAttributeInfos()) {
// If will be IC and ACC attribute same (same name), then we
// will do only refresh object values from resource
SysSchemaAttributeDto sysAttribute = null;
if (attributesInSystem != null) {
Optional<SysSchemaAttributeDto> sysAttributeOptional = attributesInSystem.stream().filter(a -> {
return a.getName().equals(attribute.getName());
}).findFirst();
if (sysAttributeOptional.isPresent()) {
sysAttribute = sysAttributeOptional.get();
}
}
sysAttribute = convertIcAttributeInfo(attribute, sysAttribute);
sysAttribute.setObjectClass(sysObjectClass.getId());
sysAttributes.add(sysAttribute);
}
}
// Persist generated schema to system
sysObjectClasses = (List<SysSchemaObjectClassDto>) objectClassService.saveAll(sysObjectClasses);
attributeService.saveAll(sysAttributes);
return sysObjectClasses;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method findRoots.
/**
* Find all roots for this tree (uses groovy script for root definition)
*
* @param parentAttribute
* @param accountsMap
* @param config
* @return
*/
private Collection<String> findRoots(SysSystemAttributeMappingDto parentAttribute, Map<String, IcConnectorObject> accountsMap, AbstractSysSyncConfigDto config, SynchronizationContext context) {
Set<String> roots = Sets.newHashSet();
if (parentAttribute == null) {
return roots;
}
accountsMap.forEach((uid, account) -> {
if (StringUtils.hasLength(config.getRootsFilterScript())) {
Map<String, Object> variables = new HashMap<>();
variables.put("account", account);
List<Class<?>> allowTypes = new ArrayList<>();
allowTypes.add(IcAttributeImpl.class);
allowTypes.add(IcAttribute.class);
allowTypes.add(IcLoginAttributeImpl.class);
Object isRoot = groovyScriptService.evaluate(config.getRootsFilterScript(), variables, allowTypes);
if (isRoot != null && !(isRoot instanceof Boolean)) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_ROOT_FILTER_VALUE_WRONG_TYPE, ImmutableMap.of("type", isRoot.getClass().getName()));
}
if ((Boolean) isRoot) {
roots.add(uid);
}
} else {
// Default search root strategy: If parent is null or an empty string, then it is a root node.
// IdM is able to cope only with null parent of the root node. Therefore empty string value is changed to null.
Object parentValue = super.getValueByMappedAttribute(parentAttribute, account.getAttributes(), context);
if (parentValue == null) {
roots.add(uid);
} else if (StringUtils.isEmpty(parentValue)) {
SysSchemaAttributeDto schemaAttribute = DtoUtils.getEmbedded(parentAttribute, SysSystemAttributeMapping_.schemaAttribute.getName(), SysSchemaAttributeDto.class);
IcAttribute attribute = account.getAttributeByName(schemaAttribute.getName());
if (attribute instanceof IcAttributeImpl) {
((IcAttributeImpl) attribute).setValues(null);
}
roots.add(uid);
}
}
});
return roots;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto in project CzechIdMng by bcvsolutions.
the class RoleSynchronizationExecutor method checkSkipValueIfExcludedChange.
/**
* Check if 'SkipIfValueExcluded' value is different then value form a transformation.
*/
private void checkSkipValueIfExcludedChange(IdmRoleDto dto, SynchronizationContext context, String attributeProperty, Object transformedValue) {
if (!context.isEntityDifferent() && dto.getId() != null && getConfig(context).isSkipValueIfExcludedSwitch()) {
// Check if 'SkipIfValueExcluded' value should be modified (differential sync).
SysSystemAttributeMappingDto memberOfAttributeDto = lookupService.lookupEmbeddedDto(getConfig(context), SysSyncRoleConfig_.memberOfAttribute);
Assert.notNull(memberOfAttributeDto, "Member attribute cannot be null!");
SysSchemaAttributeDto schemaAttributeDto = lookupService.lookupEmbeddedDto(memberOfAttributeDto, SysSystemAttributeMapping_.schemaAttribute);
SysSchemaObjectClassDto schemaObjectClassDto = lookupService.lookupEmbeddedDto(schemaAttributeDto, SysSchemaAttribute_.objectClass);
Assert.notNull(schemaObjectClassDto, "Schema cannot be null!");
boolean skipIfValueExcludedFromValue = getSkipIfValueExcludedFromValue(transformedValue);
SysRoleSystemDto roleSystemDto = findRoleSystemDto(dto, memberOfAttributeDto, schemaObjectClassDto);
if (roleSystemDto == null) {
setDifferentChange(context, attributeProperty);
return;
}
// Find member attribute.
SysRoleSystemAttributeDto memberAttribute = findMemberAttribute(memberOfAttributeDto, schemaObjectClassDto, roleSystemDto);
if (memberAttribute == null || memberAttribute.isSkipValueIfExcluded() != skipIfValueExcludedFromValue) {
setDifferentChange(context, attributeProperty);
}
}
}
Aggregations