title: SAML2 xml structured attribute values
body: <p>I’ve been working with Apache CXF and WSS4J to implement a SecurityTokenService.</p>
  
  <p>Using a “CustomClaimsHandler” implementing "org.apache.cxf.sts.claims.ClaimsHandler" I can create a SAML token containing this kind of attributes :</p>
  
  <pre><code>&lt;saml2:Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"&gt;
                 &lt;saml2:AttributeValue xsi:type="xs:string"&gt;admin&lt;/saml2:AttributeValue&gt;
  &lt;/saml2:Attribute&gt;
  </code></pre>
  
  <p>The thing is I am now trying to create an attribute with some XML content. For exemple :</p>
  
  <pre><code>&lt;saml2:Attribute Name="http://my/xml/content"&gt;
                 &lt;saml2:AttributeValue xsi:type="???"&gt;
          &lt;somthing&gt;
  &lt;somthingElse&gt;text&lt;/somthingElse&gt;
          &lt;/somthing&gt;
  &lt;/saml2:AttributeValue&gt;
  &lt;/saml2:Attribute&gt;
  </code></pre>
  
  <p>I’ve looked at making a custom implementation of a “ClaimsAttributeStatementProvider” (org.apache.cxf.sts.claims) but I seem to have to use the “AttributeBean” class of WSS4J. But this class doesn’t seem to let me change the type.</p>
  
  <p>Does someone now how to deal with this issue ?</p>
  
  <p>======================================================================</p>
  
  <p>Edit following Colm's answer :</p>
  
  <p>I added a dependency to opensaml-core v3.0.0 in my CXF STS project to obtain the “org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport” class as shown in the exemple you pointed to me. 
  Before calling  the XMLObjectProviderRegistrySupport.getBuilderFactory() I seemed to have to initialize the configuration of opensaml. I didn’t manage to use the embedded configuration that I suppose my WSS4J in CXF is using. 
  I managed the initialization calling “org.opensaml.core.config.InitializationService.initialize();” </p>
  
  <p>All seems good for the creation of the AttributeBean with an XSAny type.</p>
  
  <p>The problem is when WSS4J tries to  Handle the SAMLCallback :</p>
  
  <p><code>
  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
  </code></p>
  
  <p>I suppose I have a version issue :</p>
  
  <p>Either I’d have to make my STS’s configuration of opensaml aware of my opensaml-core v3.0.0 classes 
  Or I’d have to use a different version of CXF to get a newer version of WSS4J.</p>
  
  <p>My version of CXF is 3.0.1 and has a dependency on WSS4J-ws-security-common  in version 2.0.1 witch has a dependency on opensaml version 2.6.1</p>
  
  <p>Do you have an idea of how to resolve this problem ?</p>
  
  <p>Regards</p>
  
  <p>=========================</p>
  
  <p>EDIT
  Colm resolved issue in post : <a href="https://stackoverflow.com/questions/29073059/saml2-assertion-with-home-defined-attributebean-in-cxf">SAML2 assertion with home defined AttributeBean in CXF</a></p>