Spring security 3.1 authentication LDAP with md5 -
when try authenticate using spring authentication manager, says "bad credentials":
authentication request = new usernamepasswordauthenticationtoken("john", "johnldap"); result = authenticationmanager.authenticate(request);
here 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" can connect successfully:
ldapsearch -d "uid=john,ou=people,dc=example,dc=com" -w johnldap -l "objectclass=*"
at first time thought issue we've tell spring md5 of password before call ldap. add 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 add tag says:
ldap: error code 34 - invalid dn]
what's wrong here?
if remember correctly user-dn-pattern
should not contain root dn, automatically appended. try using:
user-dn-pattern="uid={0},ou=people">
and don't think need password-encoder
if want simple bind authentication.
Comments
Post a Comment