Mehdi Ahmed
Mehdi Ahmed

Reputation: 13

SecurityConfig for two Roles

I'm trying to use Spring Security, all worked with one role.

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");

}

its works for one role not for two role please help me and thank you

Upvotes: 1

Views: 2388

Answers (1)

Karthik R
Karthik R

Reputation: 5786

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

That should help.

Upvotes: 8

Related Questions