本文介绍了Spring security 多个 hasIPAddress antMatchers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 spring 安全配置片段:

I have the following spring security configuration snippet:

http
   .authorizeRequests()
   .antMatchers("/tokens").hasIpAddress("10.0.0.0/16")
   ....

这有效,但我还想从 127.0.0.1 授予对 "/tokens" 的访问权限.我希望以下内容可以奏效,但它没有:

This works, but I would also like to grant access to "/tokens" from 127.0.0.1. I was hoping something along the lines of the following would work, but it doesn't:

http
   .authorizeRequests()
   .antMatchers("/tokens").hasIpAddress("10.0.0.0/16").hasIpAddress("127.0.0.1/32")
   ....

推荐答案

http
    .authorizeRequests()
    .antMatchers("/tokens").access(
            "hasIpAddress('10.0.0.0/16') or hasIpAddress('127.0.0.1/32')")
....

这篇关于Spring security 多个 hasIPAddress antMatchers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 17:52