Class WSSecUsernameToken


  • public class WSSecUsernameToken
    extends WSSecBase
    Builds a WS UsernameToken. Refer to the WS specification, UsernameToken profile
    • Constructor Detail

      • WSSecUsernameToken

        public WSSecUsernameToken​(WSSecHeader securityHeader)
      • WSSecUsernameToken

        public WSSecUsernameToken​(Document doc)
    • Method Detail

      • 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 not
        iteration - The number of iterations to use in deriving a key
      • getDerivedKey

        public byte[] getDerivedKey​(byte[] saltValue)
                             throws WSSecurityException
        Get the derived key. After the prepare() 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 during prepare(). 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 calling prepare() all parameters such as user, password, passwordType etc. must be set. A complete UsernameToken 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 after prepare(). 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 after prepare(). This allows to insert the UsernameToken element at any position in the Security header.
      • build

        public Document build​(byte[] salt)
        Adds a new UsernameToken to a soap envelope. Before calling build() all parameters such as user, password, passwordType etc. must be set. A complete UsernameToken is constructed and added to the wsse:Security header.
        Parameters:
        salt - the salt value to add if we are using a derived key
        Returns:
        Document with UsernameToken added
      • getUsernameTokenElement

        public Element getUsernameTokenElement()
        Returns the UsernameToken element. The method can be called any time after prepare(). 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)
      • setWsTimeSource

        public void setWsTimeSource​(WSTimeSource wsTimeSource)