这有点接近我之前的问题,但我一直在查找如何做到这一点
applicationContext-security.xml中的当前代码:
<authentication-manager alias="authenticationManager">
<!-- DAO Based Security -->
<authentication-provider>
<password-encoder hash="sha-256" />
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="SELECT user_name AS username, user_password AS password, enabled FROM user where user_name=?"
authorities-by-username-query="SELECT user_name as username, R.name as authority FROM user U, roles R WHERE U.roles = R.Id AND user_name=?"/>
</authentication-provider>
</authentication-manager>
我想改变的是:
<authentication-manager alias="authenticationManager">
<!-- DAO Based Security -->
<authentication-provider>
<password-encoder hash="sha-256" />
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="SELECT user_name AS username, user_password AS password, id, location, userFirstName, userLastName, enabled FROM user where user_name=?"
authorities-by-username-query="SELECT user_name as username, R.name as authority FROM user U, roles R WHERE U.roles = R.Id AND user_name=?"/>
</authentication-provider>
</authentication-manager>
基本上我想从数据库中检索另外4个字段
我目前的问题是我不知道我需要做什么,我试图自定义userDetails和userDetailsService但我似乎无法使用此网站的代码http://www.theserverside.com/tip/-Spring-Security-Customizing-Your-User-and-Authorization-in
答案 0 :(得分:3)
您不能使用原始org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
(那就是jdbc-user-service
后面的类)。您需要对其进行子类化,或者需要实现完整的UserDetailsService
。