HBASE-23347 Allow custom authentication methods for RPCs; addendum (#1060)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Peter Somogyi 2020-01-21 18:47:13 +01:00
parent c16569996b
commit ac5ac1dcb3
3 changed files with 19 additions and 6 deletions

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.hbase.security.provider; package org.apache.hadoop.hbase.security.provider;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -111,13 +112,14 @@ public final class SaslClientAuthenticationProviders {
Class<? extends AuthenticationProviderSelector> clz = conf.getClass( Class<? extends AuthenticationProviderSelector> clz = conf.getClass(
SELECTOR_KEY, BuiltInProviderSelector.class, AuthenticationProviderSelector.class); SELECTOR_KEY, BuiltInProviderSelector.class, AuthenticationProviderSelector.class);
try { try {
AuthenticationProviderSelector selector = clz.newInstance(); AuthenticationProviderSelector selector = clz.getConstructor().newInstance();
selector.configure(conf, providers); selector.configure(conf, providers);
if (LOG.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOG.trace("Loaded ProviderSelector {}", selector.getClass()); LOG.trace("Loaded ProviderSelector {}", selector.getClass());
} }
return selector; return selector;
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
throw new RuntimeException("Failed to instantiate " + clz + throw new RuntimeException("Failed to instantiate " + clz +
" as the ProviderSelector defined by " + SELECTOR_KEY, e); " as the ProviderSelector defined by " + SELECTOR_KEY, e);
} }
@ -148,8 +150,9 @@ public final class SaslClientAuthenticationProviders {
// Instantiate it // Instantiate it
SaslClientAuthenticationProvider provider; SaslClientAuthenticationProvider provider;
try { try {
provider = (SaslClientAuthenticationProvider) clz.newInstance(); provider = (SaslClientAuthenticationProvider) clz.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
LOG.warn("Failed to instantiate SaslClientAuthenticationProvider {}", clz, e); LOG.warn("Failed to instantiate SaslClientAuthenticationProvider {}", clz, e);
continue; continue;
} }

View File

@ -96,6 +96,10 @@ public class TestSaslClientAuthenticationProviders {
static class ConflictingProvider1 implements SaslClientAuthenticationProvider { static class ConflictingProvider1 implements SaslClientAuthenticationProvider {
static final SaslAuthMethod METHOD1 = new SaslAuthMethod( static final SaslAuthMethod METHOD1 = new SaslAuthMethod(
"FOO", (byte)12, "DIGEST-MD5", AuthenticationMethod.SIMPLE); "FOO", (byte)12, "DIGEST-MD5", AuthenticationMethod.SIMPLE);
public ConflictingProvider1() {
}
@Override public SaslAuthMethod getSaslAuthMethod() { @Override public SaslAuthMethod getSaslAuthMethod() {
return METHOD1; return METHOD1;
} }
@ -118,6 +122,10 @@ public class TestSaslClientAuthenticationProviders {
static class ConflictingProvider2 implements SaslClientAuthenticationProvider { static class ConflictingProvider2 implements SaslClientAuthenticationProvider {
static final SaslAuthMethod METHOD2 = new SaslAuthMethod( static final SaslAuthMethod METHOD2 = new SaslAuthMethod(
"BAR", (byte)12, "DIGEST-MD5", AuthenticationMethod.SIMPLE); "BAR", (byte)12, "DIGEST-MD5", AuthenticationMethod.SIMPLE);
public ConflictingProvider2() {
}
@Override public SaslAuthMethod getSaslAuthMethod() { @Override public SaslAuthMethod getSaslAuthMethod() {
return METHOD2; return METHOD2;
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.security.provider; package org.apache.hadoop.hbase.security.provider;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Optional; import java.util.Optional;
import java.util.ServiceLoader; import java.util.ServiceLoader;
@ -120,9 +121,10 @@ public final class SaslServerAuthenticationProviders {
try { try {
SaslServerAuthenticationProvider provider = SaslServerAuthenticationProvider provider =
(SaslServerAuthenticationProvider) clz.newInstance(); (SaslServerAuthenticationProvider) clz.getConstructor().newInstance();
addProviderIfNotExists(provider, providers); addProviderIfNotExists(provider, providers);
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
LOG.warn("Failed to instantiate {}", clz, e); LOG.warn("Failed to instantiate {}", clz, e);
} }
} }