Java – LDAP user password authentication using JNDI
•
Java
public static void main(String[] args)
public static void main(String[] args) { String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory"; String MY_HOST = "ldap://Localhost:1389"; String MGR_DN = "cn=John,ou=Users,o=IT,dc=QuizPortal"; String MGR_PW = "password"; //Identify service provider to use Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,INITCTX); env.put(Context.PROVIDER_URL,MY_HOST); env.put(Context.Security_AUTHENTICATION,"simple"); env.put(Context.Security_PRINCIPAL,MGR_DN); env.put(Context.Security_CREDENTIALS,MGR_PW); try { // Create the initial directory context InitialDirContext initialContext = new InitialDirContext(env); System.out.println("Context Sucessfully Initialized"); } catch(Exception e) { System.err.println(e); } }
I would like to ask when Mgr will be_ DN = "CN = John, Ou = users, o = it, DC = quizportal" is set to Mgr_ DN =“uid = 103,dc = QuizPortal”. Basically, from CN to uid, I will encounter an error
javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
When I am designated CN = John but not uid = 103, I am authenticated Am I not allowed to specify with uid?
Solution
You must specify a dn or distinguished name This is the name that the user binds in the directory You cannot select only any attribute chain If your user is bound through the "CN" attribute, only the "CN" attribute is part of the DN
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码