How to configure Spring Security to use a custom AuthenticationManager implementation?

I have:

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

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

+3
source share
1 answer

First you need to specify customAuthenticationProvider, for example:

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

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

Your own authentication provider can then extend Spring Security AbstractUserDetailsAuthenticationProvider, where you can place your own authentication code.

public class CustomAuthenticationProviderImpl extends AbstractUserDetailsAuthenticationProvider {
    ...
}
+8
source

Source: https://habr.com/ru/post/1752345/


All Articles