In terms of the latter, you just add what extension XMLObjects you want
to the protocol message Extensions object, by calling
Extensions#getUnknownXMLObjects(), and adding/processing what you want
to the List that is returned (just like other list return types in
OpenSAML).
Of course defining what extensions you use and what they mean and how
they are processed on the receiver side is all up to you, if there's not
an existing profile for that extension.
If you are seeking some general guidance on how to solve some problem
using SAML - rather than how to implement a particular solution with
OpenSAML - this might not be the correct list.
1) the right and best way is to implement XMLObjects for those custom
elements. This will make it easier to both generate and process them.
You would write support for your custom elements by implementing
XMLObject interfaces and impls, marshallers and unmarshallers for each
element. See the OpenSAML developer's guide for details:
https://spaces.internet2.edu/display/OpenSAML/OSTwoDeveloperManual
You can also look at any of the code in SAML for examples of how that is
done. I would strongly urge you to implement this solution rather than
the next.
2) a quick and dirty way to generate such a structure is to use more
generic object provider support already in the library. You can use the
XSAny XMLObject implementation for an element that has extensible
element and/or attribute content, and then marshall it as element with a
particular QName. This would work for your RequestedAuthnContexts
element with its complex content type. You could also use XSAny
provider for your AuthnContextClassRef element, as it supports text
content. Or you could just use the XSString provider. (I won't ask why
you aren't just reusing the similarly named element from the Assertion
schema). There's an example at the bottom of the following wiki page of
using the XSString provider directly. Just adjust the QName used for
your element name (instead of the example Attribute).
https://spaces.internet2.edu/display/OpenSAML/OSTwoUsrManJavaAnyTypes
Usage of XSAny is similar. In both cases you'd want to omit the second
QName arg in the builder's buildObject method, as you probably don't
want to express the xsi:type on the element.
--Brent
> > <mailto:put...@georgetown.edu <mailto:put...@georgetown.edu>>>
Deena Gurajala wrote:
> I figured out that I have to write a custom schema for my extensions.
> They way I did it is.
>
> -write a custom schema.
Yes, you probably should have a schema for your custom stuff.
> - Use JAXB to marshal the JAVA to XML DOM.
> -Then set it o Extensions using setDOM method.
>
No, not really. JAXB is not really a complimentary technology to
OpenSAML. They are both Java-XML binding approaches. Use one or the
other, but probably not both.
>
>
> Extensions extens=new ExtensionsBuilder().buildObject();
>
> extens.setDOM(new
> DocumentGenerator().generate().getDocumentElement());
No, definitely do not use the setDOM method on the XMLObjects. That is
used by other components withing the library (marshallers and
unmarshallers) to cache the DOM representation of the XMLObject, it is
not really intended for use via the public API. You'll get
unpredictable results doing that.
Honestly, we should probably at least have a custom builder for the
protocol Extensions so that people don't have to do that, but that's the
way it is right now.
And btw, you generally don't want to instantiate a builder (or
marshaller or unmarshaller) directly, it's better to obtain it via
Configuration.getBuilderFactory.getBuilder(QName).
--Brent