Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在不使用“权限”的情况下使用Spring Security的JDBC身份验证?_Spring_Postgresql_Spring Security - Fatal编程技术网

如何在不使用“权限”的情况下使用Spring Security的JDBC身份验证?

如何在不使用“权限”的情况下使用Spring Security的JDBC身份验证?,spring,postgresql,spring-security,Spring,Postgresql,Spring Security,我对当局有意见 原因:PreparedStatementCallback;错误的SQL语法[select] 用户名,来自授权机构的授权,其中用户名=?];嵌套 异常为org.postgresql.util.PSQLException:错误:关系 当局不存在职位:32 我不想实现权限,但不知道如何在Spring的JavaConfig中禁用它 @Override protected void configure(AuthenticationManagerBuilder auth) t

我对当局有意见

原因:PreparedStatementCallback;错误的SQL语法[select] 用户名,来自授权机构的授权,其中用户名=?];嵌套 异常为org.postgresql.util.PSQLException:错误:关系 当局不存在职位:32

我不想实现权限,但不知道如何在Spring的JavaConfig中禁用它

@Override
protected void configure(AuthenticationManagerBuilder auth)
        throws Exception {
    auth.jdbcAuthentication()
            .dataSource(dataSource)
            .usersByUsernameQuery(
                    "select username,password,'true' as enabled from users where username=?")
            .passwordEncoder(new ShaPasswordEncoder());
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().httpBasic();
}

据我所知,您不能在Spring Security中使用JavaConfig停用权限机制,但您可以覆盖用于获取权限数据的查询以实现相同的效果

当使用SpringSecurity的JDBC身份验证时,它会对检索身份验证数据的数据库方案做出某些假设。您已经通过调用usersByUsernameQuery覆盖了示例中用于获取用户数据的查询

我成功地禁用了整个权限检查,方法是覆盖查询以获取权限数据,如Craig Walls在Spring in Action中所述:

@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder)
        throws Exception {

    authenticationManagerBuilder.jdbcAuthentication().dataSource(dataSource)
            .usersByUsernameQuery(
                    "SELECT username, password, enabled FROM users WHERE username=?")
            .authoritiesByUsernameQuery(
                    "SELECT username, 'ROLE_USER' FROM users WHERE username=?");
}