首页 > 其他 > 详细

hadoop KerberosUtil 做Kerberos认证

时间:2018-05-24 14:20:07      阅读:185      评论:0      收藏:0      [点我收藏+]

网上找了一下,自己写了个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认证

原文:https://www.cnblogs.com/yanghaolie/p/9082517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!