hive 认证

来源:互联网 发布:淘宝平均停留时间 编辑:程序博客网 时间:2024/05/22 05:38
Pluggable custom authentication: Pluggable custom authentication provides a custom authentication provider for HiveServer2. To enable it, confgure the
settings as follows:
<property>
<name>hive.server2.authentication</name>
<value>CUSTOM</value>
</property>
<property>
<name>hive.server2.custom.authentication.class</name>
<value>pluggable-auth-class-name</value>
<description> Custom authentication class name, such as
com.packtpub.hive.essentials.hiveudf.customAuthenticator
</description>
</property>



The following is a sample of a customized class that implements theorg.apache.hive.service.auth.PasswdAuthenticationProviderinterface.The overridde Authenticatemethod has the core logic of how to authenticate a username and password. Make sure to copy the compiled JAR fle to$HIVE_HOME/lib/ so that the preceding settings can work.
customAuthenticator.java
package com.packtpub.hive.essentials.hiveudf;
import java.util.Hashtable;
import javax.security.sasl.AuthenticationException;
import org.apache.hive.service.auth.PasswdAuthenticationProvider;
/*
* The customized class for HiveServer2 authentication
*/
public class customAuthenticator implements PasswdAuthenticationProvider {
Hashtable<String, String> authHashTable = null;
public customAuthenticator () {
authHashTable = new Hashtable<String, String>();
authHashTable.put("user1", "passwd1");
authHashTable.put("user2", "passwd2");
}
@Override
public void Authenticate(String user, String password) throws AuthenticationException {
String storedPasswd = authHashTable.get(user);
if (storedPasswd != null && storedPasswd.equals(password))
return;
throw new AuthenticationException("customAuthenticatorException: Invalid user");
}
}

原创粉丝点击