Class UsernameToken
java.lang.Object
org.apache.wss4j.dom.message.token.UsernameToken
UsernameToken according to WS Security specifications, UsernameToken profile.
Enhanced to support digest password type for username token signature
Enhanced to support passwordless usernametokens as allowed by spec.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionUsernameToken(boolean milliseconds, Document doc) Constructs aUsernameTokenobject according to the defined parameters.UsernameToken(boolean milliseconds, Document doc, String pwType) Constructs aUsernameTokenobject according to the defined parameters.UsernameToken(boolean milliseconds, Document doc, WSTimeSource timeSource, String pwType) UsernameToken(Element elem, boolean allowNamespaceQualifiedPasswordTypes, BSPEnforcer bspEnforcer) Constructs aUsernameTokenobject and parses thewsse:UsernameTokenelement to initialize it. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCreated(boolean milliseconds, WSTimeSource timeSource, Document doc) Creates and adds a Created element to this UsernameTokenvoidaddCreated(boolean milliseconds, Document doc) Creates and adds a Created element to this UsernameTokenvoidaddIteration(Document doc, int iteration) Creates and adds a Iteration element to this UsernameTokenvoidCreates and adds a Nonce element to this UsernameTokenvoidAdds a Salt element to this UsernameToken.voidAdd the WSSE Namespace to this UT.voidAdd the WSU Namespace to this UT.booleanReturn true if this UsernameToken contains a Password elementCreate a WSUsernameTokenPrincipal from this UsernameToken objectbooleanGet the created timestamp.Return the Created Element as a Date objectbyte[]getDerivedKey(BSPEnforcer bspEnforcer, String rawPassword) This method gets a derived key as defined in WSS Username Token Profile.Returns the dom element of thisUsernameTokenobject.getID()Gets the id.intGet the Iteration value of this UsernameToken.getName()Get the user name.getNonce()Get the nonce.Gets the password string.booleanbyte[]getSalt()Get the Salt value of this UsernameToken.inthashCode()booleanReturn whether the UsernameToken represented by this class is to be used for key derivation as per the UsernameToken Profile 1.1.booleanisHashed()Get the hashed indicator.voidSet the id of this username token.voidSet the user name.voidsetPassword(String pwd) Sets the password string.voidsetPasswordsAreEncoded(boolean passwordsAreEncoded) toString()Returns the string representation of the token.booleanverifyCreated(int timeToLive, int futureTimeToLive) Return true if the "Created" value is before the current time minus the timeToLive argument, and if the Created value is not "in the future".
-
Field Details
-
BASE64_ENCODING
- See Also:
-
PASSWORD_TYPE
- See Also:
-
DEFAULT_ITERATION
public static final int DEFAULT_ITERATION- See Also:
-
TOKEN
-
-
Constructor Details
-
UsernameToken
public UsernameToken(Element elem, boolean allowNamespaceQualifiedPasswordTypes, BSPEnforcer bspEnforcer) throws WSSecurityException Constructs aUsernameTokenobject and parses thewsse:UsernameTokenelement to initialize it.- Parameters:
elem- thewsse:UsernameTokenelement that contains the UsernameToken dataallowNamespaceQualifiedPasswordTypes- whether to allow (wsse) namespace qualified password types or not (for interop with WCF)bspEnforcer- a BSPEnforcer instance to enforce BSP rules- Throws:
WSSecurityException
-
UsernameToken
Constructs aUsernameTokenobject according to the defined parameters. This constructs set the password encoding toWSS4JConstants.PASSWORD_DIGEST- Parameters:
doc- the SOAP envelope asDocument
-
UsernameToken
Constructs aUsernameTokenobject according to the defined parameters.- Parameters:
doc- the SOAP envelope asDocumentpwType- the required password encoding, eitherWSS4JConstants.PASSWORD_DIGESTorWSS4JConstants.PASSWORD_TEXTorWSS4JConstants.PW_NONEnullif no password required
-
UsernameToken
-
-
Method Details
-
addWSSENamespace
public void addWSSENamespace()Add the WSSE Namespace to this UT. The namespace is not added by default for efficiency purposes. -
addWSUNamespace
public void addWSUNamespace()Add the WSU Namespace to this UT. The namespace is not added by default for efficiency purposes. -
addNonce
Creates and adds a Nonce element to this UsernameToken -
addCreated
Creates and adds a Created element to this UsernameToken -
addCreated
Creates and adds a Created element to this UsernameToken -
addSalt
Adds a Salt element to this UsernameToken.- Parameters:
doc- The Document for the UsernameTokensaltValue- The salt to add.
-
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.
-
getCreatedDate
Return the Created Element as a Date object- Returns:
- the Created Date
-
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
nullif no such node exists.
-
containsPasswordElement
public boolean containsPasswordElement()Return true if this UsernameToken contains a Password element -
getSalt
Get the Salt value of this UsernameToken.- Returns:
- Returns the binary Salt value or
nullif 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 indicator. If the indicator istrue> the password of theUsernameTokenwas encoded usingWSS4JConstants.PASSWORD_DIGEST- Returns:
- the hashed indicator.
-
getPasswordType
- Returns:
- Returns the passwordType.
-
setPassword
Sets the password string. This function sets the password in theUsernameTokeneither 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
-
setPasswordsAreEncoded
public void setPasswordsAreEncoded(boolean passwordsAreEncoded) - Parameters:
passwordsAreEncoded- whether passwords are encoded
-
getPasswordsAreEncoded
public boolean getPasswordsAreEncoded()- Returns:
- whether passwords are encoded
-
getElement
Returns the dom element of thisUsernameTokenobject.- Returns:
- the
wsse:UsernameTokenelement
-
toString
Returns the string representation of the token. -
getID
Gets the id.- Returns:
- the value of the
wsu:Idattribute of this username token
-
setID
Set the id of this username token.- Parameters:
id- the value for thewsu:Idattribute of this username token
-
getDerivedKey
This method gets a derived key as defined in WSS Username Token Profile.- Parameters:
rawPassword- The raw password to use to derive the key- Returns:
- Returns the derived key as a byte array
- Throws:
WSSecurityException
-
isDerivedKey
Return whether the UsernameToken represented by this class is to be used for key derivation as per the UsernameToken Profile 1.1. It does this by checking that the username token has salt and iteration values.- Throws:
WSSecurityException
-
createPrincipal
Create a WSUsernameTokenPrincipal from this UsernameToken object- Throws:
WSSecurityException
-
verifyCreated
public boolean verifyCreated(int timeToLive, int futureTimeToLive) Return true if the "Created" value is before the current time minus the timeToLive argument, and if the Created value is not "in the future".- Parameters:
timeToLive- the value in seconds for the validity of the Created timefutureTimeToLive- the value in seconds for the future validity of the Created time- Returns:
- true if the UsernameToken is before (now-timeToLive), false otherwise
-
hashCode
public int hashCode() -
equals
-