【问题标题】:Spring Security SAML Extension with Remember Me functionality across multiple tomcat webappsSpring Security SAML 扩展,具有跨多个 tomcat webapps 的记住我功能
【发布时间】:2019-01-13 17:14:02
【问题描述】:

我有 2 个 spring 应用程序在 tomcat 服务器上并排运行。我将基于令牌的 RememberMeAuthenticationProvider 与自定义 UserDetailsS​​ervice 一起使用,因此我只对用户进行一次身份验证,他们可以在两个应用程序之间导航,而无需重新进行身份验证。

除了正常的用户名/密码登录过程外,我还配置了 spring saml 扩展,以使用外部 IdP 对我的应用程序 (SP) 上的用户进行身份验证。我使用带有自定义 SAMLUserDetailsS​​ervice 的 SAMLAuthenticationProvider 将 saml 断言用户名与我的数据库中的用户匹配,并且他们在我的 one 应用程序中进行了身份验证。我遇到的问题是用户未在我的第二个应用程序上进行身份验证。导航到第二个应用程序时,它不断要求输入用户名和密码,正如我所期望的那样,因为没有为 SAMLAuthenticationProvider 配置的记住我的令牌/cookie。

有什么方法可以通过 SAMLUserDetailsS​​ervice 使用基于令牌的记住我服务?

【问题讨论】:

    标签: java spring spring-security saml-2.0 spring-saml


    【解决方案1】:

    关键是确保SAMLProcessingFilter.rememberMeServices 已设置。 这有点棘手,因为没有公开默认的rememberMe() 组件。这是一个可能的解决方案。

    @Autowired
    public void configureRememberMe(
            @Qualifier(BeanIds.SPRING_SECURITY_FILTER_CHAIN) Filter securityChain,
            List<SAMLProcessingFilter> filters
    ) {
        RememberMeServices rememberMe = ((FilterChainProxy) securityChain).getFilterChains().stream()
                .flatMap(chain -> chain.getFilters().stream())
                .filter(RememberMeAuthenticationFilter.class::isInstance)
                .map(RememberMeAuthenticationFilter.class::cast)
                .findAny()
                .map(RememberMeAuthenticationFilter::getRememberMeServices)
                .orElseGet(NullRememberMeServices::new);
    
        filters.forEach(filter -> filter.setRememberMeServices(rememberMe));
    }
    

    如果您构建自己的RememberMeServices,则直接将其注入,而不是将其从过滤器链中捞出。

    下一个问题是如果你没有.alwaysRemember()。我认为没有任何方法可以通过 IdP 传递请求参数。您将不得不根据某些外部上下文扩展 RememberMeServices 并覆盖 rememberMeRequested,或者扩展 WebSSOProfile 以将 remember-me 参数动态添加到绑定 URL。

    【讨论】:

      【解决方案2】:

      当用户成功通过身份验证时,我最终使用了 SAMLAuthenticationProvider 并手动创建了一个记住我的令牌(通过复制 RememberMeAuthenticationProvider 下的 spring 源代码)。

      我找不到通过 spring 配置优雅地结合 SAMLAuthenticationProvider 和 RememberMeAuthenticationProvider 的功能的方法,但它现在可以工作了。

      【讨论】:

        【解决方案3】:

        您是否已将两个应用程序配置为使用相同的会话存储?他们是否在同一个域/子域上,以便他们可以共享身份验证 cookie?我会将其中一个应用程序设置为(唯一的)身份验证点,并将第二个应用程序的登录设置为去它进行身份验证。

        【讨论】:

          猜你喜欢
          • 2012-03-13
          • 2019-07-26
          • 1970-01-01
          • 2014-07-23
          • 2015-08-27
          • 2013-03-02
          • 2014-08-02
          • 2020-05-31
          • 1970-01-01
          相关资源
          最近更新 更多