Search in sources :

Example 1 with IcObjectClassInfo

use of eu.bcvsolutions.idm.ic.api.IcObjectClassInfo in project CzechIdMng by bcvsolutions.

the class ConnIdIcConvertUtil method convertConnIdSchema.

public static IcSchema convertConnIdSchema(Schema schema) {
    if (schema == null) {
        return null;
    }
    IcSchemaImpl icSchema = new IcSchemaImpl();
    List<IcObjectClassInfo> objectClasses = icSchema.getDeclaredObjectClasses();
    for (ObjectClassInfo classInfo : schema.getObjectClassInfo()) {
        objectClasses.add(ConnIdIcConvertUtil.convertConnIdObjectClassInfo(classInfo));
    }
    if (schema.getSupportedObjectClassesByOperation() != null) {
        for (Class<? extends APIOperation> operation : schema.getSupportedObjectClassesByOperation().keySet()) {
            Set<ObjectClassInfo> objectClasesConnid = schema.getSupportedObjectClassesByOperation().get(operation);
            List<String> objectClassesForOperation = new ArrayList<>(objectClasesConnid.size());
            for (ObjectClassInfo oci : objectClasesConnid) {
                objectClassesForOperation.add(oci.getType());
            }
            icSchema.getSupportedObjectClassesByOperation().put(operation.getSimpleName(), objectClassesForOperation);
        }
    }
    return icSchema;
}
Also used : IcSchemaImpl(eu.bcvsolutions.idm.ic.impl.IcSchemaImpl) ObjectClassInfo(org.identityconnectors.framework.common.objects.ObjectClassInfo) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) ArrayList(java.util.ArrayList) GuardedString(org.identityconnectors.common.security.GuardedString)

Example 2 with IcObjectClassInfo

use of eu.bcvsolutions.idm.ic.api.IcObjectClassInfo 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;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) SysConnectorKey_(eu.bcvsolutions.idm.acc.entity.SysConnectorKey_) SysSystem_(eu.bcvsolutions.idm.acc.entity.SysSystem_) FormPropertyManager(eu.bcvsolutions.idm.acc.service.api.FormPropertyManager) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IcConfigurationPropertiesImpl(eu.bcvsolutions.idm.ic.impl.IcConfigurationPropertiesImpl) Asserts(org.apache.http.util.Asserts) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) IcObjectPoolConfigurationImpl(eu.bcvsolutions.idm.ic.impl.IcObjectPoolConfigurationImpl) StringUtils(org.apache.commons.lang3.StringUtils) IcConfigurationProperties(eu.bcvsolutions.idm.ic.api.IcConfigurationProperties) SysConnectorKeyDto(eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IcConnectorInstance(eu.bcvsolutions.idm.ic.api.IcConnectorInstance) Predicate(javax.persistence.criteria.Predicate) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IcConnectorConfigurationCzechIdMImpl(eu.bcvsolutions.idm.ic.czechidm.domain.IcConnectorConfigurationCzechIdMImpl) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcConfigurationFacade(eu.bcvsolutions.idm.ic.service.api.IcConfigurationFacade) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) ImmutableMap(com.google.common.collect.ImmutableMap) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IcConnectorKeyImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorKeyImpl) IcObjectPoolConfiguration(eu.bcvsolutions.idm.ic.api.IcObjectPoolConfiguration) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) Serializable(java.io.Serializable) List(java.util.List) IcConnectorServer(eu.bcvsolutions.idm.ic.api.IcConnectorServer) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Optional(java.util.Optional) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) HashMap(java.util.HashMap) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystemRepository(eu.bcvsolutions.idm.acc.repository.SysSystemRepository) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmPasswordPolicy_(eu.bcvsolutions.idm.core.model.entity.IdmPasswordPolicy_) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) Service(org.springframework.stereotype.Service) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) SysSystemFormValueService(eu.bcvsolutions.idm.acc.service.api.SysSystemFormValueService) IcConfigurationProperty(eu.bcvsolutions.idm.ic.api.IcConfigurationProperty) Qualifier(org.springframework.beans.factory.annotation.Qualifier) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) DefaultConnectorType(eu.bcvsolutions.idm.acc.connector.DefaultConnectorType) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Root(javax.persistence.criteria.Root) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) IcConnectorInstanceImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorInstanceImpl) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) IcSchema(eu.bcvsolutions.idm.ic.api.IcSchema) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysRemoteServer_(eu.bcvsolutions.idm.acc.entity.SysRemoteServer_) IcConnectorConfigurationImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorConfigurationImpl) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AbstractFormableService(eu.bcvsolutions.idm.core.eav.api.service.AbstractFormableService) Collections(java.util.Collections) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) SysSchemaObjectClassFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ArrayList(java.util.ArrayList) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IcSchema(eu.bcvsolutions.idm.ic.api.IcSchema) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IcObjectClassInfo

use of eu.bcvsolutions.idm.ic.api.IcObjectClassInfo in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method generateSchema.

/**
 * Generate schema from connector configuration and form definition
 *
 * @return
 */
private IcSchemaImpl generateSchema() {
    IcSchemaImpl schema = new IcSchemaImpl();
    List<IcObjectClassInfo> objectClasses = schema.getDeclaredObjectClasses();
    IcObjectClassInfoImpl objectClass = new IcObjectClassInfoImpl();
    objectClass.setType(IcObjectClassInfo.ACCOUNT);
    List<IcAttributeInfo> attributes = objectClass.getAttributeInfos();
    // Create UID schema attribute
    IcAttributeInfoImpl attributeUid = new IcAttributeInfoImpl();
    attributeUid.setClassType(String.class.getName());
    attributeUid.setCreateable(true);
    attributeUid.setMultivalued(false);
    attributeUid.setName(IcAttributeInfo.NAME);
    attributeUid.setNativeName(VsAccount_.uid.getName());
    attributeUid.setReadable(true);
    attributeUid.setRequired(true);
    attributeUid.setReturnedByDefault(true);
    attributeUid.setUpdateable(true);
    attributes.add(attributeUid);
    // Create ENABLE schema attribute
    if (this.virtualConfiguration.isDisableSupported()) {
        IcAttributeInfoImpl attributeDisabled = new IcAttributeInfoImpl();
        attributeDisabled.setClassType(Boolean.class.getName());
        attributeDisabled.setCreateable(true);
        attributeDisabled.setMultivalued(false);
        attributeDisabled.setName(IcAttributeInfo.ENABLE);
        attributeDisabled.setNativeName(VsAccount_.enable.getName());
        attributeDisabled.setReadable(true);
        attributeDisabled.setRequired(false);
        attributeDisabled.setReturnedByDefault(true);
        attributeDisabled.setUpdateable(true);
        attributes.add(attributeDisabled);
    }
    // Attributes from definition and configuration
    Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
        IdmFormAttributeDto formAttribute = formAttributeService.findAttribute(VsAccount.class.getName(), formDefinition.getCode(), virtualAttirbute);
        if (formAttribute == null) {
            return;
        }
        IcAttributeInfoImpl attribute = new IcAttributeInfoImpl();
        String classType = this.convertToSchemaClassType(formAttribute.getPersistentType());
        attribute.setClassType(classType);
        attribute.setCreateable(!formAttribute.isReadonly());
        attribute.setMultivalued(formAttribute.isMultiple());
        attribute.setName(virtualAttirbute);
        attribute.setNativeName(virtualAttirbute);
        attribute.setReadable(true);
        attribute.setRequired(formAttribute.isRequired());
        attribute.setReturnedByDefault(true);
        attribute.setUpdateable(!formAttribute.isReadonly());
        attributes.add(attribute);
    });
    objectClasses.add(objectClass);
    return schema;
}
Also used : IcObjectClassInfoImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassInfoImpl) VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) IcSchemaImpl(eu.bcvsolutions.idm.ic.impl.IcSchemaImpl) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IcAttributeInfoImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeInfoImpl)

Aggregations

IcObjectClassInfo (eu.bcvsolutions.idm.ic.api.IcObjectClassInfo)3 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)2 IcAttributeInfo (eu.bcvsolutions.idm.ic.api.IcAttributeInfo)2 IcSchemaImpl (eu.bcvsolutions.idm.ic.impl.IcSchemaImpl)2 ArrayList (java.util.ArrayList)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 DefaultConnectorType (eu.bcvsolutions.idm.acc.connector.DefaultConnectorType)1 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)1 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)1 SysConnectorKeyDto (eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto)1 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)1 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)1 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)1 SysSchemaObjectClassFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter)1 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)1 SysSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter)1 SysSystemMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter)1