using my own FORM_LOGIN_FILTER
<http auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint"> <custom-filter position="FORM_LOGIN_FILTER" ref="myAuthenticationFilter" /> </http> <beans:bean id="myAuthenticationFilter" class="MyAuthenticationFilter"> <beans:property name="authenticationManager" ref="authenticationManager"/> <beans:property name="authenticationFailureHandler" ref="failureHandler"/> <beans:property name="authenticationSuccessHandler" ref="successHandler"/> </beans:bean> <beans:bean id="successHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> <beans:property name="defaultTargetUrl" value="/login.spring"/> </beans:bean> <beans:bean id="failureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> <beans:property name="defaultFailureUrl" value="/login.spring?login_error=1"/> </beans:bean> <beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> <beans:property name="loginFormUrl" value="/login.spring"/> </beans:bean>
Creating a custom authentication with Acegi/Spring Security - Stack Overflow
-
Implement a custom
AuthenticationProviderwhich gets all your authentication information from theAuthentication:getCredentials(),getDetails(), andgetPrincipal().Tie it into your Spring Security authentication mechanism using the following configuration snippet:
<bean id="myAuthenticationProvider" class="com.example.MyAuthenticationProvider"> <security:custom-authentication-provider /> </bean> -
This step is optional, if you can find a suitable one from standard implementations. If not, implement a class extending the
Authenticationinterface on which you can put your authentication parameters:(e.g. a user identifier, timestamp, signature, etc.) -
Extend a custom
SpringSecurityFilterwhich ties the above two classes together. For example, the Filter might get theAuthenticationManagerand callauthenticate()using your implementation ofAuthenticationas input.You can extend AbstractAuthenticationProcessingFilter as a start.
You can reference UsernamePasswordAuthenticationFilter which extends
AbstractAuthenticationProcessingFilter.UsernamePasswordAuthenticationFilterimplements the standard Username/Password Authentication. -
Configure your Spring Security to add or replace the standard
AUTHENTICATION_PROCESSING_FILTER. For Spring Security Filter orders, seehttp://static.springsource.org/spring-security/site/docs/3.0.x/reference/ns-config.html#filter-stackHere is a configuration snippet for how to replace it with your implementation:
<beans:bean id="myFilter" class="com.example.MyAuthenticationFilter"> <custom-filter position="AUTHENTICATION_PROCESSING_FILTER"/> </beans:bean>
