Spring Security, to allow only users who have both roles to access the page

Viewed 17

First of all, I'm sorry I'm not good at English.

I created a class to extend WebSecurityConfigurerAdapter.

@Override
public void configure(HttpSecurity http) throws Exception {
    http.csrf().disable().headers().frameOptions().disable()
    .and()
        .authorizeHttpRequests()
            .antMatchers("/aaa/**", "/bbb/**").permitAll()
            .antMatchers("/ccc", "/ddd/**").hasRole("AAA")
            .antMatchers("/zzz/**").access("hasRole('AAA') and hasAnyRole('MASTER', 'ZZZ'")
            .antMatchers("/**").permitAll()
            .anyRequest().authenticated()
    .and() 
// continue....

The situation I want is:

the user have both "AAA" and "MASTER" -> can access /zzz

the user have both "AAA" and "ZZZ" -> can access /zzz

Many sites I referenced say that I can apply roles with SpEL inside the "access" method.

However in the zzz line, the access method doesn't accept a String parameter.

Could you please tell me how to apply it?

Thanks.

0 Answers
Related