如何从OpenSAML 2.6迁移到3.1.1版本。

18
我需要将一个类从opensaml 2.6迁移到opensaml 3.1.1。编译时出现了一些错误。
Element plaintextElement = getElementAssertion(inputBean);
String xml = XMLHelper.prettyPrintXML(plaintextElement);

我在新版本中找不到XMLHelper类。

2)

DefaultBootstrap.bootstrap();
builderFactory = Configuration.getBuilderFactory();
Configuration.getMarshallerFactory().getMarshaller(assertion).marshall(assertion);

我找不到DefaultBootstrap类,也找不到一个带有getBuilderFactory()和getMarshallerFactory()方法的Configuration类。
BasicCredential credential = new BasicCredential();

现在构造函数new BasicCredential()不可见。

我没有找到有关弃用说明的文档。我该如何将这个类移植到opensaml 3.1.1版本?

2个回答

31

不确定您是否已经升级到opensaml 3,但由于我在尝试升级时遇到了这个问题,所以我想记录一下我发现的内容。

很少有文档,因为显然目前它们不是一个优先事项(也在这里提到:OpenSaml3 Documentation),我发现的最有用的页面(即使远远不完整)是这个页面:https://wiki.shibboleth.net/confluence/display/OS30/Initialization+and+Configuration

1)有一个类SerializeSupport,其中包含一个方法prettyPrintXML,在lib net.shibboleth.utilities:java-support中。

2)现在通过InitializationService进行初始化,例如:

InitializationService.initialize();
您可以通过 XMLObjectProviderRegistrySupport 检索构建器/编组程序,例如:
XMLObjectProviderRegistrySupport.getMarshallerFactory()
XMLObjectProviderRegistrySupport.getBuilderFactory()
XMLObjectProviderRegistrySupport.getUnmarshallerFactory()

请注意,opensaml使用Java Service Provider API。在我的情况下(使用OSGi捆绑包org.apache.servicemix.bundles:org.apache.servicemix.bundles.opensaml)用于解析SAML断言,我添加了SPI配置META-INF/services/org.opensaml.core.config.Initializer,其中包含以下条目:

org.opensaml.core.xml.config.XMLObjectProviderInitializer
org.opensaml.core.xml.config.GlobalParserPoolInitializer
org.opensaml.saml.config.XMLObjectProviderInitializer
org.opensaml.saml.config.SAMLConfigurationInitializer
org.opensaml.xmlsec.config.XMLObjectProviderInitializer

编辑:上述内容在测试中有效,但在OSGi容器中无法运行。解决OSGi的方法:在OSGi容器中找不到OpenSAML3资源'default-config.xml'

如果您使用标准库(org.opensaml:opensaml-coreorg.opensaml:opensaml-saml-apiorg.opensaml:opensaml-saml-impl等),则可能不需要添加任何SPI配置,因为这些jar已经包含了带有初始化标准配置的SPI配置。

3)在lib org.opensaml:opensaml-security-api中有一个BasicCredential类。我没有看到提供在初始化期间提供密钥的替代方法。


那么,当我仍然从工厂获取null而不是(un)marshaller时,可能的原因是什么呢?XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(authnRequest.getElementQName()) - Gobliins
你执行过 InitializationService.initialize(); 吗? - Xin Meng
1
在https://git.shibboleth.net/view/?p=java-opensaml.git;a=blob;f=opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/MetadataTest.java;hb=HEAD上有一些有用的示例代码。请注意,一些初始化工作在超类`org.opensaml.core.xml.XMLObjectBaseTestCase#initXMLObjectSupport`中完成,该超类又继承自`OpenSAMLInitBaseTestCase`(仅执行`InitializationService.initialize()`)。 - Marcel Stör
我正在处理一些类似于第1节的问题,涉及到SOAPHelperWSSecurityHelper类。有人知道这两个类去哪了吗? - Serban
可能是 org.opensaml.soap.util.SOAPSupportorg.opensaml.soap.wssecurity.util.WSSecuritySupport https://build.shibboleth.net/nexus/content/sites/site/java-opensaml/3.2.0/apidocs/org/opensaml/soap/util/SOAPSupport.html https://build.shibboleth.net/nexus/content/sites/site/java-opensaml/3.2.0/apidocs/org/opensaml/soap/wssecurity/util/WSSecuritySupport.html - Clauds

0

我正在学习如何使用OS3进行开发。这是一个将base 64 saml请求转换为V3版本中的SAMLObject的示例。希望它能对你有所帮助。

该项目请参见github存储库

public class SAMLToolkit {

    public static SAMLObject convertBase64ToSaml(String base64Str) {
        byte[] decodedBytes = new byte[0];
        try {
            decodedBytes = Base64.decode(base64Str);
        } catch (Base64DecodingException e) {
            e.printStackTrace();
            return null;
        }

        InputStream is = new ByteArrayInputStream(decodedBytes);
        //is = new InflaterInputStream(is, new Inflater(true));
        try {

            InitializationService.initialize();
            Document messageDoc;
            BasicParserPool basicParserPool = new BasicParserPool();
            basicParserPool.initialize();
            messageDoc = basicParserPool.parse(is);
            Element messageElem = messageDoc.getDocumentElement();
            Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().getUnmarshaller(messageElem);

            assert unmarshaller != null;
            return(SAMLObject) unmarshaller.unmarshall(messageElem);
        } catch (InitializationException e) {
            e.printStackTrace();
            return null;
        } catch (XMLParserException e) {
            e.printStackTrace();
            return null;
        } catch (UnmarshallingException e) {
            e.printStackTrace();
            return null;
        } catch (ComponentInitializationException e) {
            e.printStackTrace();
            return null;
        }
    }
}

除非我也添加/META-INF/services/org.opensaml.core.config.Initializer,其中包含@Clauds所示的配置,否则这对我不起作用。 - Marcel Stör
使用 InitializationService.initialize() 会无限期地挂起。 - praveenraj

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接