12

Is there an end to end example of using Open SAML library v3? I can't find any documentation and as per https://wiki.shibboleth.net/confluence/display/OpenSAML/Home the 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

gauravphoenix
  • 2,814
  • 3
  • 25
  • 33

1 Answers1

4

You have to include the implementation in your POM.

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

One of the things that is done in version 3 is to split the library into many different modules.

Yes, the documentation is a problem. But as I understand, the developer team is aware of that. In the meanwhile, I have written a book on the subject, A Guide to OpenSAML V3. It walks through the use of OpenSAML and the changes in V3.

Stefan Rasmusson
  • 5,445
  • 3
  • 21
  • 48