Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Security禁用从特定url发出的请求的安全性_Java_Spring_Spring Mvc_Spring Boot_Spring Security - Fatal编程技术网

Java Spring Security禁用从特定url发出的请求的安全性

Java Spring Security禁用从特定url发出的请求的安全性,java,spring,spring-mvc,spring-boot,spring-security,Java,Spring,Spring Mvc,Spring Boot,Spring Security,我的应用程序使用spring安全性。我知道您可以使用antMatchers来允许对映射到应用程序中的某些URI的请求。但我也需要允许从外部api向我的应用程序中的URI发出请求,并且只允许该api发出请求。我需要这样的东西: @Override protected void configure(WebSecurity web) throws Exception { web.ignoring() .antM

我的应用程序使用spring安全性。我知道您可以使用antMatchers来允许对映射到应用程序中的某些URI的请求。但我也需要允许从外部api向我的应用程序中的URI发出请求,并且只允许该api发出请求。我需要这样的东西:

     @Override
     protected void configure(WebSecurity web) throws Exception 
     {            
        web.ignoring()
          .antMatchers("http://externalTestApi.com");
     }

有人知道这是否可能吗?我没有在这上面找到任何东西。

您可以这样做(如果您想要组合多个条件)


这适用于接受HttpSecurity作为参数的configure方法,我需要这个用于使用WebSecurity配置方法。您不是在扩展
WebSecurity配置适配器吗?只需@override
configure(HttpSecurity http)
就可以了,在WebSecurityConfigureAdapter中有两种配置方法,一种采用HttpSecurity,另一种采用WebSecurity,对于具有WebSecurity的配置,我需要这个方法,因为请求被过滤,我得到的是403 null。我正在使用RestTemplate从api发布帖子,因为它是post,它会进行一些过滤,并且我的会话有问题。如果您将其移动到使用HttpSecurity的方法,那么安全性将在该层中完成。。我不认为有任何理由阻止您将代码移动到HttpSecurity。。请看此处的差异这两种配置方法有不同的用途,正如您发布的链接中所述,使用WebSecurity,您可以拒绝请求,安全配置的方式使请求被某些筛选器拒绝,如果我按照您的建议执行,我的请求将在到达我在HttpSecurity上进行的任何配置之前被拒绝。
.authorizeRequests()
.antMatchers("/user/list")
.access("authenticated or hasIpAddress('666.666.666.666') or hasIpAddress('127.0.0.1') or hasIpAddress('0:0:0:0:0:0:0:1')")
.authorizeRequests()
.antMatchers("/user/list")
.hasIpAddress("0.0.0.0/0");