Back to home page

OSCL-LXR

 
 

    


0001 /**
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements.  See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership.  The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License.  You may obtain a copy of the License at
0009  *
0010  *     http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing, software
0013  * distributed under the License is distributed on an "AS IS" BASIS,
0014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * See the License for the specific language governing permissions and
0016  * limitations under the License.
0017  */
0018 package org.apache.hive.service.auth;
0019 
0020 import javax.security.sasl.AuthenticationException;
0021 
0022 /**
0023  * This class helps select a {@link PasswdAuthenticationProvider} for a given {@code AuthMethod}.
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 }