繁体   English   中英

在 OpenSAML 4 中将断言转换为字符串

[英]Converting assertion to string in OpenSAML 4

我正在尝试遵循此示例: 如何使用 Java 中的 OpenSAML 库创建有效的 SAML 2.0 断言并尝试创建 SAML 响应。 显示的代码适用于旧版本的 OpenSAML。 我正在使用 OpenSAML 4.1.1。 显然 XMLHelper 不再出现在 v.4 中。 我搜索了高低并没有找到一个解决方案,至少一个可以将断言转换为字符串的解决方案是有意义的。

以下是我从示例中获得的代码:

        SAMLInputContainer input = new SAMLInputContainer();
        input.strIssuer = "http://synesty.com";
        input.strNameID = "UserJohnSmith";
        input.strNameQualifier = "My Website";
        input.sessionId = "abcdedf1234567";

        Map<String,String> customAttributes = new HashMap<String, String>();
        customAttributes.put("FirstName", "John");
        customAttributes.put("LastName", "Smith");
        customAttributes.put("Email", "john.smith@yahoo.com");
        customAttributes.put("PhoneNumber", "76373898998");
        customAttributes.put("Locality", "USA");
        customAttributes.put("Username", "John.Smith");

        input.attributes = customAttributes;

        Assertion assertion = GenSAMLAssertion.buildDefaultAssertion(input);
        AssertionMarshaller marshaller = new AssertionMarshaller();
        assert assertion != null;
        Element plaintextElement = marshaller.marshall(assertion);
        String originalAssertionString = XMLHelper.nodeToString(plaintextElement);

        System.out.println("Assertion String: " + originalAssertionString);

SerializeSupport 类现在用于在 OpenSAML 中打印 XML。

String originalAssertionString = SerializeSupport.prettyPrintXML(plaintextElement)

至于 OpenSAML 4 的最新示例代码,我的博客上有一个正在进行的系列 以及我的 Github 上随附的源示例

几年前,我还写了一本关于 OpenSAML 3的书。 它尚未更新,但 3 和 4 之间几乎没有变化。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM