KeyDescriptor.getKeyInfo() always returns null

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

KeyDescriptor.getKeyInfo() always returns null

Huy Banh
 am using OpenSaml in a SP project. I want to get IdP metadata, using
the following code snipet:

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?

Thank you.
--
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: KeyDescriptor.getKeyInfo() always returns null

Brent Putman


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@dcfda20
Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl@6d304f9d
Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl@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.



--
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: KeyDescriptor.getKeyInfo() always returns null

Huy Banh
Thank you Brent.
I am busy with another task and can't get back to this until the end of the holiday. I will update again if any progress.

Merry Christmas and happy new year.

On Mon, Dec 9, 2019 at 9:11 PM Brent Putman <[hidden email]> wrote:


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@dcfda20
Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl@6d304f9d
Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl@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.


--
To unsubscribe from this list send an email to [hidden email]

--
To unsubscribe from this list send an email to [hidden email]