【问题标题】:Spring security authentication in subdomains子域中的 Spring 安全认证
【发布时间】:2019-03-10 16:02:39
【问题描述】:

我有一个使用通配符子域的网站。子域可以是任何东西,但子域始终存在(默认为“www”)。我想在登录时在每个子域中进行身份验证。

当我在 abc.example.com 中进行身份验证时,JSESSIONID cookie 被放置在 abc.example.com 中。如果我去 xyz.example.com 则找不到 cookie,所以我退出了。我也使用记住我的功能,应该也可以。

到目前为止我尝试的是:

  1. 将 cookie 放在父域中(不知道如何)
  2. 复制子域的 cookie(不知道怎么做)

有人能指出正确的方向吗?

【问题讨论】:

    标签: spring-security wildcard-subdomain


    【解决方案1】:

    我必须将记住我的 cookie 放在顶级域中。通过设置 cookie 域和禁用请求缓存来完成:

    String rememberMeCookieDomain = ".mydomain.com"
    http.rememberMe().rememberMeCookieDomain(remembermeCookieDomain).rememberMeCookieName(REMEMBERME_COOKIE_NAME).tokenRepository(tokenRepository()).tokenValiditySeconds(4 * SECONDS_IN_WEEK);
    

    结尾的“.”在 cookie 域中是必要的,以允许子域访问顶级 cookie。如果你使用 tomcat,你必须打开旧的 cookie 处理器才能工作:

    How to change Cookie Processor to LegacyCookieProcessor in tomcat 8

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-21
      • 2014-10-30
      • 2016-12-12
      • 1970-01-01
      • 2013-05-03
      • 2011-11-17
      • 2021-05-17
      • 1970-01-01
      相关资源
      最近更新 更多