在 CXF 中使用 home 定义的 AttributeBean 的 SAML2 断言

SAML2 assertion with home defined AttributeBean in CXF

我一直在使用 Apache CXF 和 WSS4J 来实现 SecurityTokenService。

使用“CustomClaimsHandler”实现 "org.apache.cxf.sts.claims.ClaimsHandler" 我可以创建一个包含此类属性的 SAML 令牌:

<saml2:Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
               <saml2:AttributeValue xsi:type="xs:string">admin</saml2:AttributeValue>
</saml2:Attribute>

问题是我现在正在尝试创建一个包含一些 XML 内容的属性。例如:

<saml2:Attribute Name="http://my/xml/content">
               <saml2:AttributeValue xsi:type="???">
        <somthing>
<somthingElse>text</somthingElse>
        </somthing>
</saml2:AttributeValue>
</saml2:Attribute>

在我收到关于此 link 的回复后:

我在我的 CXF STS 项目中添加了对 opensaml-core v3.0.0 的依赖项,以获取“org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport”class,如响应中的示例所示。 在调用 XMLObjectProviderRegistrySupport.getBuilderFactory() 之前,我似乎必须初始化 opensaml 的配置。

我管理了初始化调用“org.opensaml.core.config.InitializationService.initialize();”

对于创建具有 XSAny 类型的 AttributeBean,一切似乎都很好。

问题出在 WSS4J 尝试处理 SAMLCallback 时:

Caused by: java.lang.ClassCastException: org.opensaml.core.xml.schema.impl.XSAnyBuilder cannot be cast to org.opensaml.xml.XMLObjectBuilder at org.opensaml.xml.XMLConfigurator.initializeObjectProviders(XMLConfigurator.java:236) at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:182) at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:166) at org.opensaml.xml.XMLConfigurator.load(XMLConfigurator.java:143) at org.apache.wss4j.common.saml.OpenSAMLBootstrap.initializeXMLTooling(OpenSAMLBootstrap.java:105) at org.apache.wss4j.common.saml.OpenSAMLBootstrap.bootstrap(OpenSAMLBootstrap.java:86) at org.apache.wss4j.common.saml.OpenSAMLUtil.initSamlEngine(OpenSAMLUtil.java:61) at org.apache.wss4j.common.saml.SamlAssertionWrapper.(SamlAssertionWrapper.java:204) at org.apache.cxf.sts.token.provider.SAMLTokenProvider.createSamlToken(SAMLTokenProvider.java:303) at org.apache.cxf.sts.token.provider.SAMLTokenProvider.createToken(SAMLTokenProvider.java:122) ... 45 more

可能是版本问题:

我是否必须让我的 STS 的 opensaml 配置知道我的 opensaml-core v3.0.0 classes? 或者我必须使用不同版本的 CXF 才能获得更新版本的 WSS4J?

我的 CXF 版本是 3.0.1,依赖于 2.0.1 版的 WSS4J-ws-security-common 依赖于 opensaml 2.6.1 版

有人知道吗? 此致

您不能将 OpenSAML 3 与 CXF 3.0.x 或 WSS4J 2.0.x 一起使用。如果您确实需要使用 OpenSAML 3,那么您将需要使用 CXF master SNAPSHOT 代码 (3.1.0-SNAPSHOT),该代码目前正在使用 OpenSAML 3。