views:

29

answers:

1

What I have is:

<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="securityService"/>
</authentication-manager>

As I understand, the default AuthenticationManager implementation is used. I need to override its method authenticate. Is there a way to provide my own AuthenticationManager implementation?

+1  A: 

You need to specify a customAuthenticationProvider first, like this:-

<bean id="customAuthenticationProvider" class="your.project.CustomAuthenticationProviderImpl">
    <property name="userDetailsService" ref="userDetailsService" />
    ...
</bean>

<security:authentication-manager>
    <security:authentication-provider ref="customAuthenticationProvider" />
</security:authentication-manager>

Then, your custom authentication provider can extends Spring Security's AbstractUserDetailsAuthenticationProvider where you can place your custom authentication code.

public class CustomAuthenticationProviderImpl extends AbstractUserDetailsAuthenticationProvider {
    ...
}
limc