Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:A616567126 GPT WEB JAVA JWT Auth Library

From Leeroopedia
Knowledge Sources
Domains Security, Authentication
Last Updated 2026-10-13 18:00 GMT

Overview

Auth0 java-jwt 3.4.0 and JJWT 0.9.1 for JWT-based authentication with HMAC256 signing and Redis-backed token validation with 7-day expiry.

Description

This environment provides the JWT authentication stack for GPT-WEB-JAVA. It uses Auth0's java-jwt library version 3.4.0 for JWT creation, verification, and claim extraction. Tokens are signed with HMAC256 using a hardcoded secret key. JWT tokens carry claims for userId, name, and user type, with an 8-hour expiration time. On token creation, the MD5 hash of the token is stored in Redis with a 7-day TTL under the key prefix `TOKEN:`. Token validation checks both the JWT signature and the Redis-stored hash, enabling server-side token revocation. The JJWT 0.9.1 dependency is also present but the primary JWT operations use the auth0 library.

Usage

Use this environment for all authentication and authorization operations. Required by JwtUtil (token creation/verification), AuthorizationInterceptor (request-level auth), and AuthController (login/registration token issuance).

System Requirements

Category Requirement Notes
OS Any (Java-based) Cross-platform
Hardware Minimal JWT operations are CPU-light
Network N/A Purely local cryptographic operations

Dependencies

Java Packages (Maven)

  • `com.auth0:java-jwt` = 3.4.0
  • `io.jsonwebtoken:jjwt` = 0.9.1
  • `cn.hutool:hutool-all` = 5.8.12 (for SecureUtil.md5)

Credentials

  • `TOKEN_KEY`: Hardcoded HMAC256 signing secret in `JwtUtil.java` (value: `RdecmaE4As3HhQ51vz6OZgtkMW7FfCb0`)

Security Warning: The JWT signing key is hardcoded in source. For production, this should be externalized to an environment variable or configuration file.

Quick Install

# Dependencies are declared in pom.xml:
# com.auth0:java-jwt:3.4.0
# io.jsonwebtoken:jjwt:0.9.1
# No separate installation needed — included in Maven build

Code Evidence

JWT creation with HMAC256 from `JwtUtil.java:129-147`:

private static final String TOKEN_KEY = "RdecmaE4As3HhQ51vz6OZgtkMW7FfCb0";

private static String getTokenString(User user) {
    Algorithm algorithm = Algorithm.HMAC256(TOKEN_KEY);
    Date date = new Date();
    String token = JWT.create()
            .withIssuer(ISSUSER)
            .withSubject(SUBJECT)
            .withAudience(AUDIENCE)
            .withIssuedAt(date)
            .withExpiresAt(new Date(date.getTime() + 3600L * 1000L * 8L))
            .withClaim("userId", user.getId())
            .withClaim("name", user.getName())
            .withClaim("type", user.getType())
            .sign(algorithm);
    RedisUtil.setCacheObject(CommonConst.REDIS_KEY_PREFIX_TOKEN + user.getId(),
            SecureUtil.md5(token), CommonConst.TOKEN_EXPIRE_TIME, TimeUnit.DAYS);
    return token;
}

Token verification from `JwtUtil.java:45-58`:

public static boolean verifierToken() {
    String token = getRequestToken();
    if(Strings.isBlank(token)) { return false; }
    JWTVerifier verifier = getJWTVerifier();
    try {
        verifier.verify(token);
        return true;
    } catch (JWTVerificationException exception) {
        log.error(exception.getMessage());
        return false;
    }
}

Token expiry constants from `CommonConst.java:9-10`:

public static final long TOKEN_EXPIRE_TIME = 7L;
public static final String REDIS_KEY_PREFIX_TOKEN = "TOKEN:";

Common Errors

Error Message Cause Solution
`JWTVerificationException` Token signature invalid or expired Re-authenticate to obtain a new token
`Token not found in Redis` Token was revoked or Redis was flushed User must log in again
`Claim 'userId' is null` Token missing required claim Ensure token was created by JwtUtil.createToken
`401 Unauthorized` (interceptor) Token header missing or blank Client must send `token` HTTP header with JWT

Compatibility Notes

  • java-jwt 4.x: Not compatible with 3.4.0; API changed significantly in 4.x (e.g., `Algorithm.HMAC256` requires byte array, not String).
  • JJWT 0.9.1: Present but not actively used for core JWT operations; auth0 java-jwt is the primary library.
  • Token header: Uses custom header name `token` (not the standard `Authorization: Bearer`).
  • Token expiry mismatch: JWT expiry is 8 hours, but Redis TTL is 7 days. After JWT expires, user must re-authenticate even if Redis hash still exists.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment