【问题标题】:How can I set RequestedAuthenticationContext in spring-security for ADFS?如何在 ADFS 的 spring-security 中设置 RequestedAuthenticationContext?
【发布时间】:2021-11-26 14:37:59
【问题描述】:

我使用this 工具对其进行了测试,发现我需要身份验证类型:Form 和令牌请求:SAML-P (SAML2.0),但我不需要'不知道如何配置 spring-security 以发送 RequestedAuthenticationContext 作为 urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport 而不是 urn:oasis:names: tc:SAML:2.0:ac:classes:Kerberos 在 SAML 请求中。

所以不是这样:

  • 身份验证类型:Windows 集成身份验证
  • 令牌请求: SAML-P (SAML 2.0)
  • 对 IdP 的请求: GET https://ospa.company.com/adfs/ls/IdpInitiatedSignOn? LoginToRP=urn:microsoft:adfs:claimsxray& RequestedAuthenticationContext=urn:oasis:names:tc:SAML:2.0:ac:classes:Kerberos
  • 来自 IdP 的回复:
<samlp:Response ID="..."
                Version="2.0"
                IssueInstant="..."
                Destination="https://adfshelp.microsoft.com/ClaimsXray/TokenResponse"
                Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified"
                xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
    ...
        <AuthnStatement AuthnInstant="..." SessionIndex="...">
            <AuthnContext>

     <AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Kerberos</AuthnContextClassRef>

            </AuthnContext>
        </AuthnStatement>
    </Assertion>
</samlp:Response>

我需要这个:

  • 身份验证类型:表单
  • 令牌请求: SAML-P (SAML 2.0)
  • 对 IdP 的请求: GET https://ospa.company.com/adfs/ls/IdpInitiatedSignOn? LoginToRP=urn:microsoft:adfs:claimsxray& RequestedAuthenticationContext=urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
  • 来自 IdP 的回复:
<samlp:Response ID="..."
                Version="2.0"
                IssueInstant="..."
                Destination="https://adfshelp.microsoft.com/ClaimsXray/TokenResponse"
                Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified"
                xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
    ...
        <AuthnStatement AuthnInstant="..." SessionIndex="...">
            <AuthnContext>

     <AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</AuthnContextClassRef>

            </AuthnContext>
        </AuthnStatement>
    </Assertion>
</samlp:Response>

更新: 我们使用spring-boot 2.5.5

【问题讨论】:

  • 您使用的是最新的 Spring Security,它附带 SAML 支持吗? (也有一个已弃用的spring-security-saml 插件,这就是我问的原因。)另外,我是否正确理解您是一个希望 Spring Security 重定向到您描述的端点以启动身份验证的 SP?
  • 我们有一个通用的spring boot lib,使用的是2.2.5.RELEASE版本的spring boot。只有在必要时,我才能升级补丁版本。 spring-security-saml2-service-provider 的版本是 5.2.2.RELEASE。我们不使用 saml 插件。
  • 你描述的案例正是我们想要达到的。
  • 如果不能这样解决,我可以跳过common lib,在主应用中使用最新的spring security。
  • 当然,如果我能在公共库中以某种方式解决这个问题,那将是最好的。

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


【解决方案1】:

您需要的是AuthenticationEntryPointAuthenticationEntryPoint 是您告诉 Spring Security 在需要身份验证时重定向到哪里的方式。

由于您只需要在需要身份验证时进行重定向,因此您可以像这样使用LoginUrlAuthenticationEntryPoint

@Bean
SecurityFilterChain app(HttpSecurity http) throws Exception {
    String url = "https://ospa.company.com/adfs/ls/IdpInitiatedSignOn? LoginToRP=urn:microsoft:adfs:claimsxray& RequestedAuthenticationContext=urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport";

    AuthenticationEntryPoint entryPoint = 
            new LoginUrlAuthenticationEntryPoint(url);

    http
        .authorizeHttpRequests((authorize) -> authorize
            .anyRequest().authenticated()
        )
        .saml2Login(withDefaults())
        .exceptionHandling((exceptions) -> exceptions
            .authenticationEntryPoint(entryPoint)
        );
    
    return http.build();
}

还请确保您configure your application with your IdP's corresponding metadata

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-28
    • 2013-11-12
    • 2017-05-11
    • 2014-08-23
    • 2020-01-15
    • 2014-09-14
    • 2019-11-24
    • 2014-03-05
    相关资源
    最近更新 更多