java - 如何更改Spring Security中SAML请求的签名算法

标签 java spring digital-signature saml spring-saml

我正在使用 spring security saml 扩展来使用 ADFS 作为 IDP 来实现 SSO。

据我了解,spring security 使用 open saml 以 SHA1withRSA 作为签名算法对 SAML 请求进行签名。

我们需要更改为使用 SHA256withRSA 来签署 SAML 请求。

如何才能做到这一点?

感谢对此的任何建议。提前非常感谢

最佳答案

确保使用最新的 Spring SAML(或至少将 OpenSAML 更新到最新版本)。按如下方式扩展 SAMLBootstrap 类,并将其插入到 Spring 配置中,而不是原始的 SAMLBootstrap 类:

package fi.schafer.saml.custom;

import org.opensaml.Configuration;
import org.opensaml.xml.security.BasicSecurityConfiguration;
import org.opensaml.xml.signature.SignatureConstants;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

public class SAMLBootstrap extends org.springframework.security.saml.SAMLBootstrap {

    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

        super.postProcessBeanFactory(beanFactory);

        BasicSecurityConfiguration config = (BasicSecurityConfiguration) Configuration.getGlobalSecurityConfiguration();
        config.registerSignatureAlgorithmURI("RSA", SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
        config.setSignatureReferenceDigestMethod(SignatureConstants.ALGO_ID_DIGEST_SHA256);

    }

}

关于java - 如何更改Spring Security中SAML请求的签名算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23681362/

相关文章:

java - Hibernate 查询中的重复项

java - JAVA 中字符串转公钥

java - 创建一个抛硬币类(class)

Spring Boot端口转发80到8080

java - Spring mvc看不到jsp

pdf - 使用多个 DSS 词典进行签名

android - 自 Android 2.3 起 PSS 签名验证失败

Java Applet 在没有互联网的情况下无法加载

java - 在 Java 中使用 Selenium 以编程方式下载文件

java - 使用 JSoup 抓取 HTML,出现 HTTP 错误,状态 456