This code snippet works for correct user/password combinations with the values I use to configure the properties, i.e. no exceptions are thrown/catched.
When i provide an invalid user/password combination, I get an AuthenticationException as expected. However, on two other machines, I don't get any Exception for a wrong password combination, I do get an exception correctly for a wrong user though.
// set properties for our connection and provider
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
properties.put(Context.PROVIDER_URL, providerUrl);
properties.put(Context.REFERRAL, "ignore" );
properties.put(Context.SECURITY_AUTHENTICATION, "simple");
// set properties for authentication
properties.put(Context.SECURITY_PRINCIPAL, distinguishedName);
properties.put(Context.SECURITY_CREDENTIALS, password);
try {
new InitialDirContext( properties );
// success
} catch (AuthenticationException e) {
// unable to validate user
} catch (NamingException e) {
// unable to connect to LDAP server
} catch (Exception e) {
// does not happen during testing
}
How can this be?
It's a Microsoft Windows 2003 LDAP Server I'm using to test this.