使用带有两个表的 postgresql db 来验证登录...(用户和权限)
CREATE TABLE users
(
username character(50) NOT NULL,
password character(50) NOT NULL,
enabled boolean NOT NULL,
CONSTRAINT users_pkey PRIMARY KEY (username)
)
CREATE TABLE authorities
(
username character(50) NOT NULL,
authority character(50) NOT NULL,
CONSTRAINT fk_authorities_users FOREIGN KEY (username)
REFERENCES users (username) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
当我尝试执行以下操作时,我做错了什么?
registerAuthentication(AuthenticationManagerBuilder auth){
auth.
jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select username,password,enabled
from users where username = ?")
.authoritiesByUsernameQuery("select username,authority from
authorities where username = ?");
}
Thanks
尝试这个:
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select username as principal, password as credentials, true from users where username = ?")
.authoritiesByUsernameQuery("select username as principal, authority as role from authorities where username = ?")
.rolePrefix("ROLE_");
也许这个源代码可以帮助你:https://github.com/spring-projects/spring-security-javaconfig/blob/master/spring-security-javaconfig/src/test/groovy/org/springframework/security/config/annotation/authentication/NamespaceJdbcUserServiceTests.groovy https://github.com/spring-projects/spring-security-javaconfig/blob/master/spring-security-javaconfig/src/test/groovy/org/springframework/security/config/annotation/authentication/NamespaceJdbcUserServiceTests.groovy
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)