KeyDescriptor.getKeyInfo() always returns null

Brent Putman putmanb at georgetown.edu
Mon Dec 9 23:11:11 EST 2019


On 12/9/19 10:05 AM, Huy Banh wrote:
>  am using OpenSaml in a SP project. I want to get IdP metadata, using
> the following code snipet:

Well, that's not really the best way to obtain and use SAML Metadata. 
We have first order support working with metadata via various
implementations of the MetadataResolver interface.

And we also have specific support for working with keys and other key
material from Metadata using the metadata-based impl of
CredentialResolver, called MetadataCredentialResolver.


>
> final BasicParserPool pool = new BasicParserPool();
> pool.initialize();
>
> final String idpUrl = "https://samltest.id/saml/idp";
> final XMLObject xml = XMLObjectSupport.unmarshallFromInputStream(pool,
> new URL(idpUrl).openStream());
> final IDPSSODescriptor singleSignonDesc = ((EntityDescriptor)
> xml).getIDPSSODescriptor(SAMLConstants.SAML20P_NS);
>
> singleSignonDesc
>     .getKeyDescriptors()
>     .forEach(k -> System.out.println("Key info: " + k.getKeyInfo()));
>
> All data is retrieved properly, except KeyDescriptor.getKeyInfo(). It
> always returns null. Of course there is a key for each in metadata.
> Would someone help me?

Despite being sub-optimal, I don't see anything wrong with your code in
terms of doing what it purports to do. And it seems to run correctly for
me without modification.  It parses and sees all 3 KeyDescriptors'
KeyInfo instances.  Output is:

Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl at dcfda20
Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl at 6d304f9d
Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl at f73dcd6

Make sure that before any of that code, you call
InitializationService.initialize().

If that's not it, then I think your issue is something environmental and
specific to you.  You might turn on DEBUG logging at various categories
and see what it's actually doing.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/dev/attachments/20191209/099f05d8/attachment.html>


More information about the dev mailing list