cc.saml
Class SAML

java.lang.Object
  extended by cc.saml.SAML
Direct Known Subclasses:
SAMLAssertion

public class SAML
extends java.lang.Object

Utility that uses OpenSAML to carry out common SAML tasks.


Field Summary
private  javax.xml.parsers.DocumentBuilder builder
           
private static java.lang.String CM_PREFIX
           
private static SecureRandomIdentifierGenerator generator
           
private  java.lang.String issuerURL
           
 
Constructor Summary
SAML()
          Initialize JAXP DocumentBuilder instance for later use and reuse.
SAML(java.lang.String issuerURL)
          Initialize JAXP DocumentBuilder instance for later use and reuse, and establishes an issuer URL.
 
Method Summary
 void addAttribute(AttributeStatement statement, java.lang.String name, java.lang.String value)
          Adds a SAML attribute to an attribute statement.
static org.w3c.dom.Element addToElement(XMLObject object, org.w3c.dom.Element parent)
          Helper method to add an XMLObject as a child of a DOM Element.
 org.w3c.dom.Document asDOMDocument(XMLObject object)
          Helper method to get an XMLObject as a DOM Document.
<T> T
create(java.lang.Class<T> cls, javax.xml.namespace.QName qname)
          Slightly easier way to create objects using OpenSAML's builder system.
 Assertion createAssertion(Subject subject)
          Returns a SAML assertion with generated ID, current timestamp, given subject, and simple time-based conditions.
 Assertion createAttributeAssertion(Subject subject, java.util.Map<java.lang.String,java.lang.String> attributes)
          Returns a SAML attribute assertion.
 Assertion createAuthnAssertion(Subject subject, java.lang.String authnCtx)
          Returns a SAML authentication assertion.
 Response createResponse(Assertion assertion)
          Helper method to generate a response, based on a pre-built assertion.
 Response createResponse(Assertion assertion, java.lang.String inResponseTo)
          Helper method to generate a response, based on a pre-built assertion and query ID.
 Response createResponse(java.lang.String statusCode, java.lang.String inResponseTo)
          Helper method to generate a shell response with a given status code and query ID.
 Response createResponse(java.lang.String statusCode, java.lang.String message, java.lang.String inResponseTo)
          Helper method to generate a shell response with a given status code, status message, and query ID.
 Subject createSubject(java.lang.String username, java.lang.String format, java.lang.String confirmationMethod)
          Returns a SAML subject.
static XMLObject fromElement(org.w3c.dom.Element element)
          Helper method to read an XML object from a DOM element.
static void main(java.lang.String[] args)
          Parse the command line for a filename to read, and optionally a filename to write (absent which the application will write to the console).
 void printToFile(XMLObject object, java.lang.String filename)
          Helper method to pretty-print any XML object to a file.
 XMLObject readFromFile(java.lang.String filename)
          Helper method to read an XML object from a file.
 Issuer spawnIssuer()
          Helper method to spawn a new Issuer element based on our issuer URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

builder

private javax.xml.parsers.DocumentBuilder builder

issuerURL

private java.lang.String issuerURL

generator

private static SecureRandomIdentifierGenerator generator

CM_PREFIX

private static final java.lang.String CM_PREFIX
See Also:
Constant Field Values
Constructor Detail

SAML

public SAML()
Initialize JAXP DocumentBuilder instance for later use and reuse.


SAML

public SAML(java.lang.String issuerURL)
Initialize JAXP DocumentBuilder instance for later use and reuse, and establishes an issuer URL.

Parameters:
issuerURL - This will be used in all generated assertions
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Parse the command line for a filename to read, and optionally a filename to write (absent which the application will write to the console). Reads the given file as an XMLObject, and then dumps using a simple pretty printer.

Throws:
java.lang.Exception

create

public <T> T create(java.lang.Class<T> cls,
                    javax.xml.namespace.QName qname)
Slightly easier way to create objects using OpenSAML's builder system.


addToElement

public static org.w3c.dom.Element addToElement(XMLObject object,
                                               org.w3c.dom.Element parent)
                                        throws java.io.IOException,
                                               MarshallingException,
                                               javax.xml.transform.TransformerException
Helper method to add an XMLObject as a child of a DOM Element.

Throws:
java.io.IOException
MarshallingException
javax.xml.transform.TransformerException

asDOMDocument

public org.w3c.dom.Document asDOMDocument(XMLObject object)
                                   throws java.io.IOException,
                                          MarshallingException,
                                          javax.xml.transform.TransformerException
Helper method to get an XMLObject as a DOM Document.

Throws:
java.io.IOException
MarshallingException
javax.xml.transform.TransformerException

printToFile

public void printToFile(XMLObject object,
                        java.lang.String filename)
                 throws java.io.IOException,
                        MarshallingException,
                        javax.xml.transform.TransformerException
Helper method to pretty-print any XML object to a file.

Throws:
java.io.IOException
MarshallingException
javax.xml.transform.TransformerException

fromElement

public static XMLObject fromElement(org.w3c.dom.Element element)
                             throws java.io.IOException,
                                    UnmarshallingException,
                                    org.xml.sax.SAXException
Helper method to read an XML object from a DOM element.

Throws:
java.io.IOException
UnmarshallingException
org.xml.sax.SAXException

readFromFile

public XMLObject readFromFile(java.lang.String filename)
                       throws java.io.IOException,
                              UnmarshallingException,
                              org.xml.sax.SAXException
Helper method to read an XML object from a file.

Throws:
java.io.IOException
UnmarshallingException
org.xml.sax.SAXException

spawnIssuer

public Issuer spawnIssuer()
Helper method to spawn a new Issuer element based on our issuer URL.


createSubject

public Subject createSubject(java.lang.String username,
                             java.lang.String format,
                             java.lang.String confirmationMethod)
Returns a SAML subject.

Parameters:
username - The subject name
format - If non-null, we'll set as the subject name format
confirmationMethod - If non-null, we'll create a SubjectConfirmation element and use this as the Method attribute; must be "sender-vouches" or "bearer", as HOK would require additional parameters and so is NYI

createAssertion

public Assertion createAssertion(Subject subject)
Returns a SAML assertion with generated ID, current timestamp, given subject, and simple time-based conditions.

Parameters:
subject - Subject of the assertion

createResponse

public Response createResponse(Assertion assertion)
                        throws java.io.IOException,
                               MarshallingException,
                               javax.xml.transform.TransformerException
Helper method to generate a response, based on a pre-built assertion.

Throws:
java.io.IOException
MarshallingException
javax.xml.transform.TransformerException

createResponse

public Response createResponse(java.lang.String statusCode,
                               java.lang.String inResponseTo)
                        throws java.io.IOException,
                               MarshallingException,
                               javax.xml.transform.TransformerException
Helper method to generate a shell response with a given status code and query ID.

Throws:
java.io.IOException
MarshallingException
javax.xml.transform.TransformerException

createResponse

public Response createResponse(java.lang.String statusCode,
                               java.lang.String message,
                               java.lang.String inResponseTo)
                        throws java.io.IOException,
                               MarshallingException,
                               javax.xml.transform.TransformerException
Helper method to generate a shell response with a given status code, status message, and query ID.

Throws:
java.io.IOException
MarshallingException
javax.xml.transform.TransformerException

createResponse

public Response createResponse(Assertion assertion,
                               java.lang.String inResponseTo)
                        throws java.io.IOException,
                               MarshallingException,
                               javax.xml.transform.TransformerException
Helper method to generate a response, based on a pre-built assertion and query ID.

Throws:
java.io.IOException
MarshallingException
javax.xml.transform.TransformerException

createAuthnAssertion

public Assertion createAuthnAssertion(Subject subject,
                                      java.lang.String authnCtx)
Returns a SAML authentication assertion.

Parameters:
subject - The subject of the assertion
authnCtx - The "authentication context class reference", e.g. AuthnContext.PPT_AUTHN_CTX

addAttribute

public void addAttribute(AttributeStatement statement,
                         java.lang.String name,
                         java.lang.String value)
Adds a SAML attribute to an attribute statement.

Parameters:
statement - Existing attribute statement
name - Attribute name
value - Attribute value

createAttributeAssertion

public Assertion createAttributeAssertion(Subject subject,
                                          java.util.Map<java.lang.String,java.lang.String> attributes)
Returns a SAML attribute assertion.

Parameters:
subject - Subject of the assertion
attributes - Attributes to be stated (may be null)