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>
