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 voidaddCreated()Add a Created element to the UsernameToken.voidaddDerivedKey(int iteration)Add a derived key to the UsernameTokenvoidaddNonce()Add a Nonce element to the UsernameToken.voidappendToHeader()Appends the UsernameToken element to the elements already in the Security header.Documentbuild()Documentbuild(byte[] salt)Adds a newUsernameTokento a soap envelope.byte[]getDerivedKey(byte[] saltValue)Get the derived key.StringgetId()Get the id generated duringprepare().booleangetPasswordsAreEncoded()ElementgetUsernameTokenElement()Returns theUsernameTokenelement.WSTimeSourcegetWsTimeSource()booleanisPrecisionInMilliSeconds()voidprepare()Creates a Username token.voidprepare(byte[] saltValue)voidprependToHeader()Prepends the UsernameToken element to the elements already in the Security header.voidsetPasswordsAreEncoded(boolean passwordsAreEncoded)voidsetPasswordType(String pwType)Defines how to construct the password element of theUsernameToken.voidsetPrecisionInMilliSeconds(boolean precisionInMilliSeconds)voidsetWsTimeSource(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_DIGESTandWSS4JConstants.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(int iteration)
Add a derived key to the UsernameToken- Parameters:
iteration- The number of iterations to use in deriving a key
-
getDerivedKey
public byte[] getDerivedKey(byte[] saltValue) throws WSSecurityExceptionGet 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 completeUsernameTokenis 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 newUsernameTokento a soap envelope. Before callingbuild()all parameters such as user, password, passwordType etc. must be set. A completeUsernameTokenis constructed and added to thewsse:Securityheader.- 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 theUsernameTokenelement. 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)
-
-