diff --git a/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java b/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java index 5342214..d8fe0be 100644 --- a/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java +++ b/service/src/java/org/apache/hive/service/auth/LdapAuthenticationProviderImpl.java @@ -32,18 +32,24 @@ private final String ldapURL; private final String baseDN; private final String ldapDomain; + private final String securityProtocol; - LdapAuthenticationProviderImpl () { - HiveConf conf = new HiveConf(); + LdapAuthenticationProviderImpl(HiveConf conf) { this.ldapURL = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_PLAIN_LDAP_URL); this.baseDN = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_PLAIN_LDAP_BASEDN); this.ldapDomain = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_PLAIN_LDAP_DOMAIN); + this.securityProtocol = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_PLAIN_LDAP_SECURITY_PROTOCOL); } @Override public void Authenticate(String user, String password) throws AuthenticationException { - + if(user == null || user.length() == 0) { + throw new AuthenticationException("Username cannot be blank"); + } + if(password == null || password.length() == 0) { + throw new AuthenticationException("Password cannot be blank"); + } Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapURL); @@ -51,7 +57,9 @@ public void Authenticate(String user, String password) // If the domain is supplied, then append it. LDAP providers like Active Directory // use a fully qualified user name like foo@bar.com. if (ldapDomain != null) { - user = user + "@" + ldapDomain; + if(!user.contains("@")) { + user = user + "@" + ldapDomain; + } } // setup the security principal @@ -64,7 +72,9 @@ public void Authenticate(String user, String password) env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, bindDN); env.put(Context.SECURITY_CREDENTIALS, password); - + if(securityProtocol != null){ + env.put(Context.SECURITY_PROTOCOL, securityProtocol); + } try { // Create initial context DirContext ctx = new InitialDirContext(env); @@ -74,5 +84,4 @@ public void Authenticate(String user, String password) } return; } - }