栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Security配置中的单角色多个IP地址

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Security配置中的单角色多个IP地址

您的

for
循环导致以下配置:

@SuppressWarnings("ALL")@Configuration@EnableWebSecuritypublic 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(“USER”).antMatchers(“/admin/”)
.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'))";


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/435405.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号