Class PasswordResetTokenStore

java.lang.Object
org.apache.wiki.auth.PasswordResetTokenStore

public final class PasswordResetTokenStore extends Object
In-memory store of single-use, expiring password reset tokens, used by LostPassword.jsp.

A password reset is a two-step operation: a cryptographically random token is issued and mailed to the account owner (issue(String)), and the stored credential is only changed when that token is presented back (redeem(String)). Only a SHA-256 hash of the token is kept server-side, tokens expire after TOKEN_TTL_MS, are removed on first use, and at most one token per account may be outstanding at a time (which also acts as a simple per-account throttle). The store itself is bounded to MAX_PENDING entries as a global backstop.

Note: the store is per-JVM. On a multi-node deployment a token must be redeemed on the node that issued it.

Since:
2.12.4
  • Field Details

  • Method Details

    • getInstance

      Returns the shared store instance.
      Returns:
      the shared PasswordResetTokenStore.
    • issue

      public String issue(String loginName)
      Issues a new reset token for the given login name. The raw token is returned exactly once, for inclusion in the reset e-mail; only its SHA-256 hash is retained. If a non-expired token is already outstanding for the account, or the store is full, no token is issued.
      Parameters:
      loginName - the login name the token is bound to.
      Returns:
      the raw token, or null if issuance was throttled.
    • redeem

      public String redeem(String token)
      Redeems a token: if it matches a stored, non-expired token hash, the token is removed (single use) and the login name it was issued for is returned. Comparison of the hashed values is constant-time.
      Parameters:
      token - the raw token as received from the user.
      Returns:
      the login name the token was bound to, or null if the token is unknown, already used or expired.