【问题标题】:Opensaml error receiving correct unmarshallerOpensaml 错误接收正确的解组器
【发布时间】:2021-11-09 13:52:06
【问题描述】:

我在 opensaml2.6 上运行此代码

Element metadataRoot = document.getDocumentElement();

// Unmarshall
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(metadataRoot);
if (unmarshaller == null) {
    System.out.println("Error receiving unmarshaller for this document.");
    return;
}

对于文档

<?xml version="1.0" encoding="UTF-8"?><saml2:EncryptedAssertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">

Unmarshaller 返回一个null,你能帮我理解一下查找正确Unmarshaller 的标准是什么以及它在opensaml 中的工作原理吗?

【问题讨论】:

  • 我发现没有unmarshallers register 因为库中没有初始化: 重要的一段代码: // 初始化库 DefaultBootstrap.bootstrap();

标签: java nullpointerexception null marshalling opensaml


【解决方案1】:

我发现没有解组器注册,因为库中没有初始化:

重要的一段代码:

// Initialize the library
DefaultBootstrap.bootstrap();

【讨论】:

  • 谢谢 Pegerto,你拯救了我的一天
  • 我使用 OpenSaml3,这将是:InitializationService.initialize(),但我仍然从 MarshallerFactory 获得 null。有人可以帮忙吗?
  • @Goblins,我也没有运气。我在 OpenSAML3 中按照以下代码进行初始化:github.com/apereo/cas/blob/master/support/… 然后 unmarshallerFactory.getUnmarshallers() 返回 9 个解组器(例如整数、布尔值、字符串),但我关心的没有。
【解决方案2】:

在 OpenSAML3 中,您必须首先确保在您的依赖项中包含 opensaml-saml-impl 工件,因为所有编组器和解组器都在那里实现。

然后,正如@Goblins 和@Pegerto 指出的那样,您必须致电InitializationService.initialize()。我发现这个链接对于在使用依赖注入https://github.com/apereo/cas/blob/master/support/cas-server-support-saml-core-api/src/main/java/org/apereo/cas/support/saml/OpenSamlConfigBean.java时进行正确的初始化很有用@

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多