gpt4 book ai didi

java - OpenSAML 自定义属性值

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:25:11 27 4
gpt4 key购买 nike

我正在尝试创建 SAML 响应。构成断言的属性之一称为地址,属性值需要是在 XSD 中定义的自定义类型。如何将自定义属性值类型添加到响应中?

最佳答案

如果你的属性值 XML 是 String 形式:


String yourXMLFragment = "...";

AttributeStatementBuilder attributeStatementBuilder =
(AttributeStatementBuilder) builderFactory.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
AttributeStatement attributeStatement = attributeStatementBuilder.buildObject();

AttributeBuilder attributeBuilder =
(AttributeBuilder) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
Attribute attr = attributeBuilder.buildObject();
attr.setName("yourAttributeName");

XSAnyBuilder sb2 = (XSAnyBuilder) builderFactory.getBuilder(XSAny.TYPE_NAME);
XSAny attrAny = sb2.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSAny.TYPE_NAME);
attrAny.setTextContent(yourXMLFragment.trim());

attr.getAttributeValues().add(attrAny);
attributeStatement.getAttributes().add(attr);

关于java - OpenSAML 自定义属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6900341/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com