java - Spring Security 禁用从某个 url 发出的请求的安全性

标签 java spring spring-mvc spring-boot spring-security

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

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

有人知道这是否可行吗?我没有找到任何相关内容。

最佳答案

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

.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");

关于java - Spring Security 禁用从某个 url 发出的请求的安全性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46564580/

相关文章:

java - 使用 fragment 中的自定义适配器和自定义行过滤 ListView

java - 如何相邻打印两个不同的循环

java - 如何将缓存控制添加到 @RestController servlet 路径?

java - JSON Map<String,ArrayList> 数据未转换为 Restful jersey 中的 bean 对象

java - 具有全局上下文上下文 :component-scan? 的 Spring MVC 注释

java - 如何从 Spring MVC 导出到 Excel

java - Java SE 是否与 JDK 相同?

java - 连接到 MySQL 服务器 JDBC

java - 如何将 Spring IOC 与 Swing 结合使用

java - Servlet 的 Spring root WebApplicationContext