Java Spring Security - Autorizar problema

TomaszC283:

tengo un problema con Autorizar en la primavera de Seguridad . Estoy escribiendo una aplicación simple organizador y hay un 14 papeles, pero yo estoy haciendo pruebas de enteros en ROLE_ADMIN , y no me funciona. escribiendo / admin conseguirme de a / página negado :( Se puede encontrar un problema aquí?

    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");
    }
Aram Yeghiazaryan:

Trate de .antMatchers de cambio ( "/ admin / ") .hasAnyRole (" ROLE_ADMIN", ...) a .antMatchers ( "/ admin / ") .hasAnyRole (" admin", ....) como Spring Security añade PAPEL prefijo a cada función de forma automática. Por ejemplo

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

}

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=371136&siteId=1
Recomendado
Clasificación