2012-10-19 66 views
4

我子類org.springframework.security.core.userdetails.User,在我的構造函數我叫查證件登錄失敗時。力彈簧安全之前賬戶狀態標誌

我遇到的問題是,如果我將accountNotLocked設置爲false,則會顯示帳戶鎖定錯誤消息,無論密碼是否正確,都會顯示此問題。如果首先彈出驗證的憑證,然後啓用帳戶NonExpired,credentialsNonExpired和accountNonLocked標誌,我會更喜歡它。通過這種方式,只有獲得憑據的用戶纔會被通知他們的賬戶被鎖定。

有沒有辦法強制春天做到這一點?

+1

理想情況下,我建議不要這樣做,因爲最好先檢查標誌而不是密碼(因爲這可以用來猜測正確的密碼) –

回答

5

我假設你使用的是最流行的DaoAuthenticationProvider,並且問題在於UserDetailsChecker這個類的默認實現。也就是說,移動DaoAuthenticationProvider.additionalAuthenticationChecks後的所有支票應該足以解決您的問題。嘗試以下配置:

<authentication-manager alias="authenticationManager"> 
    <authentication-provider ref="daoAuthenticationProvider" /> 
</authentication-manager> 

<bean id="daoAuthenticationProvider" 
     class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"> 
    <property name="userDetailsService" ref="userDetailsService"/> 
    <property name="passwordEncoder" ref="passwordEncoder"/> 
    <property name="preAuthenticationChecks" 
     class="com.example.NullUserDetailsChecker"/> 
    <property name="postAuthenticationChecks" 
     class="org.springframework.security.authentication.AccountStatusUserDetailsChecker"/> 
</bean> 

其中com.example.NullUserDetailsCheckernull object pattern實施UserDetailsChecker(具有什麼也不做無效檢查方法)。