CustomPasswdAuthenticator.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.primeton.dgs.extractor.adapter.hive;
  2. import org.apache.hadoop.conf.Configuration;
  3. import org.apache.hadoop.hive.conf.HiveConf;
  4. import javax.security.sasl.AuthenticationException;
  5. import org.slf4j.Logger;
  6. /**
  7. * <pre>
  8. *
  9. * Created by zhenqin.
  10. * User: zhenqin
  11. * Date: 2020/8/10
  12. * Time: 18:18
  13. * Vendor: yiidata.com
  14. * To change this template use File | Settings | File Templates.
  15. *
  16. * </pre>
  17. *
  18. * @author zhenqin
  19. */
  20. public class CustomPasswdAuthenticator implements org.apache.hive.service.auth.PasswdAuthenticationProvider {
  21. private Logger LOG = org.slf4j.LoggerFactory.getLogger(CustomPasswdAuthenticator.class);
  22. private static final String HIVE_JDBC_PASSWD_AUTH_PREFIX="hive.jdbc_passwd.auth.%s";
  23. private Configuration conf = null;
  24. @Override
  25. public void Authenticate(String userName, String passwd)
  26. throws AuthenticationException {
  27. LOG.info("user: " + userName + " try login.");
  28. String passwdConf = getConf().get(String.format(HIVE_JDBC_PASSWD_AUTH_PREFIX, userName));
  29. if (passwdConf == null) {
  30. String message = "user's ACL configration is not found. user:" + userName;
  31. LOG.info(message);
  32. throw new AuthenticationException(message);
  33. }
  34. if (!passwd.equals(passwdConf)) {
  35. String message = "user name and password is mismatch. user:" + userName;
  36. throw new AuthenticationException(message);
  37. }
  38. }
  39. public Configuration getConf() {
  40. if (conf == null) {
  41. this.conf = new Configuration(new HiveConf());
  42. }
  43. return conf;
  44. }
  45. public void setConf(Configuration conf) {
  46. this.conf = conf;
  47. }
  48. }