Skip to content

Commit

Permalink
Allow extending metastore authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
phd3 authored and dain committed Sep 5, 2022
1 parent a51ba1d commit bb608ef
Showing 1 changed file with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,24 @@
import io.trino.plugin.hive.ForHiveMetastore;

import static com.google.inject.Scopes.SINGLETON;
import static com.google.inject.multibindings.OptionalBinder.newOptionalBinder;
import static io.airlift.configuration.ConfigBinder.configBinder;
import static io.trino.hdfs.authentication.AuthenticationModules.createCachingKerberosHadoopAuthentication;
import static io.trino.plugin.hive.metastore.thrift.ThriftMetastoreAuthenticationConfig.ThriftMetastoreAuthenticationType.KERBEROS;

public class ThriftMetastoreAuthenticationModule
extends AbstractConfigurationAwareModule
{
@Override
protected void setup(Binder binder)
{
install(getAuthenticationModule());
}
newOptionalBinder(binder, IdentityAwareMetastoreClientFactory.class)
.setDefault().to(UgiBasedMetastoreClientFactory.class).in(SINGLETON);
newOptionalBinder(binder, HiveMetastoreAuthentication.class)
.setDefault().to(NoHiveMetastoreAuthentication.class).in(SINGLETON);

private Module getAuthenticationModule()
{
return switch (buildConfigObject(ThriftMetastoreAuthenticationConfig.class).getAuthenticationType()) {
case NONE -> new NoHiveMetastoreAuthenticationModule();
case KERBEROS -> new KerberosHiveMetastoreAuthenticationModule();
};
}

public static class NoHiveMetastoreAuthenticationModule
implements Module
{
@Override
public void configure(Binder binder)
{
binder.bind(IdentityAwareMetastoreClientFactory.class).to(UgiBasedMetastoreClientFactory.class).in(SINGLETON);
binder.bind(HiveMetastoreAuthentication.class).to(NoHiveMetastoreAuthentication.class).in(SINGLETON);
if (buildConfigObject(ThriftMetastoreAuthenticationConfig.class).getAuthenticationType() == KERBEROS) {
install(new KerberosHiveMetastoreAuthenticationModule());
}
}

Expand All @@ -61,8 +51,10 @@ public static class KerberosHiveMetastoreAuthenticationModule
@Override
public void configure(Binder binder)
{
binder.bind(IdentityAwareMetastoreClientFactory.class).to(TokenFetchingMetastoreClientFactory.class).in(SINGLETON);
binder.bind(HiveMetastoreAuthentication.class).to(KerberosHiveMetastoreAuthentication.class).in(SINGLETON);
newOptionalBinder(binder, IdentityAwareMetastoreClientFactory.class)
.setBinding().to(TokenFetchingMetastoreClientFactory.class).in(SINGLETON);
newOptionalBinder(binder, HiveMetastoreAuthentication.class)
.setBinding().to(KerberosHiveMetastoreAuthentication.class).in(SINGLETON);
configBinder(binder).bindConfig(MetastoreKerberosConfig.class);
}

Expand Down

0 comments on commit bb608ef

Please sign in to comment.