JavaSpring安全性-授权问题
我对Spring Security中的授权有问题。 我正在编写一个简单的组织者应用程序,其中有14个角色,但我正在对角色\u ADMIN进行完整的测试,但它不起作用。键入/admin get's me to/denied page:( 你能在这里找到问题吗JavaSpring安全性-授权问题,java,http,spring-security,Java,Http,Spring Security,我对Spring Security中的授权有问题。 我正在编写一个简单的组织者应用程序,其中有14个角色,但我正在对角色\u ADMIN进行完整的测试,但它不起作用。键入/admin get's me to/denied page:( 你能在这里找到问题吗 protected void configure(HttpSecurity httpSec) throws Exception { httpSec.authorizeRequests().antMatchers("/"
protected void configure(HttpSecurity httpSec) throws Exception {
httpSec.authorizeRequests().antMatchers("/").permitAll().antMatchers("/login").permitAll().antMatchers("/admin/**")
.hasAnyRole("ROLE_ADMIN", "ROLE_PRODUCTION_MANAGER", "ROLE_FOREMAN").antMatchers("/workingpanel")
// Another .antMatchers //
.authenticated().and().csrf().disable().formLogin().loginPage("/login").failureUrl("/login?error=true")
.defaultSuccessUrl("/").usernameParameter("email").passwordParameter("password").and().logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/").and()
.exceptionHandling().accessDeniedPage("/denied");
}
尝试将.antMatchers(“/admin/”).hasAnyRole(“ROLE_admin”,…)更改为.antMatchers(“/admin/”).hasAnyRole(“admin”,…),因为Spring Security会自动为每个角色添加角色前缀。例如
protected void configure(final HttpSecurity http) throws Exception {
...
.antMatchers("/admin/** ").hasAnyRole("ADMIN","USER",...)
...
}请发布一个简单的、可重复的示例:。在尝试转到/admin端点之前,您是否通过表单登录?该端点后面是否有实际的控制器?它看起来像什么?看起来很简单…但如果您不知道…:D谢谢dude:-)工作正常