0

My customer is using AD , and I need to authenticate my user in java via LDAP, I wrote this simple code

 Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://10.254.***.***);
    env.put(Context.SECURITY_AUTHENTICATION, "Simple");
    env.put(Context.SECURITY_PRINCIPAL, "cn=s***.u***,ou=All Users,dc=p***,dc=net,dc=**");
    env.put(Context.SECURITY_CREDENTIALS, "******");
     
    try {
        DirContext ctx = new InitialDirContext(env);
        System.out.println("connected");
        System.out.println(ctx.getEnvironment());
         
        // do something useful with the context...
     
        ctx.close();
     
    } catch (AuthenticationNotSupportedException ex) {
        System.out.println("The authentication is not supported by the server"+ex);
    } catch (AuthenticationException ex) {
        System.out.println("incorrect password or username"+ex);
    } *catch (NamingException ex) {
        System.out.println("error when trying to create the context"+ex);
    }
        }*

This code throw following exception

incorrect password or usernamejavax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090453, comment: AcceptSecurityContext error r, data 52e, v3839 ]

however I can connect from the same user via Ad Explorer

enter image description here

enter image description here

As i am able to connect with Ad Explorer , Should be able to connect with Java application as well.

What is wrong inside my code , any help

EDIT Customer is having 2 ADs, AD1, AD2 and AD1 has trusted relation with AD2. The user I am trying to login is part of AD2, but customer don't allow to direct communicate with AD2,So I need to communicate via AD1 to authenticate my user who is part of AD2.

Malik
  • 585
  • 2
  • 6
  • 13
  • Any special charter on the password that is not correctly escaped? – Max Sep 29 '21 at 11:35
  • @Max , we have special character in the password @ , do we need some special treatment for the special character's – Malik Sep 29 '21 at 16:32

1 Answers1

0

Is this problem still unsolved? Only differences I can see from what I use here is that on the SECURITY_AUTHENTICATION we use "simple", with no capital letters at all, and we add the port to the provider URL (URL:389 in your case).