【问题标题】:Wildfly with Spring Boot app: concurrent requests from SPA app result in 403Wildfly 与 Spring Boot 应用程序:来自 SPA 应用程序的并发请求导致 403
【发布时间】:2020-10-23 14:30:57
【问题描述】:

我们在 Wildfly 18 中部署了一个 Spring Boot 应用程序,通过耳中的战争(使用 SpringBootServletInitializer)。耳中还存在其他战争,并且启用了会话共享。战争还共享一个安全域。

从浏览器或邮递员查询 Spring Boot 应用程序 REST API 工作正常。当它是一个 SPA 应用程序时,它会失败:并发请求会收到 403 Forbidden,例如在访问日志中:

127.0.0.1 [02/Jul/2020:22:54:46 +0200] "GET /api/Foo?bar=1 HTTP/1.1" 403 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"

序列化 SPA 请求使其再次工作,但这只是为了测试目的:我们希望来自 SPA 的并发请求!

我在standalone.xml 中尝试了许多配置,例如这是因为我们使用会话共享并且我希望每个会话一次有多个请求:

     <subsystem xmlns="urn:jboss:domain:infinispan:9.0">
        <cache-container name="web" default-cache="passivation" module="org.wildfly.clustering.web.infinispan">
            <local-cache name="passivation">
                <locking isolation="NONE"/>
                <transaction mode="BATCH"/>
                <file-store passivation="true" purge="false"/>
            </local-cache>
            <local-cache name="persistent">
                <transaction mode="BATCH"/>
                <file-store passivation="false" purge="false"/>
            </local-cache>
        </cache-container>

或者这个允许并发请求:

    <subsystem xmlns="urn:jboss:domain:undertow:10.0" statistics-enabled="true">
        <buffer-cache name="default"/>
        <server name="default-server">
            <http-listener name="default" max-connections="100" socket-binding="http" max-parameters="5000" allow-unescaped-characters-in-url="true"/>
            <host name="default-host" alias="localhost">
                <access-log pattern="%h %t &quot;%r&quot; %s &quot;%{i,User-Agent}&quot;" use-server-log="false"/>
                <filter-ref name="x-frame-options"/>
                <filter-ref name="limit-connections"/>
            </host>
        </server>
        <servlet-container name="default" default-encoding="UTF-8" max-sessions="10000">
            <jsp-config/>
            <session-cookie http-only="true"/>
        </servlet-container>
        <filters>
            <request-limit name="limit-connections" max-concurrent-requests="3000" queue-size="100"/>
            <response-header name="x-frame-options" header-name="X-Frame-Options" header-value="SAMEORIGIN"/>
        </filters>
    </subsystem>

欢迎在并发请求上摆脱这些讨厌的 403 的任何帮助!

【问题讨论】:

    标签: java spring-boot wildfly undertow


    【解决方案1】:

    问题已解决:前面的应用程序,在耳边的战争中,不在安全域中。而且默认安全域不是其他战争使用的安全域。

    我们已经把前面的战争放在同一个域中(通过jboss-web.xml)并且......不再是403!我们有点惊讶 403 没有出现在每次通话中,但我们很高兴它可以正常工作。

    【讨论】:

      【解决方案2】:

      我认为您需要允许 CORS 使用 SPA 托管服务器。

      您可以通过Java Configuration(WebMvcConfigurer)@CrossOrigin annotaion 进行设置。

      【讨论】:

      • 非常感谢,但是所有的战争都在同一个耳朵里,所以在同一个领域。最重要的是,大多数请求都顺利通过,只有一些返回 403(即使这样,会话实际上仍然是有效的服务器端,即使前端应用程序认为用户已注销)
      猜你喜欢
      • 2019-04-15
      • 2020-06-05
      • 2014-07-21
      • 2019-09-25
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 2017-04-03
      • 2019-01-02
      相关资源
      最近更新 更多