2010-06-29 134 views
3

我所擁有的是:如何配置Spring Security以使用自定義AuthenticationManager實現?

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

據我所知,則使用默認的AuthenticationManager實現。我需要覆蓋它的方法authenticate。有沒有辦法提供我自己的AuthenticationManager實現?

回答

8

您需要先指定一個customAuthenticationProvider,像這樣: -

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

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

然後,您的自定義身份驗證提供可擴展Spring Security的AbstractUserDetailsAuthenticationProvider在那裏你可以把你的自定義的驗證碼。

public class CustomAuthenticationProviderImpl extends AbstractUserDetailsAuthenticationProvider { 
    ... 
} 
+0

哪個(最小)方法需要寫在'CustomAuthenticationProviderImpl'中? – instinct 2014-07-30 13:50:43

相關問題