Any example of how to use opensaml v3 to verify SAML assertion?

Gaurav Kumar gauravphoenix at gmail.com
Sat Nov 12 01:56:30 EST 2016


I posted my question on SO but I reckon this mailing list is more suitable. You can find SO post here- 
http://stackoverflow.com/questions/40558996/how-to-use-opensaml-v3-there-is-little-to-no-documentation-and-v2-is-eol <http://stackoverflow.com/questions/40558996/how-to-use-opensaml-v3-there-is-little-to-no-documentation-and-v2-is-eol>

I'm using following code to get SAML assertion-

  private UnmarshallerFactory unmarshallerFactory;
  private DocumentBuilder docBuilder;

  @PostConstruct
  public void init() {

    try {
      InitializationService.initialize();
      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      documentBuilderFactory.setNamespaceAware(true);
      docBuilder = documentBuilderFactory.newDocumentBuilder();
      unmarshallerFactory = XMLObjectProviderRegistrySupport.getUnmarshallerFactory();
    } catch (Exception e){
      logger.error("Error: ",e);
    }
  }

  public Assertion getSamlAssertion(String samlResponse)
      throws IOException, XMLParserException, UnmarshallingException, SAXException {

    Document document = docBuilder.parse(new StringInputStream(samlResponse));

    Element element = document.getDocumentElement();
    Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
    XMLObject responseXmlObj = unmarshaller.unmarshall(element);
    Response response = (Response) responseXmlObj;
    return response.getAssertions().get(0);

  }
My POM-

         <dependency>
            <groupId>org.opensaml</groupId>
            <artifactId>opensaml-core</artifactId>
            <version>3.2.0</version>
        </dependency>


        <dependency>
            <groupId>org.opensaml</groupId>
            <artifactId>opensaml-saml-api</artifactId>
            <version>3.2.0</version>
        </dependency>
The problem is that I am getting null for unmarshaller . I've verified that the samlResponse is valid


I think the problem is somewhere related to how to initialize XML parsing but I can’t find an example to do so. The examples for v2 API aren’t valid anymore. 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/dev/attachments/20161111/93a6a9a8/attachment-0001.html>


More information about the dev mailing list