123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package com.yiidata.amc.common.principal;
- import org.apache.commons.lang.StringUtils;
- import org.apache.hadoop.conf.Configuration;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- /**
- *
- *
- *
- * <pre>
- *
- * Created by zhenqin.
- * User: zhenqin
- * Date: 2018/4/23
- * Time: 10:43
- * Vendor: yiidata.com
- * To change this template use File | Settings | File Templates.
- *
- * </pre>
- *
- * @author zhenqin
- */
- public class HadoopPrincipalFactory {
- /**
- * Hadoop 的认证方式
- */
- public static final String HADOOP_SECUROTY_AUTH = "hadoop.security.auth";
- /**
- * 无认证的值
- */
- public static final String HADOOP_SECUROTY_AUTH_NONE = "none";
- private static Logger LOG = LoggerFactory.getLogger(HadoopPrincipal.class);
- /**
- * 获取 加密模式
- * @param userPrincipal
- * @param userKeytabPath
- * @param krb5ConfPath
- * @return
- */
- public static HadoopPrincipal getHadoopPrincipal(
- final String userPrincipal,
- final String userKeytabPath,
- final String krb5ConfPath) {
- if(StringUtils.isBlank(userPrincipal)) {
- LOG.info("use HadoopPrincipal class: " + NonHadoopPrincipal.class.getName());
- return new NonHadoopPrincipal();
- }
- LOG.info("use HadoopPrincipal class: " + KerborsHadoopPrincipal.class.getName());
- return new KerborsHadoopPrincipal(userPrincipal, userKeytabPath, krb5ConfPath);
- }
- /**
- * 获取 加密模式
- * @param conf Hadoop Conf
- * @return
- */
- public static HadoopPrincipal getHadoopPrincipal(Configuration conf) {
- String auth = conf.get(HADOOP_SECUROTY_AUTH, HADOOP_SECUROTY_AUTH_NONE);
- if(StringUtils.isBlank(auth) || HADOOP_SECUROTY_AUTH_NONE.equals(auth)) {
- LOG.info("use HadoopPrincipal class: " + NonHadoopPrincipal.class.getName());
- return new NonHadoopPrincipal();
- }
- LOG.info("use HadoopPrincipal class: " + KerborsHadoopPrincipal.class.getName());
- final String userPrincipal = conf.get("hadoop.security.auth.principal");
- final String userKeytabPath = conf.get("hadoop.security.auth.keytab");
- final String krb5ConfPath = conf.get("hadoop.security.auth.krb5Path");
- return new KerborsHadoopPrincipal(userPrincipal, userKeytabPath, krb5ConfPath);
- }
- }
|