在SpringSecurity中,我对授权有问题。我正在编写一个简单的组织者应用程序,其中有14个角色,但我正在ROLE_ADMIN上进行整个测试,但没有成功。输入/admin‘here到/denied页面:(您在这里发现问题了吗?
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");
}发布于 2020-03-29 17:41:07
试着改变.antMatchers("/admin/").hasAnyRole("ROLE_ADMIN",.)致.antMatchers("/admin/").hasAnyRole("ADMIN",.)当Security自动向每个角色添加角色前缀时。例如
protected void configure(final HttpSecurity http) throws Exception {
...
.antMatchers("/admin/** ").hasAnyRole("ADMIN","USER",...)
...}
https://stackoverflow.com/questions/60917246
复制相似问题