Skip to content

Commit

Permalink
HBASE-23347 Allow custom authentication methods for RPCs; addendum (a…
Browse files Browse the repository at this point in the history
…pache#1060)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
  • Loading branch information
petersomogyi authored and thangTang committed Apr 16, 2020
1 parent 541defe commit 4a07f2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.security.provider;

import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -111,13 +112,14 @@ static AuthenticationProviderSelector instantiateSelector(Configuration conf,
Class<? extends AuthenticationProviderSelector> clz = conf.getClass(
SELECTOR_KEY, BuiltInProviderSelector.class, AuthenticationProviderSelector.class);
try {
AuthenticationProviderSelector selector = clz.newInstance();
AuthenticationProviderSelector selector = clz.getConstructor().newInstance();
selector.configure(conf, providers);
if (LOG.isTraceEnabled()) {
LOG.trace("Loaded ProviderSelector {}", selector.getClass());
}
return selector;
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
throw new RuntimeException("Failed to instantiate " + clz +
" as the ProviderSelector defined by " + SELECTOR_KEY, e);
}
Expand Down Expand Up @@ -148,8 +150,9 @@ static void addExplicitProviders(Configuration conf,
// Instantiate it
SaslClientAuthenticationProvider provider;
try {
provider = (SaslClientAuthenticationProvider) clz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
provider = (SaslClientAuthenticationProvider) clz.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
LOG.warn("Failed to instantiate SaslClientAuthenticationProvider {}", clz, e);
continue;
}
Expand Down
Expand Up @@ -96,6 +96,10 @@ public void testDifferentConflictingImplementationsFail() {
static class ConflictingProvider1 implements SaslClientAuthenticationProvider {
static final SaslAuthMethod METHOD1 = new SaslAuthMethod(
"FOO", (byte)12, "DIGEST-MD5", AuthenticationMethod.SIMPLE);

public ConflictingProvider1() {
}

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

public ConflictingProvider2() {
}

@Override public SaslAuthMethod getSaslAuthMethod() {
return METHOD2;
}
Expand Down
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.security.provider;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Optional;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -120,9 +121,10 @@ static void addExtraProviders(Configuration conf,

try {
SaslServerAuthenticationProvider provider =
(SaslServerAuthenticationProvider) clz.newInstance();
(SaslServerAuthenticationProvider) clz.getConstructor().newInstance();
addProviderIfNotExists(provider, providers);
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
LOG.warn("Failed to instantiate {}", clz, e);
}
}
Expand Down

0 comments on commit 4a07f2d

Please sign in to comment.