hadoop KerberosUtil 做Kerberos認證
阿新 • • 發佈:2018-05-24
RF bsp ren 工具類 ado void bpa 認證用戶 ()
網上找了一下,自己寫了個KerberosUtil工具類,測試過可以用。
註意這個不是 org.apache.hadoop.security.authentication.util.KerberosUtil類。
public class KerberosUtil { /** * 通過Kerberos認證用戶的,註意keytabPath為本地路徑不是HDFS路徑 * @param conf * @param user user為運行jar的hadoop用戶 * @param keytabPath * @throws IOException*/ public static void AuthenByKerberos(Configuration conf,String user,String keytabPath) throws IOException{ UserGroupInformation.setConfiguration(conf); UserGroupInformation.getCurrentUser().setAuthenticationMethod(AuthenticationMethod.KERBEROS); UserGroupInformation.loginUserFromKeytab(user,keytabPath); }/** * 通過Kerberos認證用戶的,註意keytabPath為本地路徑不是HDFS路徑 * @param conf * @param keytabPath * @throws IOException */ public static void AuthenByKerberos(Configuration conf,String keytabPath) throws IOException{ String user=UserGroupInformation.getLoginUser().getUserName(); AuthenByKerberos(conf,user,keytabPath); }
hadoop KerberosUtil 做Kerberos認證