Skip to Content.
Sympa Menu

mace-opensaml-users - Unmarshall and validating an SAML file

Subject: OpenSAML user discussion

List archive

Unmarshall and validating an SAML file


Chronological Thread 
  • From:
  • To:
  • Subject: Unmarshall and validating an SAML file
  • Date: Thu, 22 Oct 2009 05:42:17 -0400 (EDT)

Hi
I am trying to unmarshall and validate an SAML file using SAML2.0 API. While
running the below piece of code, I am getting the error.

String inCommonMDFile = "templates/SamlResponse.xml";
try {
DefaultBootstrap.bootstrap();
BasicParserPool ppMgr = new BasicParserPool();
ppMgr.setNamespaceAware(true);

InputStream in = new ByteArrayInputStream(inCommonMDFile.getBytes());
Document inCommonMDDoc = ppMgr.parse(in);
Element metadataRoot = inCommonMDDoc.getDocumentElement();

Schema schema = SAMLSchemaBuilder.getSAML11Schema(); Validator validator =
schema.newValidator();
javax.xml.transform.dom.DOMSource domSrc = new DOMSource(metadataRoot);
validator.validate(domSrc);

UnmarshallerFactory unmarshallerFactory =
Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller =
unmarshallerFactory.getUnmarshaller(metadataRoot);

Response samlResponse = (Response) unmarshaller.unmarshall(metadataRoot);

} catch (XMLParserException xe) {
System.out.println("Unable to parse XML file: " + xe);
catch (ConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Below are the error details.Please can any one help me out with the issue.
Unable to parse XML file: org.opensaml.xml.parse.XMLParserException:
Invalid XML
21-Oct-2009 18:37:41 org.opensaml.xml.parse.LoggingErrorHandler fatalError
SEVERE: XML Parsing Error
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at
org.opensaml.xml.parse.BasicParserPool$DocumentBuilderProxy.parse(BasicParserPool.java:607)
at org.opensaml.xml.parse.BasicParserPool.parse(BasicParserPool.java:210)
at util.MetadataTest.testInCommonUnmarshall(MetadataTest.java:80)
at util.MetadataTest.main(MetadataTest.java:124)

Below is the my SAML file,I am using.
=================SamlResponse.xml================
<Response IssueInstant="2009-09-04T13:37:33Z" MajorVersion="1"
MinorVersion="1" ID="1bc6d017-f9bd-4333-a618-a73cd4ea51ac">
<Status><StatusCode Value="Success"/>
</Status><Assertion AssertionID="9e39584f-5cbd-4241-9ec7-56e011a2035f"
IssueInstant="2009-09-04T13:37:33Z" Issuer="Test Issuer" MajorVersion="1"
MinorVersion="1">
<Conditions NotBefore="2009-09-04T13:37:33Z"
NotOnOrAfter="2009-09-04T13:37:38Z"/>
<AuthenticationStatement AuthenticationInstant="2009-09-04T13:37:33Z"
AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password">
<Subject>
<NameIdentifier
Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"></NameIdentifier>
<SubjectConfirmation/>
</Subject>
</AuthenticationStatement>
</Assertion>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#";>
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#1bc6d017-f9bd-4333-a618-a73cd4ea51ac">
<Transforms>
<Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>0qnKCEgW2h7yX/1UfkngJXGXxPk=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>vgefKC1BZXTeNjUEqU1aGvBfn1H.....</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>MIIDPTCCAuegAwIBAgIJAK3Eu7cvYD .........</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</Response>
=====================

Many Thanks
Regards,
Murali



Archive powered by MHonArc 2.6.16.

Top of Page