1.4. 跨形资源共享(CORS)请求


Data Grid REST 连接器支持 CORS,包括基于请求来源的 preflight 和规则。

下面显示了一个使用 CORS 规则的 REST 连接器配置示例:

<rest-connector name="rest1" socket-binding="rest" cache-container="default">
   <cors-rules>
      <cors-rule name="restrict host1"
                 allow-credentials="false">
         <allowed-origins>http://host1,https://host1</allowed-origins>
         <allowed-methods>GET</allowed-methods>
      </cors-rule>
      <cors-rule name="allow ALL"
                 allow-credentials="true"
                 max-age-seconds="2000">
         <allowed-origins>*</allowed-origins>
         <allowed-methods>GET,OPTIONS,POST,PUT,DELETE</allowed-methods>
         <allowed-headers>Key-Content-Type</allowed-headers>
      </cors-rule>
   </cors-rules>
</rest-connector>
Copy to Clipboard Toggle word wrap

Data Grid 根据浏览器设置的 "Origin" 标头来按顺序评估 CORS 规则。

在上例中,如果 origin 是 "http://host1" 或 "https://host1",则应用规则 "restrict host1"。如果原始卷不同,则下一个规则会被测试。

因为 "allow ALL" 规则允许所有原始卷,所以具有 "http://host1" 或 "https://host1" 以外的任何原始脚本都可以执行允许的方法,并使用提供的标头。

有关配置 CORS 规则的详情,请参考 Data Grid Server Configuration Schema

1.4.1. 允许对某些原始卷允许所有 CORS 权限

在启动服务器时,可以使用 VM 属性 infinispan.server.rest.cors-allow,以允许对一个或多个来源的所有权限。例如:

./bin/server.sh -Dinfinispan.server.rest.cors-allow=http://192.168.1.78:11222,http://host.mydomain.com
Copy to Clipboard Toggle word wrap

使用此方法指定的所有原始卷优先于配置的规则。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat