您的for
循环导致以下配置:
@SuppressWarnings("ALL")
@Configuration
@EnableWebSecurity
public class MyWebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/admin/**").access("hasRole('admin') and hasIpAddress('127.0.0.1')")
.antMatchers("/admin/**").access("hasRole('admin') and hasIpAddress('192.168.1.0/24')")
.antMatchers("/admin/**").access("hasRole('admin') and hasIpAddress('0:0:0:0:0:0:0:1')");
}
//some other configurations
}
所以对于URL:
http://localhost:9595/admin/checkappeals/211
仅考虑第一个匹配器,请参见HttpSecurity#authorizeRequests:
注意匹配器是按顺序考虑的。因此,以下内容无效,因为第一个匹配器匹配每个请求,并且永远不会到达第二个映射:
http.authorizeRequests().antMatchers(“/”) .hasRole(“ADMIN”)
您必须构建类似:
http
.authorizeRequests()
.antMatchers("/admin/**").acces("hasRole('admin') and (hasIpAddress('127.0.0.1') or hasIpAddress('192.168.1.0/24') or hasIpAddress('0:0:0:0:0:0:0:1'))";