Class UsernameToken
java.lang.Object
org.apache.ws.security.message.token.UsernameToken
UsernameToken according to WS Security specifications, UsernameToken profile.
- Author:
- Davanum Srinivas (dims@yahoo.com), Werner Dittmann (Werner.Dittmann@siemens.com)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionUsernameToken
(boolean milliseconds, Document doc) Constructs aUsernameToken
object according to the defined parameters.UsernameToken
(boolean milliseconds, Document doc, String pwType) Constructs aUsernameToken
object according to the defined parameters.UsernameToken
(Element elem) Constructs aUsernameToken
object and parses thewsse:UsernameToken
element to initialize it. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCreated
(boolean milliseconds, Document doc) Creates and adds a Created element to this UsernameTokenvoid
addIteration
(Document doc, int iteration) Creates and adds a Iteration element to this UsernameTokenvoid
Creates and adds a Nonce element to this UsernameTokenbyte[]
Adds and otionally creates a Salt element to this UsernameToken.static String
doPasswordDigest
(String nonce, String created, String password) static byte[]
generateDerivedKey
(String password, byte[] salt, int iteration) This static method generates a derived key as defined in WSS Username Token Profile.static byte[]
generateSalt
(boolean useForMac) This static method generates a 128 bit salt value as defined in WSS Username Token Profile.Get the created timestamp.Returns the dom element of thisUsernameToken
object.getID()
Gets the id.int
Get the Iteration value of this UsernameToken.getName()
Get the user name.getNonce()
Get the nonce.Gets the password string.byte[]
getSalt()
Get the Salt value of this UsernameToken.byte[]
Gets the secret key as per WS-Trust spec.byte[]
getSecretKey
(int keylen, String labelString) Gets the secret key as per WS-Trust spec.boolean
isHashed()
Get the hashed inidicator.void
Set the id of this username token.void
Set the user name.void
setPassword
(String pwd) Sets the password string.toString()
Returns the string representation of the token.
-
Field Details
-
PASSWORD_TYPE
- See Also:
-
element
-
elementUsername
-
elementPassword
-
elementNonce
-
elementCreated
-
elementSalt
-
elementIteration
-
passwordType
-
hashed
protected boolean hashed -
TOKEN
-
-
Constructor Details
-
UsernameToken
Constructs aUsernameToken
object and parses thewsse:UsernameToken
element to initialize it.- Parameters:
elem
- thewsse:UsernameToken
element that contains the UsernameToken data- Throws:
WSSecurityException
-
UsernameToken
Constructs aUsernameToken
object according to the defined parameters. This constructes set the password encoding toWSConstants.PASSWORD_DIGEST
- Parameters:
doc
- the SOAP envelope asDocument
-
UsernameToken
Constructs aUsernameToken
object according to the defined parameters.- Parameters:
doc
- the SOAP envelope asDocument
pwType
- the required password encoding, eitherWSConstants.PASSWORD_DIGEST
orWSConstants.PASSWORD_TEXT
ornull
if no password required
-
-
Method Details
-
addNonce
Creates and adds a Nonce element to this UsernameToken -
addCreated
Creates and adds a Created element to this UsernameToken -
addSalt
Adds and otionally creates a Salt element to this UsernameToken. If thesaltCalue
isnull
the the method generates a new salt. Otherwise it uses the the given value.- Parameters:
doc
- The Document for the UsernameTokensaltValue
- The salt to add, if null generate a new salt valuemac
- Iftrue
then an optionally generated value is usable for a MAC- Returns:
- Returns the added salt
-
addIteration
Creates and adds a Iteration element to this UsernameToken -
getName
Get the user name.- Returns:
- the data from the user name element.
-
setName
Set the user name.- Parameters:
name
- sets a text node containing the use name into the user name element.
-
getNonce
Get the nonce.- Returns:
- the data from the nonce element.
-
getCreated
Get the created timestamp.- Returns:
- the data from the created time element.
-
getPassword
Gets the password string. This is the password as it is in the password element of a username, token. Thus it can be either plain text or the password digest value.- Returns:
- the password string or
null
if no such node exists.
-
getSalt
Get the Salt value of this UsernameToken.- Returns:
- Returns the binary Salt value or
null
if no Salt value is available in the username token. - Throws:
WSSecurityException
-
getIteration
public int getIteration()Get the Iteration value of this UsernameToken.- Returns:
- Returns the Iteration value. If no Iteration was specified in the username token the default value according to the specification is returned.
-
isHashed
public boolean isHashed()Get the hashed inidicator. If the indicator istrue> the password of the
UsernameToken
was encoded usingWSConstants.PASSWORD_DIGEST
- Returns:
- the hashed indicator.
-
getPasswordType
- Returns:
- Returns the passwordType.
-
setPassword
Sets the password string. This function sets the password in theUsernameToken
either as plain text or encodes the password according to the WS Security specifications, UsernameToken profile, into a password digest.- Parameters:
pwd
- the password to use
-
doPasswordDigest
-
getElement
Returns the dom element of thisUsernameToken
object.- Returns:
- the
wsse:UsernameToken
element
-
toString
Returns the string representation of the token. -
getID
Gets the id.- Returns:
- the value of the
wsu:Id
attribute of this username token
-
setID
Set the id of this username token.- Parameters:
id
- the value for thewsu:Id
attribute of this username token
-
getSecretKey
public byte[] getSecretKey()Gets the secret key as per WS-Trust spec. This method uses default setting to generate the secret key. These default values are suitable for .NET WSE.- Returns:
- a secret key constructed from information conatined in this username token
-
getSecretKey
Gets the secret key as per WS-Trust spec.- Parameters:
keylen
- How many bytes to generate for the keylabelString
- the label used to generate the seed- Returns:
- a secret key constructed from information conatined in this username token
-
generateDerivedKey
public static byte[] generateDerivedKey(String password, byte[] salt, int iteration) throws WSSecurityException This static method generates a derived key as defined in WSS Username Token Profile.- Parameters:
password
- The password to include in the key generationsalt
- The Salt valueiteration
- The Iteration value. If zero (0) is given the mehtod uses the default value- Returns:
- Returns the derived key a byte array
- Throws:
WSSecurityException
-
generateSalt
public static byte[] generateSalt(boolean useForMac) This static method generates a 128 bit salt value as defined in WSS Username Token Profile.- Parameters:
useForMac
- Iftrue
define the Salt for use in a MAC- Returns:
- Returns the 128 bit salt value as byte array
-