public interface PasswdAuthenticationProvider { /** * The Authenticate method is called by the HiveServer2 authentication layer * to authenticate usersfor their requests. * If a user is to be granted, return nothing/throw nothing. * When a user is to be disallowed, throw an appropriate {@link AuthenticationException}. * * For an example implementation, see {@link LdapAuthenticationProviderImpl}. * * @param user - The username received over the connection request * @param password - The password received over the connection request * @throws AuthenticationException - When a user is found to be * invalid by the implementation */ void Authenticate(String user, String password) throws AuthenticationException;}
接口實現代碼: 將代碼打包為jar包,放在hive根目錄的lib目錄下
package org.apache.hadoop.hive.contrib.auth;import javax.security.sasl.AuthenticationException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hive.conf.HiveConf;import org.slf4j.Logger;public class CustomPasswdAuthenticator implements org.apache.hive.service.auth.PasswdAuthenticationProvider{private Logger LOG = org.slf4j.LoggerFactory.getLogger(CustomPasswdAuthenticator.class);private static final String HIVE_JDBC_PASSWD_AUTH_PREFIX="hive.jdbc_passwd.auth.%s";private Configuration conf=null;@Overridepublic void Authenticate(String userName, String passwd) throws AuthenticationException { LOG.info("user: "+userName+" try login."); String passwdConf = getConf().get(String.format(HIVE_JDBC_PASSWD_AUTH_PREFIX, userName)); if(passwdConf==null){ String message ="user's ACL configration is not found. user:"+userName; LOG.info(message); throw new AuthenticationException(message);} if(!passwd.equals(passwdConf)){ String message ="user name and password is mismatch. user:"+userName; throw new AuthenticationException(message);}} public Configuration getConf(){ if(conf==null){ this.conf=new Configuration(new HiveConf());}return conf;} public void setConf(Configuration conf){ this.conf=conf;}}