编程语言
首页 > 编程语言> > java-OpenSAML自定义属性值

java-OpenSAML自定义属性值

作者:互联网

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

解决方法:

如果您的属性值XML为字符串形式:


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);

标签:saml,opensaml,java
来源: https://codeday.me/bug/20191102/1990800.html