Search code examples
javasaml-2.0opensaml

SAML marshalling opensaml and java


I have recently upgraded opensaml dependency from 2.5.3 to 2.6.1 and xmlutil from 1.3.0 to 1.4.1. It compiles without any errors but while running the application i get the following exception:

java.lang.NullPointerException
org.opensaml.xml.io.AbstractXMLObjectMarshaller.marshall(AbstractXMLObjectMarshaller.java:84)

Calling Code:

final MarshallerFactory marshallerFac = SAMLUtil.getMarshallerFactory();
     final org.opensaml.xml.io.Marshaller authnStatementMarshaller = marshallerFac.getMarshaller(assertion);

     Element assertionElement = null;

     try {
        assertionElement = authnStatementMarshaller.marshall(assertion);
        try {
           // Sign assertion and query signature
           Signer.signObject(signature);
        }
        catch (final SignatureException e) {
           LOGGER.error("Fout opgetreden bij ondertekenen Assertion", e);
        }
     }

Solution

  • I've noticed that if you don't initialize ("bootstrap") the SAML configuration, you get a NullPointerException (rather unhelpfully, I might add) when you try to construct the SAML.

    import org.opensaml.DefaultBootstrap;
    import org.opensaml.xml.ConfigurationException;
    
    try {
        DefaultBootstrap.bootstrap();
    }
    catch (ConfigurationException ce) {
    }
    

    The above is just a snippet of code to illustrate what I'm talking about. Did you maybe forget to bootstrap the configuration? That has to be done before you do anything.