我正在使用“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/