Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaSpring安全性-授权问题_Java_Http_Spring Security - Fatal编程技术网

JavaSpring安全性-授权问题

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("/"

我对Spring Security中的授权有问题。 我正在编写一个简单的组织者应用程序,其中有14个角色,但我正在对角色\u ADMIN进行完整的测试,但它不起作用。键入/admin get's me to/denied page:( 你能在这里找到问题吗

    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:-)工作正常