How to make extra validation in Spring Security login form?

后端 未结 3 1221
谎友^
谎友^ 2021-01-01 06:04

I wonder how to make extra validation on login form before it will be processed by Spring Security. I\'m thinking about some LoginController, LoginForm bean, but i don\'t kn

3条回答
  •  失恋的感觉
    2021-01-01 06:49

    You could subclass UsernamePasswordAuthenticationFilter:

    http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/authentication/UsernamePasswordAuthenticationFilter.html

    You could override the attemptAuthentication() method, have it call super.attemptAuthentication(), and if that returns a non-null Authentication object, perform your additional work (to see if the user checked the box).

    http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/authentication/UsernamePasswordAuthenticationFilter.html#attemptAuthentication(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

    The docs for how to specify your customer filter are here:

    http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ns-config.html#ns-custom-filters

提交回复
热议问题