use of io.trino.spi.security.PasswordAuthenticator 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.security.PasswordAuthenticator in project trino by trinodb.
the class TestPasswordAuthenticatorManager method testMultipleConfigFiles.
@Test
public void testMultipleConfigFiles() throws Exception {
Path config1 = createTempFile("passwordConfig", "1");
Path config2 = createTempFile("passwordConfig", "2");
Files.write(config1, ImmutableList.of("password-authenticator.name=type1"));
Files.write(config2, ImmutableList.of("password-authenticator.name=type2"));
PasswordAuthenticatorManager manager = new PasswordAuthenticatorManager(new PasswordAuthenticatorConfig().setPasswordAuthenticatorFiles(config1.toAbsolutePath() + "," + config2.toAbsolutePath()));
manager.setRequired();
manager.addPasswordAuthenticatorFactory(new TestingPasswordAuthenticatorFactory("type1", "password1"));
manager.addPasswordAuthenticatorFactory(new TestingPasswordAuthenticatorFactory("type2", "password2"));
manager.loadPasswordAuthenticator();
List<PasswordAuthenticator> authenticators = manager.getAuthenticators();
assertThat(login(authenticators, "password1")).isTrue();
assertThat(login(authenticators, "password2")).isTrue();
assertThat(login(authenticators, "wrong_password")).isFalse();
}
use of io.trino.spi.security.PasswordAuthenticator in project trino by trinodb.
the class PasswordManagerFormAuthenticator method isValidCredential.
@Override
public Optional<String> isValidCredential(String username, String password, boolean secure) {
if (username == null) {
return Optional.empty();
}
if (!secure) {
return Optional.of(username).filter(user -> insecureAuthenticationOverHttpAllowed && password == null);
}
List<PasswordAuthenticator> authenticators = passwordAuthenticatorManager.getAuthenticators();
for (PasswordAuthenticator authenticator : authenticators) {
try {
Principal principal = authenticator.createAuthenticatedPrincipal(username, password);
String authenticatedUser = userMapping.mapUser(principal.toString());
return Optional.of(authenticatedUser);
} catch (AccessDeniedException | UserMappingException e) {
// Try another one
} catch (RuntimeException e) {
log.debug(e, "Error authenticating user for Web UI");
}
}
return Optional.empty();
}
use of io.trino.spi.security.PasswordAuthenticator in project trino by trinodb.
the class PasswordAuthenticatorManager method loadPasswordAuthenticator.
public void loadPasswordAuthenticator() {
if (!required.get()) {
return;
}
ImmutableList.Builder<PasswordAuthenticator> authenticators = ImmutableList.builder();
for (File configFile : configFiles) {
authenticators.add(loadAuthenticator(configFile.getAbsoluteFile()));
}
this.authenticators.set(authenticators.build());
}
Aggregations