Skip to Content.
Sympa Menu

mace-opensaml-users - Re: [OpenSAML] MalformedURLException: no protocol when unmarshalling assertion

Subject: OpenSAML user discussion

List archive

Re: [OpenSAML] MalformedURLException: no protocol when unmarshalling assertion


Chronological Thread 
  • From: Bryce Allen <>
  • To:
  • Cc: Rachana Ananthakrishnan <>, Kyle Miller <>
  • Subject: Re: [OpenSAML] MalformedURLException: no protocol when unmarshalling assertion
  • Date: Fri, 4 Mar 2011 17:07:09 -0600

Nevermind; this had nothing to do with OpenSAML, I was calling the
wrong parse method on DocumentBuilder. Been a long day :P.

To document the (now rather obvious) error, the parseDocument taking a
string should look like this:

public static Document parseDocument(String xmlString)
throws SAXException, IOException, ParserConfigurationException {
DocumentBuilder builder = builderFactory.newDocumentBuilder();
return builder.parse(new
ByteArrayInputStream(xmlString.getBytes()));
}

There does not seem to be any problem with using UUIDs beginning with a
number as the Assertion ID.

-Bryce

On Fri, 4 Mar 2011 16:05:09 -0600
Bryce Allen
<>
wrote:
> I created an assertion using OpenSAML - see attached document. I am
> marshalling and serializing the assertion to string like this:
>
> public static String writeAssertionAsString(Assertion a) {
> if (a == null)
> throw new IllegalArgumentException("Passed assertion is
> null");
> try {
> MarshallerFactory mf =
> Configuration.getMarshallerFactory(); Marshaller m =
> mf.getMarshaller(a); if (m == null)
> throw new IllegalArgumentException("marshaller is
> null");
>
> DocumentBuilderFactory dbfac =
> DocumentBuilderFactory.newInstance();
> DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
>
> Document doc = docBuilder.newDocument();
>
> m.marshall(a, doc);
>
>
> // Transformation
> TransformerFactory transfac =
> TransformerFactory.newInstance();
> Transformer trans = transfac.newTransformer();
> trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
> "no");
> trans.setOutputProperty(OutputKeys.METHOD,"xml");
> //create string from xml tree
> StringWriter sw = new StringWriter();
> StreamResult result = new StreamResult(sw);
> DOMSource source = new DOMSource(doc);
> trans.transform(source, result);
> return sw.toString();
> } catch (MarshallingException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (ParserConfigurationException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } catch (TransformerException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> return null;
> }
>
> And de-serializing/unmarshalling like this:
>
> public static Assertion parseAssertion(String data)
> throws SAXException, IOException, UnmarshallingException,
> ParserConfigurationException {
> DocumentBuilder builder = builderFactory.newDocumentBuilder();
> Document document = builder.parse(data);
> return parseAssertion(document);
> }
>
> public static Assertion parseAssertion(Document document)
> throws UnmarshallingException {
> Element element = document.getDocumentElement();
> UnmarshallerFactory unmarshallerFactory =
> Configuration.getUnmarshallerFactory();
> Unmarshaller unmarshaller =
> unmarshallerFactory.getUnmarshaller(element);
> return (Assertion)unmarshaller.unmarshall(element);
> }
>
> I get the following exception from parseAssertion:
>
> java.net.MalformedURLException: no protocol:
> [entire XML document passed in]
> at java.net.URL.<init>(URL.java:583)
> at java.net.URL.<init>(URL.java:480)
> at java.net.URL.<init>(URL.java:429)
> at
> org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown
> Source) at
> org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(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(DocumentBuilder.java:177) at
> org.cabig.rest.security.SAMLUtil.parseAssertion(SAMLUtil.java:234) at
> org.cabig.rest.client.AssertionTester.main(AssertionTester.java:38)
>
>
> I still get this error after changing my ID so it begins with a letter
> (re the comment by Scott Cantor). What am I doing wrong here? Any help
> would be greatly appreciated.
>
> I can read the document and verify the signature fine without using
> OpenSAML (i.e. using javax.xml.crypto.dsig). Using OpenSAML 2.4.1.
>
> Thanks,
> Bryce



Archive powered by MHonArc 2.6.16.

Top of Page