org.apache.struts2.util

## Class TokenHelper

- java.lang.Object
- - org.apache.struts2.util.TokenHelper

-     public class TokenHelper
      extends Object

  TokenHelper

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_TOKEN_NAME` The default name to map the token value
    `static String` | `TOKEN_NAME_FIELD` The name of the field which will hold the token name
    `static String` | `TOKEN_NAMESPACE` The default namespace for storing token session values

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TokenHelper()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `buildTokenSessionAttributeName(String tokenName)` Build a name-spaced token session attribute name based on the given token name.
    `static String` | `generateGUID()`
    `static String` | `getToken()` Gets a transaction token from the params in the ServletActionContext using the default token name.
    `static String` | `getToken(String tokenName)` Gets the Token value from the params in the ServletActionContext using the given name
    `static String` | `getTokenName()` Gets the token name from the Parameters in the ServletActionContext
    `static void` | `setSessionToken(String tokenName, String token)` Put a given named token into the session map.
    `static String` | `setToken()` Sets a transaction token into the session using the default token name.
    `static String` | `setToken(String tokenName)` Sets a transaction token into the session based on the provided token name.
    `static boolean` | `validToken()` Checks for a valid transaction token in the current request params.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TOKEN_NAMESPACE

          public static final String TOKEN_NAMESPACE

      The default namespace for storing token session values
      See Also:
        Constant Field Values

    - #### DEFAULT_TOKEN_NAME

          public static final String DEFAULT_TOKEN_NAME

      The default name to map the token value
      See Also:
        Constant Field Values

    - #### TOKEN_NAME_FIELD

          public static final String TOKEN_NAME_FIELD

      The name of the field which will hold the token name
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TokenHelper

          public TokenHelper()

  - ### Method Detail

    - #### setToken

          public static String setToken()

      Sets a transaction token into the session using the default token name.
      Returns:
        the token string

    - #### setToken

          public static String setToken(String tokenName)

      Sets a transaction token into the session based on the provided token name.
      Parameters:
        `tokenName` - the token name based on which a generated token value is stored into session; for actual session store, this name will be prefixed by a namespace.
      Returns:
        the token string

    - #### setSessionToken

          public static void setSessionToken(String tokenName,
                                             String token)

      Put a given named token into the session map. The token will be stored with a namespace prefix prepended.
      Parameters:
        `tokenName` - the token name based on which given token value is stored into session; for actual session store, this name will be prefixed by a namespace.
        `token` - the token value to store

    - #### buildTokenSessionAttributeName

          public static String buildTokenSessionAttributeName(String tokenName)

      Build a name-spaced token session attribute name based on the given token name.
      Parameters:
        `tokenName` - the token name to prefix
      Returns:
        the name space prefixed session token name

    - #### getToken

          public static String getToken()

      Gets a transaction token from the params in the ServletActionContext using the default token name.
      Returns:
        token

    - #### getToken

          public static String getToken(String tokenName)

      Gets the Token value from the params in the ServletActionContext using the given name
      Parameters:
        `tokenName` - the name of the parameter which holds the token value
      Returns:
        the token String or null, if the token could not be found

    - #### getTokenName

          public static String getTokenName()

      Gets the token name from the Parameters in the ServletActionContext
      Returns:
        the token name found in the params, or null if it could not be found

    - #### validToken

          public static boolean validToken()

      Checks for a valid transaction token in the current request params. If a valid token is found, it is removed so the it is not valid again.
      Returns:
        false if there was no token set into the params (check by looking for `TOKEN_NAME_FIELD`), true if a valid token is found

    - #### generateGUID

          public static String generateGUID()

Copyright © 2000–2024 Apache Software Foundation. All rights reserved.