Package org.apache.wss4j.dom.message
Class WSSecUsernameToken
- java.lang.Object
-
- org.apache.wss4j.dom.message.WSSecBase
-
- org.apache.wss4j.dom.message.WSSecUsernameToken
-
public class WSSecUsernameToken extends WSSecBase
Builds a WS UsernameToken. Refer to the WS specification, UsernameToken profile
-
-
Field Summary
-
Fields inherited from class org.apache.wss4j.dom.message.WSSecBase
addWSUNamespace, attachmentCallbackHandler, callbackLookup, expandXopInclude, keyIdentifierType, password, storeBytesInAttachment, user
-
-
Constructor Summary
Constructors Constructor Description WSSecUsernameToken(WSSecHeader securityHeader)
WSSecUsernameToken(Document doc)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCreated()
Add a Created element to the UsernameToken.void
addDerivedKey(boolean useMac, int iteration)
Add a derived key to the UsernameTokenvoid
addNonce()
Add a Nonce element to the UsernameToken.void
appendToHeader()
Appends the UsernameToken element to the elements already in the Security header.Document
build()
Document
build(byte[] salt)
Adds a newUsernameToken
to a soap envelope.byte[]
getDerivedKey(byte[] saltValue)
Get the derived key.String
getId()
Get the id generated duringprepare()
.boolean
getPasswordsAreEncoded()
Element
getUsernameTokenElement()
Returns theUsernameToken
element.WSTimeSource
getWsTimeSource()
boolean
isPrecisionInMilliSeconds()
void
prepare()
Creates a Username token.void
prepare(byte[] saltValue)
void
prependToHeader()
Prepends the UsernameToken element to the elements already in the Security header.void
setPasswordsAreEncoded(boolean passwordsAreEncoded)
void
setPasswordType(String pwType)
Defines how to construct the password element of theUsernameToken
.void
setPrecisionInMilliSeconds(boolean precisionInMilliSeconds)
void
setWsTimeSource(WSTimeSource wsTimeSource)
-
Methods inherited from class org.apache.wss4j.dom.message.WSSecBase
clean, getDocument, getIdAllocator, getKeyIdentifierType, getParts, getSecurityHeader, getWsDocInfo, isExpandXopInclude, setAttachmentCallbackHandler, setBodyID, setCallbackLookup, setExpandXopInclude, setIdAllocator, setKeyIdentifierType, setStoreBytesInAttachment, setUserInfo, setWsDocInfo, setWsuId
-
-
-
-
Constructor Detail
-
WSSecUsernameToken
public WSSecUsernameToken(WSSecHeader securityHeader)
-
WSSecUsernameToken
public WSSecUsernameToken(Document doc)
-
-
Method Detail
-
setPasswordType
public void setPasswordType(String pwType)
Defines how to construct the password element of theUsernameToken
.- Parameters:
pwType
- contains the password type. Only allowed values areWSS4JConstants.PASSWORD_DIGEST
andWSS4JConstants.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, int iteration)
Add a derived key to the UsernameToken- Parameters:
useMac
- whether the derived key is to be used for a MAC or notiteration
- The number of iterations to use in deriving a key
-
getDerivedKey
public byte[] getDerivedKey(byte[] saltValue) throws WSSecurityException
Get the derived key. After theprepare()
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).- Parameters:
saltValue
- The salt value to use- Returns:
- Return the derived key of this token or null if
prepare()
was not called before. - Throws:
WSSecurityException
-
setPasswordsAreEncoded
public void setPasswordsAreEncoded(boolean passwordsAreEncoded)
- Parameters:
passwordsAreEncoded
- whether passwords are encoded
-
getPasswordsAreEncoded
public boolean getPasswordsAreEncoded()
- Returns:
- whether passwords are encoded
-
getId
public String getId()
Get the id generated duringprepare()
. 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()
Creates a Username token. The method prepares and initializes a WSSec UsernameToken structure after the relevant information was set. A Before callingprepare()
all parameters such as user, password, passwordType etc. must be set. A completeUsernameToken
is constructed.
-
prepare
public void prepare(byte[] saltValue)
-
prependToHeader
public void prependToHeader()
Prepends the UsernameToken element to the elements already in the Security header. The method can be called any time afterprepare()
. This allows to insert the UsernameToken element at any position in the Security header.
-
appendToHeader
public void appendToHeader()
Appends the UsernameToken element to the elements already in the Security header. The method can be called any time afterprepare()
. This allows to insert the UsernameToken element at any position in the Security header.
-
build
public Document build(byte[] salt)
Adds a newUsernameToken
to a soap envelope. Before callingbuild()
all parameters such as user, password, passwordType etc. must be set. A completeUsernameToken
is constructed and added to thewsse:Security
header.- Parameters:
salt
- the salt value to add if we are using a derived key- Returns:
- Document with UsernameToken added
-
build
public Document build()
-
getUsernameTokenElement
public Element getUsernameTokenElement()
Returns theUsernameToken
element. The method can be called any time afterprepare()
. This allows to insert the UsernameToken element at any position in the Security header.- Returns:
- the Username Token element
-
isPrecisionInMilliSeconds
public boolean isPrecisionInMilliSeconds()
-
setPrecisionInMilliSeconds
public void setPrecisionInMilliSeconds(boolean precisionInMilliSeconds)
-
getWsTimeSource
public WSTimeSource getWsTimeSource()
-
setWsTimeSource
public void setWsTimeSource(WSTimeSource wsTimeSource)
-
-