Yuri Blanc
Yuri Blanc

Reputation: 645

OpenSaml read metadata

I'm tring to read the metadata from an Idp using Open Saml 2. When i try to unmarshall the metadata openSaml show only this getter for attributes getUnknownAtrributes(). Looks like i am missing some point since when reading the Idp response SAML the code works very well. (it shows getAssertions() that returns a list of assertions).

I need to parse the metadata and find informations regarding the Idp.

Here the method

     public Metadata metadataReader() {

        ByteArrayInputStream bytesIn = new ByteArrayInputStream(ISSUER_METADATA_URL.getBytes());
        BasicParserPool ppMgr = new BasicParserPool();

        ppMgr.setNamespaceAware(true);
        // grab the xml file
//      File xmlFile = new File(this.file);
        Metadata metadata = null;
        try {
            Document document = ppMgr.parse(bytesIn);
            Element metadataRoot = document.getDocumentElement();
            QName qName = new QName(metadataRoot.getNamespaceURI(), metadataRoot.getLocalName(),
                    metadataRoot.getPrefix());
            Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(qName);
            metadata = (Metadata) unmarshaller.unmarshall(metadataRoot);


            return metadata;

        } catch (XMLParserException e) {
            e.printStackTrace();
        } catch (UnmarshallingException e) {
            e.printStackTrace();
        }

        return null;

    }

Upvotes: 1

Views: 3584

Answers (1)

Stefan Rasmusson
Stefan Rasmusson

Reputation: 5595

I suggest using a metadata provider to do the heavy lifting for you. FilesystemMetadataProvider is often a good fit.

I have a blog post that explains how to use it.

Upvotes: 3

Related Questions