9

I am running this code at 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;
}

For the document

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

Unmarshaller return a null, Can you help me to undertand how are the criterias to lookup the correct Unmarshaller and how this works at opensaml?

Tremelune
  • 352
  • 2
  • 11
Pegerto
  • 614
  • 5
  • 18
  • I found that there is not unmarshallers register as there is not initialization in the library: Important piece of code: // Initialize the library DefaultBootstrap.bootstrap(); – Pegerto Jul 31 '14 at 22:31

2 Answers2

23

I found that there is not unmarshallers register as there is not initialization in the library:

Important piece of code:

// Initialize the library
DefaultBootstrap.bootstrap();
Pegerto
  • 614
  • 5
  • 18
  • 2
    Thank you Pegerto,you save my day – sampathpremarathna Mar 16 '16 at 14:05
  • 1
    I use OpenSaml3 where this would be: `InitializationService.initialize()` but i still get null from the MarshallerFactory. Anyone can help? – Gobliins Jan 10 '17 at 10:41
  • @Goblins, I have no luck either. I followed this code for initialization in OpenSAML3: https://github.com/apereo/cas/blob/master/support/cas-server-support-saml-core/src/main/java/org/apereo/cas/support/saml/OpenSamlConfigBean.java Then unmarshallerFactory.getUnmarshallers() return 9 unmarshallers (e.g. integer, boolean, string), but none for the ones I care about. – dieresys Apr 10 '17 at 16:03
4

In OpenSAML3 you have to first make sure to include the opensaml-saml-impl artifact in your dependencies, since all the marshallers and unmarshallers are implemented there.

Then, as @Goblins and @Pegerto pointed out, you have to call InitializationService.initialize(). I have found this link to be useful for doing a correct initialization when using Dependency Injection https://github.com/apereo/cas/blob/master/support/cas-server-support-saml-core-api/src/main/java/org/apereo/cas/support/saml/OpenSamlConfigBean.java

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
dieresys
  • 1,881
  • 1
  • 12
  • 8