HBASE-23347 Allow custom authentication methods for RPCs; addendum (#1060)
Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
parent
569ac1232a
commit
00e64d83e8
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue