I am trying to create an SAML 2.0 assertion with OpenSAML using an existing assertion element for a token renewal process.
// Obtain the token
Token tk = tkStorage.getToken(data.getTokenId());
OMElement assertionOMElement = tk.getToken();
int samlRstversion = data.getSamlRstVersion();
if(samlRstversion == 2) {
DefaultBootstrap.bootstrap();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller((Element)assertionOMElement);
Element x1 = (Element)assertionOMElement;
Assertion samlAssertion = (Assertion) unmarshaller
.unmarshall(x1);
//Add conditions to the assertion
}
I'm getting two errors.
- When the
DefaultBootstrap.bootstrap();is used, it throws an exceptionjava.lang.UnsupportedOperationException: This parser does not support specification "null" version "null" - When
DefaultBootstrap.bootstrap()is removed it throws at Assertion samlAssertion =(Assertion) unmarshaller.unmarshall(x1);
Is there something that I have missed?
There were two errors which caused the exception. Of course the
bootsrap()had to be done in order to continue with marshalling or unmarshalling.In a previous line of the code the
DOMimplementation was changing toDOOM.DocumentBuilderFactoryImpl.setDOOMRequired(true);Even though it was deprecated the code was using it. So before dobootstrap()it had to be set tofalsesince the underlying JAXB implementation uses the DOM.Also, casting
OMElement assertionOMElementtoElementthrew this exception.org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.Solution was to convert the
OMElementtoStringand then build theDocumentfrom it and get theDocumentElement