[OpenSAML] MalformedURLException: no protocol when unmarshalling assertion

618 views
Skip to first unread message

Bryce Allen

unread,
Mar 4, 2011, 5:05:09 PM3/4/11
to opensaml-users, Rachana Ananthakrishnan, Kyle Miller
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

ballen.xml

Bryce Allen

unread,
Mar 4, 2011, 6:07:09 PM3/4/11
to mace-open...@internet2.edu, Rachana Ananthakrishnan, Kyle Miller
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

Cantor, Scott E.

unread,
Mar 5, 2011, 12:58:01 PM3/5/11
to mace-open...@internet2.edu, Rachana Ananthakrishnan, Kyle Miller
>There does not seem to be any problem with using UUIDs beginning with a
>number as the Assertion ID.

They are schema-invalid.

-- Scott

Reply all
Reply to author
Forward
0 new messages