java - Spring Boot 忽略 Group Authorities 身份验证

标签 java spring spring-mvc spring-security spring-boot

我正在使用“spring boot”应用程序,我想配置安全性以使用 Group Authority authentication . 这看起来很简单,但是当我尝试登录时,Spring 总是检查用户权限而不是组权限。

我的配置类是:

@Configuration()
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    DataSource dataSource;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests()
            .antMatchers("/css/**","/js/**", "/font-awesome/**").permitAll()
            .anyRequest()
            .authenticated().and().formLogin().loginPage("/login")
            .failureUrl("/login?error").permitAll();

    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
         auth.jdbcAuthentication().dataSource(dataSource)
             .usersByUsernameQuery(
                 "select cpf as username, senha as password, ativo as enabled from funcionario where cpf=?")                 
             .groupAuthoritiesByUsername(
                 "select g.id, g.nome, p.nome " +
                 "from grupo g, funcionario_grupo fg, grupo_permissoes gp, permissoes p " +
                 "where gf.username = ? and g.id = gp.grupo_id and g.id = fg.group_id gp.permissoes_id = p.id");
    }
}

我尝试了几种方法来配置 Spring 以使用我的 groupAuthoritiesByUsername,甚至使用 XML,但都没有成功。

有人可以帮助我,我做错了什么?缺少什么?

最佳答案

我无法弄清楚我的配置有什么问题,但最后我可以解决创建自定义 UserDetailService 的问题,我做了一些类似 http://www.sivalabs.in/2014/03/springmvc4-spring-data-jpa.html 的事情。只是改变一点点来满足我的需要

关于java - Spring Boot 忽略 Group Authorities 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29157485/

相关文章:

java - ServletResponse.flushBuffer——它会阻塞直到我的响应被传递吗?

java - 在单个 Java 类的命令行中使用 JUnit 编译和运行测试

java - "The type of a class variable determines which method names can be used with the variable"。这意味着什么?

java - 如何处理Jackson的无限递归

java - Spring Integration LoggingHandler 中的 NPE

spring - 使用非公司认可的第三方软件库

jquery-ui - JTable jQuery 与 Spring MVC 3 集成问题

Java(等于方法)

spring-mvc - Spring 3,具有基于Java的配置和资源访问问题

java - 如何从 Controller 传递多个模型对象以及如何将所有作为命令对象传递到表单 :form in spring mvc?