public class UsernameToken extends Object
Modifier and Type | Field and Description |
---|---|
static String |
BASE64_ENCODING |
static int |
DEFAULT_ITERATION |
protected Element |
element |
protected Element |
elementCreated |
protected Element |
elementIteration |
protected Element |
elementNonce |
protected Element |
elementPassword |
protected Element |
elementSalt |
protected Element |
elementUsername |
protected boolean |
hashed |
static String |
PASSWORD_TYPE |
protected String |
passwordType |
static QName |
TOKEN |
Constructor and Description |
---|
UsernameToken(boolean milliseconds,
Document doc)
Constructs a
UsernameToken object according to the defined
parameters. |
UsernameToken(boolean milliseconds,
Document doc,
String pwType)
Constructs a
UsernameToken object according to the defined
parameters. |
UsernameToken(boolean milliseconds,
Document doc,
WSTimeSource timeSource,
String pwType) |
UsernameToken(Element elem)
Constructs a
UsernameToken object and parses the
wsse:UsernameToken element to initialize it. |
UsernameToken(Element elem,
boolean allowNamespaceQualifiedPasswordTypes,
boolean bspCompliant)
Constructs a
UsernameToken object and parses the
wsse:UsernameToken element to initialize it. |
Modifier and Type | Method and Description |
---|---|
void |
addCreated(boolean milliseconds,
Document doc)
Creates and adds a Created element to this UsernameToken
|
void |
addCreated(boolean milliseconds,
WSTimeSource timeSource,
Document doc)
Creates and adds a Created element to this UsernameToken
|
void |
addIteration(Document doc,
int iteration)
Creates and adds a Iteration element to this UsernameToken
|
void |
addNonce(Document doc)
Creates and adds a Nonce element to this UsernameToken
|
byte[] |
addSalt(Document doc,
byte[] saltValue,
boolean mac)
Adds and optionally creates a Salt element to this UsernameToken.
|
void |
addWSSENamespace()
Add the WSSE Namespace to this UT.
|
void |
addWSUNamespace()
Add the WSU Namespace to this UT.
|
boolean |
containsPasswordElement()
Return true if this UsernameToken contains a Password element
|
Principal |
createPrincipal()
Create a WSUsernameTokenPrincipal from this UsernameToken object
|
static String |
doPasswordDigest(String nonce,
String created,
byte[] password) |
static String |
doPasswordDigest(String nonce,
String created,
String password) |
boolean |
equals(Object object) |
static byte[] |
generateDerivedKey(byte[] password,
byte[] salt,
int iteration)
This static method generates a derived key as defined in WSS Username
Token Profile.
|
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.
|
String |
getCreated()
Get the created timestamp.
|
Date |
getCreatedDate()
Return the Created Element as a Date object
|
byte[] |
getDerivedKey()
This method gets a derived key as defined in WSS Username Token Profile.
|
Element |
getElement()
Returns the dom element of this
UsernameToken object. |
String |
getID()
Gets the id.
|
int |
getIteration()
Get the Iteration value of this UsernameToken.
|
String |
getName()
Get the user name.
|
String |
getNonce()
Get the nonce.
|
String |
getPassword()
Gets the password string.
|
boolean |
getPasswordsAreEncoded() |
String |
getPasswordType() |
byte[] |
getSalt()
Get the Salt value of this UsernameToken.
|
byte[] |
getSecretKey()
Gets the secret key as per WS-Trust spec.
|
byte[] |
getSecretKey(int keylen)
Gets the secret key as per WS-Trust spec.
|
byte[] |
getSecretKey(int keylen,
String labelString)
Gets the secret key as per WS-Trust spec.
|
int |
hashCode() |
boolean |
isDerivedKey()
Return whether the UsernameToken represented by this class is to be used
for key derivation as per the UsernameToken Profile 1.1.
|
boolean |
isHashed()
Get the hashed indicator.
|
void |
setID(String id)
Set the id of this username token.
|
void |
setName(String name)
Set the user name.
|
void |
setPassword(String pwd)
Sets the password string.
|
void |
setPasswordsAreEncoded(boolean passwordsAreEncoded) |
void |
setRawPassword(RequestData data)
Set the raw (plain text) password used to compute secret key.
|
String |
toString()
Returns the string representation of the token.
|
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".
|
public static final String BASE64_ENCODING
public static final String PASSWORD_TYPE
public static final int DEFAULT_ITERATION
public static final QName TOKEN
protected Element element
protected Element elementUsername
protected Element elementPassword
protected Element elementNonce
protected Element elementCreated
protected Element elementSalt
protected Element elementIteration
protected String passwordType
protected boolean hashed
public UsernameToken(Element elem) throws WSSecurityException
UsernameToken
object and parses the
wsse:UsernameToken
element to initialize it.elem
- the wsse:UsernameToken
element that contains
the UsernameToken dataWSSecurityException
public UsernameToken(Element elem, boolean allowNamespaceQualifiedPasswordTypes, boolean bspCompliant) throws WSSecurityException
UsernameToken
object and parses the
wsse:UsernameToken
element to initialize it.elem
- the wsse:UsernameToken
element that contains
the UsernameToken dataallowNamespaceQualifiedPasswordTypes
- whether to allow (wsse)
namespace qualified password types or not (for interop with WCF)bspCompliant
- whether the UsernameToken processing complies with the BSP specWSSecurityException
public UsernameToken(boolean milliseconds, Document doc)
UsernameToken
object according to the defined
parameters. This constructs set the password encoding to
WSConstants.PASSWORD_DIGEST
doc
- the SOAP envelope as Document
public UsernameToken(boolean milliseconds, Document doc, String pwType)
UsernameToken
object according to the defined
parameters.doc
- the SOAP envelope as Document
pwType
- the required password encoding, either
WSConstants.PASSWORD_DIGEST
or
WSConstants.PASSWORD_TEXT
or
WSConstants.PW_NONE
null
if no
password requiredpublic UsernameToken(boolean milliseconds, Document doc, WSTimeSource timeSource, String pwType)
public void addWSSENamespace()
public void addWSUNamespace()
public void addNonce(Document doc)
public void addCreated(boolean milliseconds, Document doc)
public void addCreated(boolean milliseconds, WSTimeSource timeSource, Document doc)
public byte[] addSalt(Document doc, byte[] saltValue, boolean mac)
saltValue
is null
the the method
generates a new salt. Otherwise it uses the the given value.doc
- The Document for the UsernameTokensaltValue
- The salt to add, if null generate a new salt valuemac
- If true
then an optionally generated value is
usable for a MACpublic void addIteration(Document doc, int iteration)
public String getName()
public void setName(String name)
name
- sets a text node containing the use name into the user name
element.public String getNonce()
public String getCreated()
public Date getCreatedDate()
public String getPassword()
null
if no such node exists.public boolean containsPasswordElement()
public byte[] getSalt() throws WSSecurityException
null
if no Salt
value is available in the username token.WSSecurityException
public int getIteration()
public boolean isHashed()
true> the password of the
UsernameToken
was encoded using WSConstants.PASSWORD_DIGEST
public String getPasswordType()
public void setPassword(String pwd)
UsernameToken
either as plain text or encodes the password
according to the WS Security specifications, UsernameToken profile, into
a password digest.pwd
- the password to usepublic void setRawPassword(RequestData data) throws WSSecurityException
WSSecurityException
public void setPasswordsAreEncoded(boolean passwordsAreEncoded)
passwordsAreEncoded
- whether passwords are encodedpublic boolean getPasswordsAreEncoded()
public static String doPasswordDigest(String nonce, String created, byte[] password)
public static String doPasswordDigest(String nonce, String created, String password)
public Element getElement()
UsernameToken
object.wsse:UsernameToken
elementpublic String toString()
public String getID()
wsu:Id
attribute of this username
tokenpublic void setID(String id)
id
- the value for the wsu:Id
attribute of this
username tokenpublic byte[] getSecretKey()
public byte[] getSecretKey(int keylen)
public byte[] getSecretKey(int keylen, String labelString)
keylen
- How many bytes to generate for the keylabelString
- the label used to generate the seedpublic static byte[] generateDerivedKey(byte[] password, byte[] salt, int iteration) throws WSSecurityException
password
- The password to include in the key generationsalt
- The Salt valueiteration
- The Iteration value. If zero (0) is given the method uses the
default valueWSSecurityException
public static byte[] generateDerivedKey(String password, byte[] salt, int iteration) throws WSSecurityException
password
- The password to include in the key generationsalt
- The Salt valueiteration
- The Iteration value. If zero (0) is given the method uses the
default valueWSSecurityException
public byte[] getDerivedKey() throws WSSecurityException
WSSecurityException
public boolean isDerivedKey() throws WSSecurityException
WSSecurityException
public Principal createPrincipal()
public boolean verifyCreated(int timeToLive, int futureTimeToLive)
timeToLive
- the value in seconds for the validity of the Created timefutureTimeToLive
- the value in seconds for the future validity of the Created timepublic static byte[] generateSalt(boolean useForMac)
useForMac
- If true
define the Salt for use in a MACCopyright © 2004–2015 The Apache Software Foundation. All rights reserved.