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
DOM
implementation was changing toDOOM
.DocumentBuilderFactoryImpl.setDOOMRequired(true);
Even though it was deprecated the code was using it. So before dobootstrap()
it had to be set tofalse
since the underlying JAXB implementation uses the DOM.Also, casting
OMElement assertionOMElement
toElement
threw 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
OMElement
toString
and then build theDocument
from it and get theDocumentElement