Peg*_*rto 4 java null marshalling nullpointerexception opensaml
我在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;
}
Run Code Online (Sandbox Code Playgroud)
对于文件
<?xml version="1.0" encoding="UTF-8"?><saml2:EncryptedAssertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
Run Code Online (Sandbox Code Playgroud)
Unmarshaller返回a null,你能帮助我了解如何查找正确的标准Unmarshaller以及它在opensaml中是如何工作的?
Peg*_*rto 13
我发现没有unmarshallers注册,因为库中没有初始化:
重要的一段代码:
// Initialize the library
DefaultBootstrap.bootstrap();
Run Code Online (Sandbox Code Playgroud)
在 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