2013-02-12 55 views

回答

1

如果使用查詢(假設:userstatus 0已禁用,另一個已啓用):

SELECT a AS username, b AS password, if(userstatus=0,0,1) AS enabled 

您可以在裏面添加另一個if語句。

+0

也需要獲得userstatus值 – Kandy7 2013-02-12 11:54:50

0

怎麼做您的userstatus字段中的值是否表示?它不僅僅是一個二進制啓用/禁用標誌,但它不完全意味着什麼。

檢查您是否可以將這些值映射到UserDetails接口的屬性(已啓用,帳戶已過期,賬戶鎖定,憑證已過期)如果是這樣,則只需在子類中覆蓋JdbcDaoImpl.loadUsersByUsername(),以便根據創建User對象已報名數據庫。然後,配置此定製sublclass作爲UserDetailsService

<authentication-manager> 
    <authentication-provider user-service-ref='myUserDetailsService'/> 
</authentication-manager> 

<beans:bean id="myUserDetailsService" class="YourCustomJdbcDaoImpl"> 
    <beans:property name="dataSource" ref="dataSource"/> 
</beans:bean> 
然後

的Spring Security的其他組件將確保如果啓用了用戶只能得到驗證,沒有上鎖等

+0

0 - 無效的,1-活動的,組2的其中一個 – Kandy7 2013-02-12 10:04:13

+0

在同一個字段中混合帳戶狀態和組成員信息不是最好的主意。根據Spring Security文檔中指定的用戶模式,創建用戶數據庫可能會更好:http://static.springsource.org/spring-security/site/docs/3.1.x/reference/appendix-schema.html 然後你不需要自定義任何東西,默認的實現就可以開箱即用。 – zagyi 2013-02-12 10:23:12

相關問題