Javaの春のセキュリティ - AUTHORIZEの問題点

TomaszC283:

私は問題が持っている春のセキュリティで承認を私は、単純なオーガナイザーアプリを書いているし、14の役割がありますが、私は上の全体のテストを作ってるんだROLE_ADMIN、そしてそれが動作しませんでした。タイピング/管理者のgetはに/拒否されたページ私です:(あなたはここでの問題を見つけることができますか?

    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");
    }
アラムYeghiazaryan:

( "/管理/変更.antMatchersしよう.antMatchers( "/管理/に").hasAnyRole(" ROLE_ADMIN"、...)春のセキュリティはROLEを追加するよう(.... "ADMIN"、)").hasAnyRole自動的に各役割に接頭辞。例えば

protected void configure(final HttpSecurity http) throws Exception {
...
.antMatchers("/admin/** ").hasAnyRole("ADMIN","USER",...)
...

}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=371132&siteId=1