V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
monkeyWie
V2EX  ›  Java

关于 spring security 配置问题

  •  
  •   monkeyWie ·
    monkeyWie · 2020-09-04 16:05:55 +08:00 · 1292 次点击
    这是一个创建于 1328 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想实现只对 /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();
    

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

    1 条回复    2020-09-04 16:59:47 +08:00
    THESDZ
        1
    THESDZ  
       2020-09-04 16:59:47 +08:00
    自己写个拦截器
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1603 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:00 · PVG 01:00 · LAX 10:00 · JFK 13:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.