0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 package org.apache.hive.service.auth;
0019
0020 import javax.security.sasl.AuthenticationException;
0021
0022
0023
0024
0025 public final class AuthenticationProviderFactory {
0026
0027 public enum AuthMethods {
0028 LDAP("LDAP"),
0029 PAM("PAM"),
0030 CUSTOM("CUSTOM"),
0031 NONE("NONE");
0032
0033 private final String authMethod;
0034
0035 AuthMethods(String authMethod) {
0036 this.authMethod = authMethod;
0037 }
0038
0039 public String getAuthMethod() {
0040 return authMethod;
0041 }
0042
0043 public static AuthMethods getValidAuthMethod(String authMethodStr)
0044 throws AuthenticationException {
0045 for (AuthMethods auth : AuthMethods.values()) {
0046 if (authMethodStr.equals(auth.getAuthMethod())) {
0047 return auth;
0048 }
0049 }
0050 throw new AuthenticationException("Not a valid authentication method");
0051 }
0052 }
0053
0054 private AuthenticationProviderFactory() {
0055 }
0056
0057 public static PasswdAuthenticationProvider getAuthenticationProvider(AuthMethods authMethod)
0058 throws AuthenticationException {
0059 if (authMethod == AuthMethods.LDAP) {
0060 return new LdapAuthenticationProviderImpl();
0061 } else if (authMethod == AuthMethods.PAM) {
0062 return new PamAuthenticationProviderImpl();
0063 } else if (authMethod == AuthMethods.CUSTOM) {
0064 return new CustomAuthenticationProviderImpl();
0065 } else if (authMethod == AuthMethods.NONE) {
0066 return new AnonymousAuthenticationProviderImpl();
0067 } else {
0068 throw new AuthenticationException("Unsupported authentication method");
0069 }
0070 }
0071 }