【问题标题】:Create SAML 2.0 assertion by existing element in OpenSAML通过 OpenSAML 中的现有元素创建 SAML 2.0 断言
【发布时间】:2014-08-22 18:34:45
【问题描述】:

我正在尝试使用 OpenSAML 的现有断言元素创建 SAML 2.0 断言以进行令牌更新过程。

 // 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
}

我遇到了两个错误。

  1. 当使用DefaultBootstrap.bootstrap(); 时,它会抛出一个 异常java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"
  2. DefaultBootstrap.bootstrap() 被移除时,它会抛出 断言 samlAssertion = (Assertion) unmarshaller.unmarshall(x1);

我有什么遗漏的吗?

【问题讨论】:

    标签: java opensaml ws-trust


    【解决方案1】:

    首先,您必须始终运行引导程序,否则会出错。

    看起来第一个错误是因为您的 JAXP 实现太旧了 https://lists.internet2.edu/sympa/arc/mace-opensaml-users/2010-01/msg00015.html

    OpenSAML 团队建议使用 Apache Xerces 或 Xalan。

    【讨论】:

      【解决方案2】:

      有两个错误导致了异常。当然必须完成bootsrap() 才能继续编组或解组。

      1. 在代码的前一行中,DOM 实现已更改为 DOOMDocumentBuilderFactoryImpl.setDOOMRequired(true); 即使它是deprecated,代码也在使用它。所以在 bootstrap() 之前必须将其设置为 false,因为底层 JAXB 实现使用 DOM。

      2. 此外,将 OMElement assertionOMElement 转换为 Element 会引发此异常。 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.

      解决方案是将OMElement 转换为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();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-03-14
        • 1970-01-01
        • 2019-05-04
        • 2019-08-08
        • 1970-01-01
        • 2017-07-23
        • 1970-01-01
        相关资源
        最近更新 更多