Roman
Roman

Reputation: 66156

How can I configure Spring Security to use custom AuthenticationManager implementation?

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?

Upvotes: 3

Views: 10094

Answers (1)

limc
limc

Reputation: 40168

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 {
    ...
}

Upvotes: 8

Related Questions