Spring Security 来自2.1.0->2.5.0 saml-许多不推荐

stszievb  于 2021-10-10  发布在  Java
关注(0)|答案(2)|浏览(351)

关于spring security 2.5.0的小问题。
以前在2.1.0版本有一个spring boot+spring安全项目。
现在我进行了升级,升级到spring boot 2.5.0+spring-security-saml2-service-provider 5.5.0
业务逻辑工作正常,我们使用它进行saml身份验证,没有问题。
我们得到的一个片段是:

//local signing (and decryption key)
        Saml2X509Credential signingCredential = getSigningCredential();
        //IDP certificate for verification of incoming messages
        Saml2X509Credential idpVerificationCertificate = getVerificationCertificate();
        String acsUrlTemplate = "{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI;
        return RelyingPartyRegistration.withRegistrationId(registrationId)
                .remoteIdpEntityId(idpEntityId)
                .idpWebSsoUrl(webSsoEndpoint)
                .credentials(c -> c.add(signingCredential))
                .credentials(c -> c.add(idpVerificationCertificate))
                .localEntityIdTemplate(localEntityIdTemplate)
                .assertionConsumerServiceUrlTemplate(acsUrlTemplate)
                .build();

同样,它工作得很好。
我们将该项目升级到了最新的(截至撰写本文时)2.5.0版本,并且在代码段的大部分行中都看到了不推荐的内容。
尝试查看SpringSecurity5.5.0,建议改用assertionconsumerservicelocation。
但我很难理解,什么是字符串取代一切?

return RelyingPartyRegistration.withRegistrationId(registrationId).assertionConsumerServiceLocation("what comes here?").build();

需要帮忙吗?

kcugc4gi

kcugc4gi1#

反对的动机是我们应该在 RelyingPartyRegistration .
对约定进行了更改,以便更好地遵循注册要表示的元数据描述符。
例如,relyingpartyregistration.providerdetails包含一个名为GetWebSourl的方法,但它不容易Map到idpssodescriptor中的任何内容。将其命名为GetSingleSignonService location会更清楚,因为此信息位于中。
您可以在方法的javadoc中看到应该使用什么。像这样:

/**
 * @deprecated Use {@link #assertionConsumerServiceLocation} instead.
 */
@Deprecated
public Builder assertionConsumerServiceUrlTemplate(String assertionConsumerServiceUrlTemplate) {
    this.assertionConsumerServiceLocation = assertionConsumerServiceUrlTemplate;
    return this;
}

或者在spring security官方存储库中打开该文件。

qq24tv8q

qq24tv8q2#

在审查spring security文档后,这与新的spring security 5.5+版本中的相同:

RelyingPartyRegistration getSaml2AuthenticationConfiguration()  {
        //remote IDP entity ID
        String idpEntityId = "https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php";

        //remote WebSSO Endpoint - Where to Send AuthNRequests to
        String webSsoEndpoint = "https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php";

        String acsUrlTemplate = "{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI;

        //local signing (and decryption key)
        Saml2X509Credential relyingPartySigningCredential = getSigningCredential();
        //IDP certificate for verification of incoming messages
        Saml2X509Credential assertingPartyVerificationCredential = getVerificationCertificate();

        //local registration ID
        String registrationId = "registrationId";
        //local entity ID - autogenerated based on URL
        String localEntityIdTemplate = "localEntityIdTemplate";

        return RelyingPartyRegistration
                .withRegistrationId(registrationId)
                .entityId(localEntityIdTemplate)
                .assertionConsumerServiceLocation(acsUrlTemplate)
                .signingX509Credentials(c -> c.add(relyingPartySigningCredential))
                .assertingPartyDetails(details -> details
                        .verificationX509Credentials(c -> c.add(assertingPartyVerificationCredential))
                        .singleSignOnServiceLocation(webSsoEndpoint)
                        .entityId(idpEntityId)).build();

    }

相关问题