Creating SAML Objects from Scratch
New SAMLObjects are created through a builder class. This class is responsible for creating an object using some particular implementation and setting up some initial information such as element name and schema type.
- Retrieve the builder factory using the
- Retrieve the builder for the SAMLObject you're trying to create using the
org.opensaml.xml.XMLObjectBuilderFactory#getBuilder(QName)method. The QName constants on the interfaces for the various SAMLObjects should be used as the argument, however creating a new QName from scratch will work as well.
- Invoke the appropriate
buildObject()method on the returned
SAMLObjectBuilder. Normally the no-argument method is sufficient but other methods allow you to explicitly set the element name and schema type of the constructed object.
The following example demonstrates creating a SAML 1.1 Assertion from scratch. The try/catch code has been omitted here for readability.
This more advanced example uses the schema type name and builds an element of the Assertion schema type but with a different name in a different name space.
Additional Building Information
- While every SAMLObjectBuilder has a no-argument builder method the more generic XMLObjectBuilder need not have this method.
- Builders are thread-safe and stateless. You may use an instance to create any number of objects.