monkeyWie
0.65D
V2EX  ›  Java

关于 spring security 配置问题

  •  
  •   monkeyWie ·
    monkeyWie · Sep 4, 2020 · 1814 views
    This topic created in 2085 days ago, the information mentioned may be changed or developed.

    想实现只对 /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 replies    2020-09-04 16:59:47 +08:00
    THESDZ
        1
    THESDZ  
       Sep 4, 2020
    自己写个拦截器
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3171 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 12:13 · PVG 20:13 · LAX 05:13 · JFK 08:13
    ♥ Do have faith in what you're doing.