Spring security 使用spring security:WebSecurityConfigureAdapter:auth.jdbcAuthentication().usersByUsernameQuery:查询字符串应该是什么样的?

Spring security 使用spring security:WebSecurityConfigureAdapter:auth.jdbcAuthentication().usersByUsernameQuery:查询字符串应该是什么样的?,spring-security,spring-jdbc,Spring Security,Spring Jdbc,使用带有两个表的postgresql db对登录进行身份验证…(用户和权限) 当我尝试做以下事情时,我做错了什么 registerAuthentication(AuthenticationManagerBuilder auth){ auth. jdbcAuthentication() .dataSource(dataSource) .usersByUsernameQuery("select username,password,enab

使用带有两个表的postgresql db对登录进行身份验证…(用户和权限)

当我尝试做以下事情时,我做错了什么

registerAuthentication(AuthenticationManagerBuilder auth){

auth.
      jdbcAuthentication()
            .dataSource(dataSource)
            .usersByUsernameQuery("select username,password,enabled 
                 from users where username = ?")
            .authoritiesByUsernameQuery("select username,authority from 
                 authorities where username = ?");

}
谢谢

试试这个:

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_");
可能此源代码可以帮助您:

确保已将记录插入表中。必须在两个表中至少插入一条记录。
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_");