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);
}
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;
}
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);
}
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;
}
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));
}
Aggregations