【问题标题】:Using SAML with Spring Boot behind an ELB redirects to http instead of https在 ELB 后面使用带有 Spring Boot 的 SAML 重定向到 http 而不是 https
【发布时间】:2019-04-21 12:48:23
【问题描述】:

我正在尝试使用 Okta 对来自 SpringBoot 应用程序的用户进行身份验证。

我已经按照 Okta 教程设置了应用程序:https://developer.okta.com/blog/2017/03/16/spring-boot-saml

但是,我的应用程序位于 ELB 之后,因此 TLS 在 LB 处终止。所以我修改了教程中的配置以满足我的需要。

 @Override
protected void configure(final HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/saml*").permitAll()
            .anyRequest().authenticated()
            .and()
        .apply(saml())
            .serviceProvider()
                .keyStore()
                    .storeFilePath(this.keyStoreFilePath)
                    .password(this.password)
                    .keyname(this.keyAlias)
                    .keyPassword(this.password)
                    .and()
                .protocol("https")
                .hostname(String.format("%s", serverName))
                .basePath("/")
                .and()
            .identityProvider()
            .metadataFilePath(this.metadataUrl);
}

这可以解决问题,但有一个问题。用户通过 Okta 身份验证后,最终将用户重定向到 http URL 而不是 https URL。我认为这样做的原因是 TLS 在 LB 处被终止,而我的应用实际上正在接收带有 http 的请求,该请求是在 RelayState 中发送的。

这是我发现的:spring-boot-security-saml-config-options.md。 它包含 Spring Boot 安全性的 SAML 属性列表。我在 application.properties 文件中添加了以下内容

saml.sso.context-provider.lb.enabled = true
saml.sso.context-provider.lb.scheme=https
saml.sso.profile-options.relay-state=<https://my.website.com>

它不会改变 http 重定向。是不是我做错了什么?

【问题讨论】:

    标签: spring-boot saml-2.0 spring-saml okta


    【解决方案1】:

    当像 Okta 这样的 SAML 2.0 IdP 重定向回您的应用程序时,端点 URL 要么基于您的应用程序公开的 SAML 2.0 元数据,要么基于 IdP 中的配置。

    此外,在 SAML 2.0 AuthnRequest 中添加 Destination 属性是可选的:

    <samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified" 
        Destination="https://my.website.com" IssueInstant="2018-11-22T09:23:08.844Z" Version="2.0" ID="id-f8ee3ab1-6745-42d5-b00f-7845b97fe953">
    <Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion"> ... </Issuer>
    ...
    </samlp:AuthnRequest>
    

    【讨论】:

      猜你喜欢
      • 2014-06-30
      • 2017-08-02
      • 2021-12-12
      • 2015-07-25
      • 1970-01-01
      • 2015-05-17
      • 2016-06-21
      • 2018-12-11
      • 2017-12-25
      相关资源
      最近更新 更多