我正在将Java 8项目中的OpenSAML从2.6.1升级到3.3.1
许多代码编译错误很容易修复,但我被困在某个时候。

如果我们使用签名算法,则以前的代码如下:

KeyPair signingKeyPair = parseKeyPair(properties.getProperty("signingKey"), properties.getProperty("signingKeyPassword"));
signingCredential = createCredential(signingKeyPair, serviceProviderID, UsageType.SIGNING);
if (properties.getProperty("signingAlgorithm") != null) {
    SecurityConfiguration securityConfiguration = Configuration.getGlobalSecurityConfiguration();
    if (securityConfiguration instanceof BasicSecurityConfiguration && "RSA".equals(signingCredential.getPublicKey().getAlgorithm())) {
               ((BasicSecurityConfiguration) securityConfiguration).registerSignatureAlgorithmURI("RSA", properties.getProperty("signingAlgorithm"));
    }
}


在OpenSAML 3.0+中,行Configuration.getGlobalSecurityConfiguration();不再编译。如何在OpenSAML 3.0+中获得全局安全性配置?

最佳答案

免责声明:我以前没有使用过这些安全配置类,但是我有一些从OpenSAML 2.x升级到3.x的经验,并且在OpenSAML文档和源代码中进行了摸索。

我希望这可以帮助您入门:

// initializes the various security configurations
GlobalSecurityConfigurationInitializer.init();

// fetches the various security configurations
DecryptionConfiguration dc = SecurityConfigurationSupport.getGlobalDecryptionConfiguration();
EncryptionConfiguration ec = SecurityConfigurationSupport.getGlobalEncryptionConfiguration();
SignatureSigningConfiguration ssc = SecurityConfigurationSupport.getGlobalSignatureSigningConfiguration();
SignatureValidationConfiguration svc = SecurityConfigurationSupport.getGlobalSignatureValidationConfiguration();


我不确定这些配置中的哪一个可以满足您所需的功能,但是以下是Javadocs,其中包含一些其他详细信息:


DecryptionConfiguration / BasicDecryptionConfiguration
EncryptionConfiguration / BasicEncryptionConfiguration
SignatureSigningConfiguration / BasicSignatureSigningConfiguration
SignatureValidationConfiguration / BasicSignatureValidationConfiguration


您也可以check out the OpenSAML source;具体来说,DefaultSecurityConfigurationBootstrap类是其中很多设置的地方。

08-06 15:29