<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 12/9/19 10:05 AM, Huy Banh wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAF=96oA0RmiKHdReOY0+04MWpuun4dxVbhSZx-_HJNeGJZQ6FQ@mail.gmail.com">
      <pre class="moz-quote-pre" wrap=""> am using OpenSaml in a SP project. I want to get IdP metadata, using
the following code snipet:</pre>
    </blockquote>
    <p>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.</p>
    <p>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.</p>
    <p><br>
    </p>
    <blockquote type="cite"
cite="mid:CAF=96oA0RmiKHdReOY0+04MWpuun4dxVbhSZx-_HJNeGJZQ6FQ@mail.gmail.com">
      <pre class="moz-quote-pre" wrap="">

final BasicParserPool pool = new BasicParserPool();
pool.initialize();

final String idpUrl = <a class="moz-txt-link-rfc2396E" href="https://samltest.id/saml/idp">"https://samltest.id/saml/idp"</a>;
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?</pre>
    </blockquote>
    <p>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:</p>
    <p>Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl@dcfda20<br>
      Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl@6d304f9d<br>
      Key info: org.opensaml.xmlsec.signature.impl.KeyInfoImpl@f73dcd6</p>
    <p>Make sure that before any of that code, you call
      InitializationService.initialize().<br>
    </p>
    <p>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.<br>
    </p>
    <br>
  </body>
</html>