When we try to authenticate using the spring authentication manager, its says "bad credentials":
Authentication request = new UsernamePasswordAuthenticationToken("john", "johnldap");
result = authenticationManager.authenticate(request);
Here the SecurityApplicationContext.xml file:
<authentication-manager alias="authenticationManager">
<ldap-authentication-provider server-ref="ldapLocal"
user-dn-pattern="uid={0},ou=People,dc=example,dc=com">
</ldap-authentication-provider>
</authentication-manager>
<ldap-server url="ldap://127.0.0.1:389/dc=example,dc=com" manager-dn="admin" manager-password="xxxxxxxx" id="ldapLocal" />
However using "ldapsearch" we can connect successfully:
ldapsearch -D "uid=john,ou=People,dc=example,dc=com" -w johnldap -L "objectClass=*"
At first time we thought the issue was that we've to tell spring to do a md5 of the password before call LDAP. So we add it to the applicationSecurtyContext.xml:
<beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder">
</beans:bean>
<authentication-manager alias="authenticationManager">
<ldap-authentication-provider server-ref="ldapLocal"
user-dn-pattern="uid={0},ou=People,dc=example,dc=com">
<password-compare>
<password-encoder ref="passwordEncoder"> </password-encoder>
</password-compare>
</ldap-authentication-provider>
</authentication-manager>
<ldap-server url="ldap://127.0.0.1:389/dc=example,dc=com" manager-dn="admin" manager-password="xxxxxxxx" id="ldapLocal" />
But when we add the tag it says:
LDAP: error code 34 - invalid DN]
What's wrong here?