Class CmsTokenValidator

java.lang.Object
org.opencms.ui.login.CmsTokenValidator

public class CmsTokenValidator extends Object
Helper class for dealing with authorization tokens for the 'forgot password' functionality.

When a user requests a link to change his password, an authorization token is generated and also stored in the user's additional info (in a slightly different form). When the user opens the 'change password' link sent to him, the authentication token is validated by comparing it to the token in the user's additional info. Additionally, the system checks whether the age of the token stored in the additional infos is older than the maximum age, which can also be configured.

  • Field Details

  • Constructor Details

  • Method Details

    • clearToken

      public static void clearToken(CmsObject cms, CmsUser user) throws CmsException
      Removes an authorization token from the user's additional information.

      Parameters:
      cms - the CMS context
      user - the user
      Throws:
      CmsException - if something goes wrong
    • createToken

      public static String createToken(CmsObject cms, CmsUser user, long currentTime) throws CmsException
      Creates a new token for the given user and stores it in the user's additional info.

      Parameters:
      cms - the CMS context
      user - the user
      currentTime - the current time
      Returns:
      the authorization token
      Throws:
      CmsException - if something goes wrong
    • getUser

      public CmsUser getUser()
      Gets the user.

      Returns:
      the user
    • validateToken

      public String validateToken(CmsObject cms, String token, long maxAgeMillis) throws CmsException
      Validates the authentication token against the token stored in the user's additional info.

      Parameters:
      cms - the CMS context
      token - the authentication token
      maxAgeMillis - the maximum token age in milliseconds
      Returns:
      null if the validation is succesfull, or a string containing the error message if not
      Throws:
      CmsException - if something goes wrong