org.apache.ws.security.message.token
Class SecurityTokenReference

java.lang.Object
  extended by org.apache.ws.security.message.token.SecurityTokenReference

public class SecurityTokenReference
extends Object

Security Token Reference.

Author:
Davanum Srinivas (dims@yahoo.com).

Field Summary
protected  Element element
           
static String ENC_KEY_SHA1_URI
           
static String SECURITY_TOKEN_REFERENCE
           
static String SKI_URI
           
static QName STR_QNAME
           
static String THUMB_URI
           
 
Constructor Summary
SecurityTokenReference(Document doc)
          Constructor.
SecurityTokenReference(Element elem)
          Constructor.
SecurityTokenReference(Element elem, boolean bspCompliant)
          Constructor.
 
Method Summary
 void addTokenType(String tokenType)
          Add a wsse11:TokenType attribute to this SecurityTokenReference
 void addWSSENamespace()
          Add the WSSE Namespace to this STR.
 void addWSUNamespace()
          Add the WSU Namespace to this STR.
 boolean containsKeyIdentifier()
          Method containsKeyIdentifier.
 boolean containsReference()
          Method containsReference
 boolean containsX509Data()
          Method containsX509Data
 boolean containsX509IssuerSerial()
          Method containsX509IssuerSerial
 boolean equals(Object object)
           
 Element findProcessedTokenElement(Document doc, WSDocInfo docInfo, CallbackHandler cb, String uri, String type)
          Find a token that has been processed already - in other words, it access previous results to find the element, rather than conducting a general search
 Element findUnprocessedTokenElement(Document doc, WSDocInfo docInfo, CallbackHandler cb, String uri, String type)
          Find a token that has not been processed already - in other words, it searches for the element, rather than trying to access previous results to find the element
 Element getElement()
          Get the DOM element.
 Element getFirstElement()
          get the first child element.
 String getID()
          Get the id
 X509Certificate[] getKeyIdentifier(Crypto crypto)
          Gets the KeyIdentifier.
 String getKeyIdentifierEncodingType()
           
 String getKeyIdentifierValue()
           
 String getKeyIdentifierValueType()
           
 Reference getReference()
          Gets the Reference.
 byte[] getSKIBytes()
           
 Element getTokenElement(Document doc, WSDocInfo docInfo, CallbackHandler cb)
          Gets the signing token element, which may be a BinarySecurityToken or a SAML token.
 String getTokenType()
          Get the wsse11:TokenType attribute of this SecurityTokenReference
 X509Certificate[] getX509IssuerSerial(Crypto crypto)
          Gets the certificate identified with X509 issuerSerial data.
 X509Certificate getX509SKIAlias(Crypto crypto)
           
 int hashCode()
           
 int length(String namespace, String localname)
          Method length.
 int lengthKeyIdentifier()
          Method lengthKeyIdentifier.
 int lengthReference()
          Method lengthReference.
 int lengthX509Data()
          Method lengthX509Data.
 int lengthX509IssuerSerial()
          Method lengthX509IssuerSerial.
 void setID(String id)
          set the id.
 void setKeyIdentifier(String valueType, String keyIdVal)
           
 void setKeyIdentifier(String valueType, String keyIdVal, boolean base64)
           
 void setKeyIdentifier(X509Certificate cert)
          Sets the KeyIdentifier Element as a X509 certificate.
 void setKeyIdentifierEncKeySHA1(String value)
           
 void setKeyIdentifierSKI(X509Certificate cert, Crypto crypto)
          Sets the KeyIdentifier Element as a X509 Subject-Key-Identifier (SKI).
 void setKeyIdentifierThumb(X509Certificate cert)
          Sets the KeyIdentifier Element as a Thumbprint.
 void setReference(Reference ref)
          set the reference.
 void setUnknownElement(Element unknownElement)
          Set an unknown element.
 void setX509Data(DOMX509Data domX509Data)
          Sets the X509Data.
 String toString()
          return the string representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SECURITY_TOKEN_REFERENCE

public static final String SECURITY_TOKEN_REFERENCE
See Also:
Constant Field Values

STR_QNAME

public static final QName STR_QNAME

SKI_URI

public static final String SKI_URI
See Also:
Constant Field Values

THUMB_URI

public static final String THUMB_URI
See Also:
Constant Field Values

ENC_KEY_SHA1_URI

public static final String ENC_KEY_SHA1_URI
See Also:
Constant Field Values

element

protected Element element
Constructor Detail

SecurityTokenReference

public SecurityTokenReference(Element elem)
                       throws WSSecurityException
Constructor.

Parameters:
elem - A SecurityTokenReference element
Throws:
WSSecurityException

SecurityTokenReference

public SecurityTokenReference(Element elem,
                              boolean bspCompliant)
                       throws WSSecurityException
Constructor.

Parameters:
elem - A SecurityTokenReference element
bspCompliant - whether the SecurityTokenReference processing complies with the BSP spec
Throws:
WSSecurityException

SecurityTokenReference

public SecurityTokenReference(Document doc)
Constructor.

Parameters:
doc - The Document
Method Detail

addWSSENamespace

public void addWSSENamespace()
Add the WSSE Namespace to this STR. The namespace is not added by default for efficiency purposes.


addWSUNamespace

public void addWSUNamespace()
Add the WSU Namespace to this STR. The namespace is not added by default for efficiency purposes.


addTokenType

public void addTokenType(String tokenType)
Add a wsse11:TokenType attribute to this SecurityTokenReference

Parameters:
tokenType - the wsse11:TokenType attribute to add

getTokenType

public String getTokenType()
Get the wsse11:TokenType attribute of this SecurityTokenReference

Returns:
the value of the wsse11:TokenType attribute

setReference

public void setReference(Reference ref)
set the reference.

Parameters:
ref -

getReference

public Reference getReference()
                       throws WSSecurityException
Gets the Reference.

Returns:
the Reference element contained in this SecurityTokenReference
Throws:
WSSecurityException

getTokenElement

public Element getTokenElement(Document doc,
                               WSDocInfo docInfo,
                               CallbackHandler cb)
                        throws WSSecurityException
Gets the signing token element, which may be a BinarySecurityToken or a SAML token. The method gets the URI attribute of the Reference contained in the SecurityTokenReference and tries to find the referenced Element in the document. Alternatively, it gets the value of the KeyIdentifier contained in the SecurityTokenReference and tries to find the referenced Element in the document.

Parameters:
doc - the document that contains the binary security token element. This could be different from the document that contains the SecurityTokenReference (STR). See STRTransform.derefenceBST() method
docInfo - A WSDocInfo object containing previous results
cb - A CallbackHandler object to obtain tokens that are not in the message
Returns:
Element containing the signing token, must be a BinarySecurityToken
Throws:
WSSecurityException - if the referenced element is not found.

findUnprocessedTokenElement

public Element findUnprocessedTokenElement(Document doc,
                                           WSDocInfo docInfo,
                                           CallbackHandler cb,
                                           String uri,
                                           String type)
                                    throws WSSecurityException
Find a token that has not been processed already - in other words, it searches for the element, rather than trying to access previous results to find the element

Parameters:
doc - Parent Document
docInfo - WSDocInfo instance
cb - CallbackHandler instance
uri - URI of the element
type - Type of the element
Returns:
A DOM element
Throws:
WSSecurityException

findProcessedTokenElement

public Element findProcessedTokenElement(Document doc,
                                         WSDocInfo docInfo,
                                         CallbackHandler cb,
                                         String uri,
                                         String type)
                                  throws WSSecurityException
Find a token that has been processed already - in other words, it access previous results to find the element, rather than conducting a general search

Parameters:
doc - Parent Document
docInfo - WSDocInfo instance
cb - CallbackHandler instance
uri - URI of the element
type - Type of the element
Returns:
A DOM element
Throws:
WSSecurityException

setKeyIdentifier

public void setKeyIdentifier(X509Certificate cert)
                      throws WSSecurityException
Sets the KeyIdentifier Element as a X509 certificate. Takes a X509 certificate, converts its data into base 64 and inserts it into a wsse:KeyIdentifier element, which is placed in the wsse:SecurityTokenReference element.

Parameters:
cert - is the X509 certificate to be inserted as key identifier
Throws:
WSSecurityException

setKeyIdentifierSKI

public void setKeyIdentifierSKI(X509Certificate cert,
                                Crypto crypto)
                         throws WSSecurityException
Sets the KeyIdentifier Element as a X509 Subject-Key-Identifier (SKI). Takes a X509 certificate, gets the SKI data, converts it into base 64 and inserts it into a wsse:KeyIdentifier element, which is placed in the wsse:SecurityTokenReference element.

Parameters:
cert - is the X509 certificate to get the SKI
crypto - is the Crypto implementation. Used to read SKI info bytes from certificate
Throws:
WSSecurityException

setKeyIdentifierThumb

public void setKeyIdentifierThumb(X509Certificate cert)
                           throws WSSecurityException
Sets the KeyIdentifier Element as a Thumbprint. Takes a X509 certificate, computes its thumbprint using SHA-1, converts into base 64 and inserts it into a wsse:KeyIdentifier element, which is placed in the wsse:SecurityTokenReference element.

Parameters:
cert - is the X509 certificate to get the thumbprint
Throws:
WSSecurityException

setKeyIdentifierEncKeySHA1

public void setKeyIdentifierEncKeySHA1(String value)
                                throws WSSecurityException
Throws:
WSSecurityException

setKeyIdentifier

public void setKeyIdentifier(String valueType,
                             String keyIdVal)
                      throws WSSecurityException
Throws:
WSSecurityException

setKeyIdentifier

public void setKeyIdentifier(String valueType,
                             String keyIdVal,
                             boolean base64)
                      throws WSSecurityException
Throws:
WSSecurityException

getFirstElement

public Element getFirstElement()
get the first child element.

Returns:
the first Element child node

getKeyIdentifier

public X509Certificate[] getKeyIdentifier(Crypto crypto)
                                   throws WSSecurityException
Gets the KeyIdentifier.

Returns:
the the X509 certificate or zero if a unknown key identifier type was detected.
Throws:
WSSecurityException

getKeyIdentifierValue

public String getKeyIdentifierValue()

getKeyIdentifierValueType

public String getKeyIdentifierValueType()

getKeyIdentifierEncodingType

public String getKeyIdentifierEncodingType()

getX509SKIAlias

public X509Certificate getX509SKIAlias(Crypto crypto)
                                throws WSSecurityException
Throws:
WSSecurityException

getSKIBytes

public byte[] getSKIBytes()

setX509Data

public void setX509Data(DOMX509Data domX509Data)
Sets the X509Data.

Parameters:
domX509Data - the DOMX509Data to put into this SecurityTokenReference

setUnknownElement

public void setUnknownElement(Element unknownElement)
Set an unknown element.

Parameters:
unknownElement - the org.w3c.dom.Element to put into this SecurityTokenReference

getX509IssuerSerial

public X509Certificate[] getX509IssuerSerial(Crypto crypto)
                                      throws WSSecurityException
Gets the certificate identified with X509 issuerSerial data.

Returns:
a certificate array or null if nothing found
Throws:
WSSecurityException

containsReference

public boolean containsReference()
Method containsReference

Returns:
true if the SecurityTokenReference contains a wsse:Reference element

lengthReference

public int lengthReference()
Method lengthReference.

Returns:
number of wsse:Reference elements in the SecurityTokenReference

containsX509IssuerSerial

public boolean containsX509IssuerSerial()
Method containsX509IssuerSerial

Returns:
true if the SecurityTokenReference contains a ds:IssuerSerial element

containsX509Data

public boolean containsX509Data()
Method containsX509Data

Returns:
true if the SecurityTokenReference contains a ds:X509Data element

lengthX509IssuerSerial

public int lengthX509IssuerSerial()
Method lengthX509IssuerSerial.

Returns:
number of ds:IssuerSerial elements in the SecurityTokenReference

lengthX509Data

public int lengthX509Data()
Method lengthX509Data.

Returns:
number of ds:IssuerSerial elements in the SecurityTokenReference

containsKeyIdentifier

public boolean containsKeyIdentifier()
Method containsKeyIdentifier.

Returns:
true if the SecurityTokenReference contains a wsse:KeyIdentifier element

lengthKeyIdentifier

public int lengthKeyIdentifier()
Method lengthKeyIdentifier.

Returns:
number of wsse:KeyIdentifier elements in the SecurityTokenReference

length

public int length(String namespace,
                  String localname)
Method length.

Parameters:
namespace -
localname -
Returns:
number of elements with matching localname and namespace

getElement

public Element getElement()
Get the DOM element.

Returns:
the DOM element

setID

public void setID(String id)
set the id.

Parameters:
id -

getID

public String getID()
Get the id

Returns:
the wsu ID of the element

toString

public String toString()
return the string representation.

Overrides:
toString in class Object
Returns:
a representation of this SecurityTokenReference element as a String

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object


Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.