集中 session 在具有不同域的多个产品中

Centralized session in multiple product having different domain

我正在为多个产品开发集中管理模块。尝试在多个产品中保持相同的 session。


对于 Product1:成功验证并发送令牌作为响应 header

请求URL:http://localhost:8080/admin-web/rest/authenticate/

请求Headers

Accept:application/json, text/plain, */* Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.8 Cache-Control:no-cache Connection:keep-alive Host:localhost:8080 Origin:http://product1.com:9090 Pragma:no-cache Referer:http://product1.com:9090/p1/ User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36

回应Headers

Set-Cookie:token=asdf123sfs1f23sfsf321sfsf21; Version=1; Comment=""; Domain=localhost; Path=/ <------------------------------------??? Access-Control-Allow-Credentials:true Access-Control-Allow-Origin:http://product1.com:9090 Content-Encoding:gzip Content-Type:application/json Date:Mon, 13 Nov 2017 12:38:27 GMT Server:Apache-Coyote/1.1 Transfer-Encoding:chunked Vary:Origin Vary:Accept-Encoding


对于产品 2:

请求URL:http://localhost:8080/admin-web/rest/authenticate/

请求Headers

Accept:application/json, text/plain, */* Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.8 Cache-Control:no-cache Connection:keep-alive Content-Length:156 Content-Type:application/json;charset=UTF-8 Host:localhost:8080 Origin:http://product2.com:9090 Pragma:no-cache Referer:http://product2.com:9090/p2/ token:null <------------------------------------??? User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36


product1 身份验证后进行 product2 身份验证时,找到令牌 null。如果我在同一个域上部署 product1,它工作正常。 因此,我想在另一个产品请求中对同一服务 url 使用令牌 header。我该怎么做?请在下面找到我的 CORS 配置:

<filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

    <init-param>
        <param-name>cors.allowOrigin</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>cors.supportedMethods</param-name>
        <param-value>GET, HEAD, POST, OPTIONS, PUT, DELETE</param-value>
    </init-param>
</filter>

我已经通过为每个产品创建子域来解决这个问题,就像 Google 一样,我可以在其中跨子域共享 cookie。

参考Share cookie between subdomain and domain