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

发布于 2025-02-06 22:46:40 字数 1652 浏览 1 评论 0原文

我正在尝试按照此示例:如何使用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", "[email protected]");
        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);

I am trying to follow this example: How to create a valid SAML 2.0 Assertion with OpenSAML library in Java and trying to create a SAML response. The code shown is for an older version of OpenSAML. I am using OpenSAML 4.1.1. Apparently XMLHelper is no longer in v.4. I have searched high and low and not found a solution, at least one that makes sense where I can convert the assertion into a string.

Below is the code I have right out of the sample:

        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", "[email protected]");
        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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下慵懒的猫 2025-02-13 22:46:40

现在使用serializeSupport类在OpenSAML中打印XML。

String originalAssertionString = SerializeSupport.prettyPrintXML(plaintextElement)

至于OpenSAML 4的最新示例代码,我有A 在我的博客上正在进行的系列。以及随附的我的github上的源样本

几年前,我也写了< a href =“ https://payhip.com/b/41tw” rel =“ nofollow noreferrer”> opensaml 3 的书。它尚未进行更新,但是3和4之间的更改很少。

The SerializeSupport class is now used to print XML in OpenSAML.

String originalAssertionString = SerializeSupport.prettyPrintXML(plaintextElement)

As for more current sample code for OpenSAML 4 I have a ongoing series on my blog. As well as accompanying source samples on my Github

A few years ago I also wrote a book on OpenSAML 3. It has not been updated but there are very few changes between 3 and 4.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文