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

Gaurav Kumar gauravphoenix at gmail.com
Sat Nov 12 14:57:32 EST 2016


Thanks for the help, everyone.
I am now able to get the assertion read successfully using the new API. I
shall post an end to end example working example on GitHub for the benefit
of the community in about a week's time. Meanwhile, here is a summary of
what I've:

(this below example is Spring DI friendly)

Dependendenices-


<!-- SAML deps begin -->

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

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


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

<dependency>
    <groupId>org.apache.santuario</groupId>
    <artifactId>xmlsec</artifactId>
    <version>2.0.7</version>
</dependency>

<!-- SAML deps end -->



//read the request from servlet-

@Autowired SamlService samlService;

String samlResponse = httpServletRequest.getParameter("SAMLResponse");
byte[] decode = Base64.decode(samlResponse);
String decodedSAMLstr = new String(decode, "UTF-8"); // for UTF-8 encoding
Assertion samlAssertion = samlService.getSamlAssertion(decodedSAMLstr);

// do whatever you want with the assertion. Hopefully verify :P

​
//Saml service -

import com.amazonaws.util.StringInputStream;
​//or use your fav libary ​

import java.io.IOException;
import javax.annotation.PostConstruct;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
import org.opensaml.core.config.InitializationService;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.io.UnmarshallingException;
import org.opensaml.core.xml.util.XMLObjectSupport;
import org.opensaml.saml.saml2.core.Assertion;
import org.opensaml.saml.saml2.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.xml.sax.SAXException;

@Component
public class SamlService {

  private static final Logger logger =
LoggerFactory.getLogger(SamlService.class);

  @PostConstruct
  public void init() {

    try {
      InitializationService.initialize();
    } catch (Exception e) {
      logger.error("Error: ", e);
    }
  }

  public Assertion getSamlAssertion(String samlResponse)
      throws IOException, XMLParserException, UnmarshallingException,
SAXException {
    Response response = (Response) XMLObjectSupport.unmarshallFromInputStream(
        XMLObjectProviderRegistrySupport.getParserPool(), new
StringInputStream(samlResponse));
    return response.getAssertions().get(0);

  }
​}​



​​



On Sat, Nov 12, 2016 at 10:53 AM, Brent Putman <putmanb at georgetown.edu>
wrote:

>
>
> On 11/12/16 6:20 AM, Rod Widdowson wrote:
>
> It ended up as being to do with an odd classpath environment.  The initialization service has to be able to see the META-INF/services/* files in the OpenSAML jars.
> http://shibboleth.net/pipermail/dev/2016-July/008406.html
>
>
> It could be something esoteric like that I suppose, but I think it's
> probably the missing decls from the OP's POM, unless what he posted wasn't
> the complete story.
>
>
>
> --
> To unsubscribe from this list send an email to
> dev-unsubscribe at shibboleth.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/dev/attachments/20161112/33ed2a83/attachment-0001.html>


More information about the dev mailing list