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 SSO和常规登录


下一篇:UUMS和SSO