【问题标题】:jBoss CORS support with security constraints带有安全约束的 jBoss CORS 支持
【发布时间】:2016-03-22 22:09:21
【问题描述】:

我正在使用 web-common 安全约束向我的 API 添加身份验证,但它似乎破坏了我的 CORS 过滤器。我以前只使用过滤器而不使用应用服务器级别的身份验证。

基本思想是要求对所有请求进行身份验证,除了 /rest/account 端点下的请求,因为这些请求处理初始登录,因此需要公开访问。

在尝试登录时,当 OPTIONS 调用作为 POST 请求的一部分进行时,在 Chrome 和 Postman 中的测试都会返回 405 Method not allowed 响应。

希望我在下面提供了所有相关信息,但如果需要其他信息,请告诉我。提前致谢!

我的 CORS 过滤器

<filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
    <init-param>
        <param-name>cors.supportedMethods</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>cors.supportedHeaders</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowOrigin</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowSubdomains</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>cors.supportsCredentials</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CORS</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

我的安全限制

<security-constraint>
    <display-name>WebsiteUsers</display-name>
    <web-resource-collection>
        <web-resource-name>WebsiteAPI</web-resource-name>
        <description/>
        <url-pattern>/rest/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description>Standard User authentication</description>
        <role-name>Users</role-name>
    </auth-constraint>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Public</web-resource-name>
        <description>Matches a few special endpoints</description>
        <url-pattern>/rest/account/*</url-pattern>
    </web-resource-collection>
    <!-- No auth-constraint means everybody has access! -->
</security-constraint>

【问题讨论】:

    标签: jboss cors resteasy security-constraint


    【解决方案1】:

    尝试将&lt;http-method-omission&gt;OPTIONS&lt;/http-method-omission&gt; 添加到受保护的&lt;web-resource-collection&gt;。 这应该允许 OPTIONS 请求通过您的 CORS 过滤器(然后将发送回正确的 Access-Control-Allow-Methods 响应标头)。

    见https://docs.oracle.com/cd/E19798-01/821-1841/bncbk/index.html

    或者(如果您需要支持 servlet 规范 GET、POST、DELETE、PUT 等 - 除了OPTIONS) - 使用&lt;http-method&gt;

    【讨论】:

      猜你喜欢
      • 2014-09-10
      • 2020-05-29
      • 2016-10-23
      • 2011-09-10
      • 2023-03-03
      • 2010-11-08
      • 2012-01-14
      • 1970-01-01
      • 2014-10-30
      相关资源
      最近更新 更多