两个角色的 SecurityConfig

1 java spring spring-mvc spring-security

我正在尝试使用 Spring Security,所有这些都只负责一个角色。

protected void configure(HttpSecurity http) throws Exception {
    http.formLogin().loginPage("/login");
    http.csrf().disable();

    http.authorizeRequests().antMatchers("/index","/","/ajouterFiliere").hasRole("RM");
    http.authorizeRequests().antMatchers("/index","/","/ajouterFiliere").hasRole("RF");

    http.exceptionHandling().accessDeniedPage("/403");

}
Run Code Online (Sandbox Code Playgroud)

它适用于一个角色,不适用于两个角色,请帮助我,谢谢

Kar*_*k R 8

尝试: http.authorizeRequests().antMatchers("/index","/","/ajouterFiliere").hasAnyRole("RM", "RF")

那应该有帮助。