关于 spring security 配置问题

2020-09-04 16:05:55 +08:00
 monkeyWie

想实现只对 /actuator/** 路径会进行鉴权,并且在源 ip 为内网的时候放行,否则需要通过 HTTP basic 认证

目前的配置可以实现内网放行,代码如下:

http.antMatcher("/actuator/**")
                .authorizeRequests()
                .anyRequest()
                .access("hasIpAddress('::1')" +
                        " or hasIpAddress('127.0.0.1')" +
                        " or hasIpAddress('10.0.0.0/8')" +
                        " or hasIpAddress('172.16.0.0/12')" +
                        " or hasIpAddress('192.168.0.0/16')")
                .and()
                .httpBasic();

但是这样的话会导致配置文件中定义的用户名和密码失效:

spring.security.user.name=admin
spring.security.user.password=123456

之前不做 ip 白名单的时候配置的用户密码可以生效的:

http.antMatcher("/actuator/**").authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .httpBasic();

大佬们帮忙看看应该怎么配置,或者有没有什么最简单的办法能做自定义的权限校验。

1300 次点击
所在节点    Java
1 条回复
THESDZ
2020-09-04 16:59:47 +08:00
自己写个拦截器

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/704244

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX