org.apache.ws.security.message
Class WSSecUsernameToken

java.lang.Object
  extended byorg.apache.ws.security.message.WSSecBase
      extended byorg.apache.ws.security.message.WSSecUsernameToken

public class WSSecUsernameToken
extends WSSecBase

Builds a WS UsernameToken. Refer to the WS specification, UsernameToken profile

Author:
Werner Dittmann ([email protected]).

Field Summary
 
Fields inherited from class org.apache.ws.security.message.WSSecBase
doDebug, keyIdentifierType, parts, password, user, wssConfig
 
Constructor Summary
WSSecUsernameToken()
          Constructor.
 
Method Summary
 void addCreated()
          Add a Created element to the UsernameToken.
 void addDerivedKey(boolean useMac, byte[] saltValue, int iteration)
          Add a derived key to the UsernameToken
 void addNonce()
          Add a Nonce element to the UsernameToken.
 void appendToHeader(WSSecHeader secHeader)
          Appends the UsernameToken element to the elements already in the Security header.
 org.w3c.dom.Document build(org.w3c.dom.Document doc, WSSecHeader secHeader)
          Adds a new UsernameToken to a soap envelope.
 byte[] getDerivedKey()
          Get the derived key.
 java.lang.String getId()
          Get the id generated during prepare().
 byte[] getSecretKey()
          Get the derived secret key.
 org.w3c.dom.Element getUsernameTokenElement()
          Returns the UsernameToken element.
 void prepare(org.w3c.dom.Document doc)
          Creates a Username token.
 void prependToHeader(WSSecHeader secHeader)
          Prepends the UsernameToken element to the elements already in the Security header.
 void setPasswordType(java.lang.String pwType)
          Defines how to construct the password element of the UsernameToken.
 
Methods inherited from class org.apache.ws.security.message.WSSecBase
getKeyIdentifierType, setBodyID, setKeyIdentifierType, setParts, setUserInfo, setWsConfig, setWsuId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WSSecUsernameToken

public WSSecUsernameToken()
Constructor.

Method Detail

setPasswordType

public void setPasswordType(java.lang.String pwType)
Defines how to construct the password element of the UsernameToken.

Parameters:
pwType - contains the password type. Only allowed values are WSConstants.PASSWORD_DIGEST and WSConstants.PASSWORD_TEXT. or null when no password is needed.

addNonce

public void addNonce()
Add a Nonce element to the UsernameToken.


addCreated

public void addCreated()
Add a Created element to the UsernameToken.


addDerivedKey

public void addDerivedKey(boolean useMac,
                          byte[] saltValue,
                          int iteration)
Add a derived key to the UsernameToken

Parameters:
useMac - whether the derived key is to be used for a MAC or not
saltValue - The salt value to use
iteration - The number of iterations to use in deriving a key

getSecretKey

public byte[] getSecretKey()
                    throws WSSecurityException
Get the derived secret key. After the prepare() method was called use this method to compute a derived secret key. If "useDerivedKey" is set, then the returned secret key is derived as per the UsernameToken 1.1 specification. Otherwise, the generation of this secret key is according to the WS-Trust specifications.

Returns:
Return the derived secret key of this token or null if prepare() was not called before.
Throws:
WSSecurityException

getDerivedKey

public byte[] getDerivedKey()
                     throws WSSecurityException
Get the derived key. After the prepare() method was called use this method to compute a derived key. The generation of this secret key is according to the UsernameTokenProfile 1.1 specification (section 4 - Key Derivation).

Returns:
Return the derived key of this token or null if prepare() was not called before.
Throws:
WSSecurityException

getId

public java.lang.String getId()
Get the id generated during prepare(). Returns the the value of wsu:Id attribute of this UsernameToken.

Returns:
Return the wsu:Id of this token or null if prepare() was not called before.

prepare

public void prepare(org.w3c.dom.Document doc)
Creates a Username token. The method prepares and initializes a WSSec UsernameToken structure after the relevant information was set. A Before calling prepare() all parameters such as user, password, passwordType etc. must be set. A complete UsernameToken is constructed.

Parameters:
doc - The SOAP envelope as W3C document

prependToHeader

public void prependToHeader(WSSecHeader secHeader)
Prepends the UsernameToken element to the elements already in the Security header. The method can be called any time after prepare(). This allows to insert the UsernameToken element at any position in the Security header.

Parameters:
secHeader - The security header that holds the Signature element.

appendToHeader

public void appendToHeader(WSSecHeader secHeader)
Appends the UsernameToken element to the elements already in the Security header. The method can be called any time after prepare(). This allows to insert the UsernameToken element at any position in the Security header.

Parameters:
secHeader - The security header that holds the Signature element.

build

public org.w3c.dom.Document build(org.w3c.dom.Document doc,
                                  WSSecHeader secHeader)
Adds a new UsernameToken to a soap envelope. Before calling build() all parameters such as user, password, passwordType etc. must be set. A complete UsernameToken is constructed and added to the wsse:Security header.

Parameters:
doc - The SOAP envelope as W3C document
secHeader - The security header inside the SOAP envelope
Returns:
Document with UsernameToken added

getUsernameTokenElement

public org.w3c.dom.Element getUsernameTokenElement()
Returns the UsernameToken element. The method can be called any time after prepare(). This allows to insert the UsernameToken element at any position in the Security header.

Returns:
the Username Token element


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