Java 通过OpenSAML中的现有元素创建SAML2.0断言
我正在尝试使用现有的断言元素为令牌更新过程使用OpenSAML创建SAML2.0断言Java 通过OpenSAML中的现有元素创建SAML2.0断言,java,opensaml,ws-trust,Java,Opensaml,Ws Trust,我正在尝试使用现有的断言元素为令牌更新过程使用OpenSAML创建SAML2.0断言 // Obtain the token Token tk = tkStorage.getToken(data.getTokenId()); OMElement assertionOMElement = tk.getToken(); int samlRstversion = data.getSamlRstVersion(); if(sa
// 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
}
我有两个错误
DefaultBootstrap.bootstrap()启动时使用code>时,它会抛出
异常java.lang.UnsupportedOperationException:此解析器不支持规范“null”版本“null”
DefaultBootstrap.bootstrap()
时,它会抛出
断言samlAssertion=(断言)解组器。解组器(x1)代码>
有什么我遗漏的吗?首先,您必须始终运行引导程序,否则会出现错误 第一个错误是因为JAXP的实现太旧了
OpenSAML团队建议使用ApacheXerces或Xalan。有两个错误导致了异常。当然,为了继续编组或解编组,必须执行
bootsrap()
DOM
实现正在更改为DOOM
。
DocumentBuilderFactoryImpl.setDOOMRequired(true)代码>
即使是这样,代码也在使用它。因此,在执行bootstrap()
之前,必须将其设置为false
,因为底层JAXB实现使用DOM
OmeElement AssertionMelement
强制转换为元素
会引发此异常org.w3c.dom.DOMException:NAMESPACE\u ERR:试图以不正确的方式创建或更改对象。
omeelement
转换为String
,然后从中构建Document
,并获取DocumentElement
String s = assertionOMElement.toString();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(new ByteArrayInputStream(s.trim().getBytes()));
Element element = document.getDocumentElement();