i have a problem while connecting to an Active Directory via ldap using plain Java.
If the displayName begins with a , (Comma e.g. ", name") I get a javax.naming.AuthenticationException. The displayName is never used in the application. Context.SECURITY_PRINCIPAL and Context.SECURITY_CREDENTIALS wich I use dont contain any commas.
Can somebody explain this behaviour to me?
Some Stack:
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 525, vece]
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3100)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3046)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2848)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2762)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:329)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:206)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:224)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:167)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:97)
Test-Client (just replace the placeholders):
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
public class LdapClient {
public static void main( String[] args ) {
// URL to Active Directory
String ldapContextUrl = ###URL###;
//Login
String ldapContextUserDn = ###USER###;
//Password
String ldapContextPassword = ###PASSWORD###;
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
environment.put( Context.STATE_FACTORIES, "PersonStateFactory" );
environment.put( Context.OBJECT_FACTORIES, "PersonObjectFactory" );
environment.put( Context.PROVIDER_URL, ldapContextUrl );
environment.put( Context.SECURITY_PRINCIPAL, ldapContextUserDn );
environment.put( Context.SECURITY_CREDENTIALS, ldapContextPassword );
try {
DirContext ctx = new InitialDirContext( environment ); // Error occures here
} catch( NamingException e ) {
e.printStackTrace();
}
}
}
Please dont say: Dont use a displayName like this. I am just interested, why the application behaves like described above. Is it a bug, a feature or something between?
You can also reproduce this problem by using Apache Directory Studio or Websphere Application Server (Security configured against LDAP). So the problem seems to be JVM-independent. Oracle and IBM behave similar.
Thanks in advance!