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",...)
...
}