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 committed by GitHub
parent 569ac1232a
commit 00e64d83e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View File

@ -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;
@ -111,13 +112,14 @@ public final class SaslClientAuthenticationProviders {
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);
}
@ -148,8 +150,9 @@ public final class SaslClientAuthenticationProviders {
// 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;
}

View File

@ -96,6 +96,10 @@ public class TestSaslClientAuthenticationProviders {
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;
}
@ -118,6 +122,10 @@ public class TestSaslClientAuthenticationProviders {
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;
}

View File

@ -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;
@ -120,9 +121,10 @@ public final class SaslServerAuthenticationProviders {
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);
}
}