0
votes

I'm trying to configure the Spring Security with LDAP Authentication, but I need to get the username for all login requests.

I configure my spring-security.xml who points to my MyCustomAuthenticationProvider class. I think the configuration is correct, but in runtime, the Spring first try to login with his own LdapAuthenticationProvider. After fails, the request is sent to my customized class. I set the Spring Security's log level to Debug to see that happening.

[#|DEBUG| date=2015-06-02 time=10:48:11.425 thread=http-nio-8080-exec-1 controller=o.s.s.w.a.UsernamePasswordAuthenticationFilter Request is to process authentication |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.428 thread=http-nio-8080-exec-1 controller=o.s.s.authentication.ProviderManager Authentication attempt using org.springframework.security.ldap.authentication.LdapAuthenticationProvider |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.428 thread=http-nio-8080-exec-1 controller=o.s.s.l.a.LdapAuthenticationProvider Processing authentication request for user: admin |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.429 thread=http-nio-8080-exec-1 controller=o.s.s.l.search.FilterBasedLdapUserSearch Searching for user 'admin', with user search [ searchFilter: 'uid={0}', searchBase: 'ou=people', scope: subtree, searchTimeLimit: 0, derefLinkFlag: false ] |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.660 thread=http-nio-8080-exec-1 controller=o.s.s.ldap.SpringSecurityLdapTemplate Searching for entry under DN 'dc=springframework,dc=org', base = 'ou=people', filter = 'uid={0}' |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.660 thread=http-nio-8080-exec-1 controller=o.s.s.authentication.ProviderManager Authentication attempt using br.com.project.auth.MyCustomAuthenticationProvider |#]
[#|INFO | date=2015-06-02 time=10:48:11.668 thread=http-nio-8080-exec-1 controller=b.c.p.auth.MyCustomAuthenticationProvider =========================> User admin is trying to login. |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.668 thread=http-nio-8080-exec-1 controller=o.s.s.l.search.FilterBasedLdapUserSearch Searching for user 'admin', with user search [ searchFilter: '(uid={0})', searchBase: 'ou=people', scope: subtree, searchTimeLimit: 0, derefLinkFlag: false ] |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.685 thread=http-nio-8080-exec-1 controller=o.s.s.ldap.SpringSecurityLdapTemplate Searching for entry under DN 'dc=springframework,dc=org', base = 'ou=people', filter = '(uid={0})' |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.686 thread=http-nio-8080-exec-1 controller=o.s.s.w.a.UsernamePasswordAuthenticationFilter Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.686 thread=http-nio-8080-exec-1 controller=o.s.s.w.a.UsernamePasswordAuthenticationFilter Updated SecurityContextHolder to contain null Authentication |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.686 thread=http-nio-8080-exec-1 controller=o.s.s.w.a.UsernamePasswordAuthenticationFilter Delegating to authentication failure handler org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler@64f289f7 |#]
[#|DEBUG| date=2015-06-02 time=10:48:11.693 thread=http-nio-8080-exec-1 controller=o.s.s.w.a.SimpleUrlAuthenticationFailureHandler Redirecting to /login?failed |#]

How can I set to Spring use my customized class instead of his deafaul LDAP authentication provider?

1
I forgot to mention: The request was a fail attempt because a successful request not even pass into my customized class.Efraim Ferreira

1 Answers

0
votes

Finally I found the solution.

in the spring-security.xml, I remove the configuration

<security:ldap-authentication-provider
        group-search-filter="member={0}"
        group-search-base="ou=groups"
        user-search-base="ou=people"
        user-search-filter="uid={0}"
    />