将断言转换为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", "[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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在使用serializeSupport类在OpenSAML中打印XML。
至于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.
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.