在我的Spring Boot项目中,我尝试访问具有特定IP地址的多个管理员用户。Spring Security配置中的单角色多个IP地址
是否可以将单个角色映射到多个IP地址?
这里是我的安全配置中的代码,它没有工作。 (我给硬编码的角色名和IP地址为简单起见)
@SuppressWarnings("ALL")
@Configuration
@EnableWebSecurity
public class MyWebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
List<String> ipAddresses = new ArrayList<>();
ipAddresses.add("127.0.0.1");
ipAddresses.add("192.168.1.0/24");
ipAddresses.add("0:0:0:0:0:0:0:1");
for (String ip : ipAddresses) {
http.authorizeRequests().
antMatchers("/admin" + "/**")
.access("hasRole('admin') and hasIpAddress('" + ip + "')");
}
}
//some other configurations
}
URL我的要求:http://localhost:9595/admin/checkappeals/211
我收到以下错误:HTTP状态403次-message-描述访问指定的资源已被禁止。 – user7244716