com.rsa.swsj.profiles.wss
Class UsernameToken

java.lang.Object
  extended bycom.rsa.swsj.profiles.wss.Token
      extended bycom.rsa.swsj.profiles.wss.UsernameToken

public final class UsernameToken
extends Token

The UsernameToken provides a way for a SOAP message security header to include a username and password.

When creating a UsernameToken object, it is necessary to provide a username value. Optionally, a password can be included in the <UsernameToken> element.

The following example demonstrates the creation of a new Username token and password options.
 
   // create a default context
   SWSJContext ctx = new SWJContext();
 
   String id       = "userNameId";
   String userName = "Username";
   String password = "password".;
   UsernameToken token = new UsernameToken (ctx, id, userName);
 
   // when this method is called, a password will be digested
   // and added to the token as well as >Nonce< and >Created<
   // elements.
   token.setPassword (password);
 
   // when this method is called, a password will not be digested and
   // will not be added to the token if the boolean value is set to false
   setPassword(password, true);
 
 

When receiving a SOAP message containing a <UsernameToken> object, the contents of the token are often viewed for verification purposes.

To retrieve the username contained in a UsernameToken object, simply use the getUsername() method, as shown below.
 
   UsernameToken token = <A UsernameToken obtained from a SOAP message>
   String username = token.getUsername();
 


Constructor Summary
UsernameToken(SWSJContext context)

Creates an empty UsernameToken object that is initialized only with a context.

UsernameToken(SWSJContext context, java.lang.String id, java.lang.String username)

Creates a UsernameToken object that is initialized with the context, an identifier, and the user name for that token.

 
Method Summary

 java.util.Calendar

getCreationTime()

Get the time of creation.

 byte[]

getNonce()

Get the Nonce value.

 java.lang.String

getPassword()

Get the Password value.

 java.lang.String

getUsername()

Gets the username value.

 void

setCreationTime(java.util.Calendar created)

Set the value for creation time.

 void

setPassword(java.lang.String password)

Sets the password value during creation of the token or when the password needs to be validated.

 void

setPassword(java.lang.String password, boolean addToMessage)

Sets the password value during creation of the token.

 void

setUsername(java.lang.String username)

Sets the username value.

 
Methods inherited from class com.rsa.swsj.profiles.wss.Token
getContext, getId, getNamespacePrefix, setId, setNamespacePrefix
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UsernameToken

public UsernameToken(SWSJContext context)
              throws InvalidParameterException
Creates an empty UsernameToken object that is initialized only with a context.

Parameters:
context - An object that collects a number of common parameters and state variables; for example, JCE provider.
Throws:
InvalidParameterException - If context is invalid.

UsernameToken

public UsernameToken(SWSJContext context,
                     java.lang.String id,
                     java.lang.String username)
              throws InvalidParameterException
Creates a UsernameToken object that is initialized with the context, an identifier, and the user name for that token.

Parameters:
context - A SWSJContext object that collects a number of common parameters and state variables; for example, JCE provider.
id - A String object that identifies the id to use for referencing this token.
username - A String object that is the user id for this username token.
Throws:
InvalidParameterException - If an invalid value is set.
Method Detail

getCreationTime

public java.util.Calendar getCreationTime()
Get the time of creation.

Returns:
A Calendar object that indicates the creation time and reflects coordinated universal time (UTC).

setCreationTime

public void setCreationTime(java.util.Calendar created)
                     throws InvalidParameterException
Set the value for creation time. If the creation time is not set, SWS-J generates a value for the creation time.

Parameters:
created - A Calendar object that indicates the creation time and reflects coordinated universal time (UTC).
Throws:
InvalidParameterException - If an invalid value is set.

getNonce

public byte[] getNonce()
Get the Nonce value. The Nonce value is an array of random bytes, usually generated by the toolkit, that adds additional security to the password.

Returns:
The Nonce value.

getPassword

public java.lang.String getPassword()
Get the Password value.

Returns:
A String object that contains the Password value.

setPassword

public void setPassword(java.lang.String password)
                 throws TokenException,
                        InvalidParameterException
Sets the password value during creation of the token or when the password needs to be validated. When this method is called to set a password, the password is digested and then added to the token as well as to the <Nonce> and <Created> elements.

Parameters:
password - A String object that contains the password value.
Throws:
TokenException - If the password digest is invalid.
InvalidParameterException - If an invalid value is set.

setPassword

public void setPassword(java.lang.String password,
                        boolean addToMessage)
                 throws InvalidParameterException
Sets the password value during creation of the token. When this method is called to set a password, the password is added to the token as a text password if addToMessage value is set to true; otherwise, this password is only used for a security operation.

Parameters:
addToMessage - A boolean flag that specifies if this password should be added to the output message.
Throws:
InvalidParameterException - If an invalid value is set.

getUsername

public java.lang.String getUsername()
Gets the username value.

Returns:
the username value.

setUsername

public void setUsername(java.lang.String username)
                 throws InvalidParameterException
Sets the username value.

Parameters:
username - A String object that contains the username value.
Throws:
InvalidParameterException - If an invalid value is set.