首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java安全-授权问题

Java安全-授权问题
EN

Stack Overflow用户
提问于 2020-03-29 16:20:35
回答 1查看 34关注 0票数 0

在SpringSecurity中,我对授权有问题。我正在编写一个简单的组织者应用程序,其中有14个角色,但我正在ROLE_ADMIN上进行整个测试,但没有成功。输入/admin‘here到/denied页面:(您在这里发现问题了吗?

代码语言:javascript
复制
    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");
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-29 17:41:07

试着改变.antMatchers("/admin/").hasAnyRole("ROLE_ADMIN",.)致.antMatchers("/admin/").hasAnyRole("ADMIN",.)当Security自动向每个角色添加角色前缀时。例如

代码语言:javascript
复制
protected void configure(final HttpSecurity http) throws Exception {
...
.antMatchers("/admin/** ").hasAnyRole("ADMIN","USER",...)
...

}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60917246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档