【问题标题】:how to migrate from opensaml 2.6 to 3.1.1如何从 opensaml 2.6 迁移到 3.1.1
【发布时间】:2016-06-18 00:42:34
【问题描述】:

我必须将一个类从 opensaml 2.6 迁移到 opensaml 3.1.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

3)

BasicCredential credential = new BasicCredential();

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

我还没有找到带有弃用指示的文档。 要将这个类移植到 opensaml 3.1.1 版本,我必须做什么?

【问题讨论】:

    标签: java migration opensaml


    【解决方案1】:

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

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

    1) 在库net.shibboleth.utilities:java-support 中有一个类SerializeSupport 和一个方法prettyPrintXML

    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 的解决方法:OpenSAML3 resource not found 'default-config.xml' in OSGi container

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

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

    【讨论】:

    • 那么当我仍然得到 null 而不是工厂的 (un) marshaller 时,可能是什么原因? XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(authnRequest.getElementQName())
    • 你有InitializationService.initialize();吗?
    • git.shibboleth.net/view/… 有一些有用的示例代码。请注意,一些初始化位于org.opensaml.core.xml.XMLObjectBaseTestCase#initXMLObjectSupport 的超类中,而后者又继承自OpenSAMLInitBaseTestCase(除了InitializationService.initialize() 什么都不做)。
    • 对于SOAPHelperWSSecurityHelper 的课程,我正在为类似于第 1) 部分的内容而苦苦挣扎。有人知道那些去哪儿了吗?
    • 可能是org.opensaml.soap.util.SOAPSupportorg.opensaml.soap.wssecurity.util.WSSecuritySupport build.shibboleth.net/nexus/content/sites/site/java-opensaml/… build.shibboleth.net/nexus/content/sites/site/java-opensaml/…
    【解决方案2】:

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

    项目见the github repository

    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 显示的配置。
    • 使用 InitializationService.initialize() 无限期挂起
    猜你喜欢
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多