Search in sources :

Example 1 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class CertificateAuthenticatorManager method loadCertificateAuthenticator.

public void loadCertificateAuthenticator() throws Exception {
    if (!required.get()) {
        return;
    }
    File configFile = CONFIG_FILE.getAbsoluteFile();
    if (!configFile.exists()) {
        useDefaultAuthenticator();
        return;
    }
    Map<String, String> properties = new HashMap<>(loadPropertiesFrom(configFile.getPath()));
    String name = properties.remove(NAME_PROPERTY);
    checkState(!isNullOrEmpty(name), "Certificate authenticator configuration %s does not contain '%s'", configFile, NAME_PROPERTY);
    log.info("-- Loading certificate authenticator --");
    CertificateAuthenticatorFactory factory = factories.get(name);
    checkState(factory != null, "Certificate authenticator '%s' is not registered", name);
    CertificateAuthenticator authenticator;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        authenticator = factory.create(ImmutableMap.copyOf(properties));
    }
    this.authenticator.set(requireNonNull(authenticator, "authenticator is null"));
    log.info("-- Loaded certificate authenticator %s --", name);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CertificateAuthenticator(io.trino.spi.security.CertificateAuthenticator) File(java.io.File) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) CertificateAuthenticatorFactory(io.trino.spi.security.CertificateAuthenticatorFactory)

Example 2 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class PasswordAuthenticatorManager method loadAuthenticator.

private PasswordAuthenticator loadAuthenticator(File configFile) {
    Map<String, String> properties;
    try {
        properties = new HashMap<>(loadPropertiesFrom(configFile.getPath()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    String name = properties.remove(NAME_PROPERTY);
    checkState(!isNullOrEmpty(name), "Password authenticator configuration %s does not contain '%s'", configFile, NAME_PROPERTY);
    log.info("-- Loading password authenticator --");
    PasswordAuthenticatorFactory factory = factories.get(name);
    checkState(factory != null, "Password authenticator '%s' is not registered", name);
    PasswordAuthenticator authenticator;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        authenticator = factory.create(ImmutableMap.copyOf(properties));
    }
    log.info("-- Loaded password authenticator %s --", name);
    return authenticator;
}
Also used : PasswordAuthenticatorFactory(io.trino.spi.security.PasswordAuthenticatorFactory) PasswordAuthenticator(io.trino.spi.security.PasswordAuthenticator) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Example 3 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class InternalResourceGroupManager method setConfigurationManager.

@VisibleForTesting
public void setConfigurationManager(String name, Map<String, String> properties) {
    requireNonNull(name, "name is null");
    requireNonNull(properties, "properties is null");
    log.info("-- Loading resource group configuration manager --");
    ResourceGroupConfigurationManagerFactory factory = configurationManagerFactories.get(name);
    checkState(factory != null, "Resource group configuration manager '%s' is not registered", name);
    ResourceGroupConfigurationManager<C> configurationManager;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        configurationManager = cast(factory.create(ImmutableMap.copyOf(properties), configurationManagerContext));
    }
    checkState(this.configurationManager.compareAndSet(cast(legacyManager), configurationManager), "configurationManager already set");
    log.info("-- Loaded resource group configuration manager %s --", name);
}
Also used : ResourceGroupConfigurationManagerFactory(io.trino.spi.resourcegroups.ResourceGroupConfigurationManagerFactory) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class AccessControlManager method createSystemAccessControl.

private SystemAccessControl createSystemAccessControl(File configFile) {
    log.info("-- Loading system access control %s --", configFile);
    configFile = configFile.getAbsoluteFile();
    Map<String, String> properties;
    try {
        properties = new HashMap<>(loadPropertiesFrom(configFile.getPath()));
    } catch (IOException e) {
        throw new UncheckedIOException("Failed to read configuration file: " + configFile, e);
    }
    String name = properties.remove(NAME_PROPERTY);
    checkState(!isNullOrEmpty(name), "Access control configuration does not contain '%s' property: %s", NAME_PROPERTY, configFile);
    SystemAccessControlFactory factory = systemAccessControlFactories.get(name);
    checkState(factory != null, "Access control '%s' is not registered: %s", name, configFile);
    SystemAccessControl systemAccessControl;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        systemAccessControl = factory.create(ImmutableMap.copyOf(properties));
    }
    log.info("-- Loaded system access control %s --", name);
    return systemAccessControl;
}
Also used : SystemAccessControlFactory(io.trino.spi.security.SystemAccessControlFactory) ReadOnlySystemAccessControl(io.trino.plugin.base.security.ReadOnlySystemAccessControl) FileBasedSystemAccessControl(io.trino.plugin.base.security.FileBasedSystemAccessControl) SystemAccessControl(io.trino.spi.security.SystemAccessControl) ForwardingSystemAccessControl(io.trino.plugin.base.security.ForwardingSystemAccessControl) DefaultSystemAccessControl(io.trino.plugin.base.security.DefaultSystemAccessControl) AllowAllSystemAccessControl(io.trino.plugin.base.security.AllowAllSystemAccessControl) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Example 5 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class AccessControlManager method setSystemAccessControl.

@VisibleForTesting
protected void setSystemAccessControl(String name, Map<String, String> properties) {
    requireNonNull(name, "name is null");
    requireNonNull(properties, "properties is null");
    SystemAccessControlFactory factory = systemAccessControlFactories.get(name);
    checkState(factory != null, "Access control '%s' is not registered", name);
    SystemAccessControl systemAccessControl;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        systemAccessControl = factory.create(ImmutableMap.copyOf(properties));
    }
    setSystemAccessControls(ImmutableList.of(systemAccessControl));
}
Also used : SystemAccessControlFactory(io.trino.spi.security.SystemAccessControlFactory) ReadOnlySystemAccessControl(io.trino.plugin.base.security.ReadOnlySystemAccessControl) FileBasedSystemAccessControl(io.trino.plugin.base.security.FileBasedSystemAccessControl) SystemAccessControl(io.trino.spi.security.SystemAccessControl) ForwardingSystemAccessControl(io.trino.plugin.base.security.ForwardingSystemAccessControl) DefaultSystemAccessControl(io.trino.plugin.base.security.DefaultSystemAccessControl) AllowAllSystemAccessControl(io.trino.plugin.base.security.AllowAllSystemAccessControl) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ThreadContextClassLoader (io.trino.spi.classloader.ThreadContextClassLoader)23 Injector (com.google.inject.Injector)7 Bootstrap (io.airlift.bootstrap.Bootstrap)7 JsonModule (io.airlift.json.JsonModule)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 CatalogName (io.trino.plugin.base.CatalogName)4 Connector (io.trino.spi.connector.Connector)4 ConnectorContext (io.trino.spi.connector.ConnectorContext)4 TypeManager (io.trino.spi.type.TypeManager)4 Map (java.util.Map)4 Key (com.google.inject.Key)3 Module (com.google.inject.Module)3 TypeLiteral (com.google.inject.TypeLiteral)3 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)3 EventModule (io.airlift.event.client.EventModule)3 CatalogNameModule (io.trino.plugin.base.CatalogNameModule)3 ClassLoaderSafeConnectorPageSinkProvider (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSinkProvider)3 ClassLoaderSafeConnectorPageSourceProvider (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSourceProvider)3 ClassLoaderSafeConnectorSplitManager (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorSplitManager)3 ClassLoaderSafeNodePartitioningProvider (io.trino.plugin.base.classloader.ClassLoaderSafeNodePartitioningProvider)3