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

Brent Putman putmanb at georgetown.edu
Sat Nov 12 13:52:07 EST 2016



On 11/12/16 1:56 AM, Gaurav Kumar wrote:
>
> I'm using following code to get SAML assertion-
>


What you have there isn't wrong, but you probably have more code than
you need, and it's less efficient than it could be.

I'd recommend the following:

1) use an OpenSAML ParserPool instance rather than constructing and
using DocumentBuilderFactorys.  It's more efficient.  We also had the
ParserPool in v2, btw.
2) we have some helper methods that make the common marshalling and
unmarshalling cases easier, as well as certain other things.  Check out
the class org.opensaml.core.xml.util.XMLObjectSupport.

Most of what you have can reduce to 3 lines of code:

InitializationService.initialize();  // Just do this once in your
application's lifecycle

InputStream is = ...; // get an input stream for the XML to be parsed

XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(
        XMLObjectProviderRegistrySupport.getParserPool(), is);

As a part of the unmarshall call, you can of course cast the returned
value to Response, etc, if you know that's what it is.



> 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
>



If that's literally all you have for opensaml-* dependencies in your
POM, then that's your problem.  You need to add in all the appropriate
-impl dependencies.  If you just add opensaml-saml-impl, Maven should
pull most or all of the rest in transitively, depending on what you
need.  For the full list of deps you can pull in, we have some notes
and links here: http://shibboleth.net/downloads/java-opensaml/latest/


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/dev/attachments/20161112/42cbe192/attachment.html>


More information about the dev mailing list