Implementation:A616567126 GPT WEB JAVA JwtUtil
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Security, Authentication |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Concrete tool for creating, verifying, and extracting claims from HMAC256-signed JSON Web Tokens with Redis-based token validation, provided by the auth0 java-jwt library.
Description
The JwtUtil class is a static utility for JWT operations:
createToken(user)— Creates a JWT with userId, name, type claims; 8-hour expiry; HMAC256 signing. Stores MD5 hash in Redis (7-day TTL) and client type (isMobile) in Redis.verifierToken()— Verifies JWT signature from the current request's token headergetUserId()— Extracts userId claim from the request tokengetType()— Extracts user type claim (used to block non-admin access to /sys paths)getRemainingTime()— Returns remaining token validity in milliseconds
The secret key TOKEN_KEY is hardcoded. The token is read from the token HTTP header.
Usage
Import this utility when you need to:
- Create JWT tokens after login/registration
- Extract user ID from the current request's JWT
- Verify token validity
Code Reference
Source Location
- Repository: GPT-WEB-JAVA
- File: src/main/java/com/intelligent/bot/utils/sys/JwtUtil.java
Signature
public class JwtUtil {
public static String createToken(User user);
public static boolean verifierToken();
public static long getRemainingTime();
public static Long getUserId();
public static Integer getType();
}
Import
import com.intelligent.bot.utils.sys.JwtUtil;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| user | User | Yes (createToken) | User entity with id, name, type, isMobile |
| (request) | HttpServletRequest | Yes (others) | Token read from "token" header |
Outputs
| Name | Type | Description |
|---|---|---|
| createToken returns | String | Signed JWT string (8h expiry) |
| verifierToken returns | boolean | True if JWT signature valid |
| getUserId returns | Long | User ID from token, or 0L if invalid |
| getType returns | Integer | User type from token, or 0 if invalid |
Usage Examples
Creating a Token
String token = JwtUtil.createToken(user);
// Token contains: issuer=SYSTEM, subject=BEAN, audience=SSP
// Claims: userId, name, type
// Expiry: 8 hours from now
// Side effects:
// Redis: "token:{userId}" → md5(token), TTL=7 days
// Redis: "client:{userId}" → isMobile, TTL=7 days
Extracting User ID in a Controller
Long userId = JwtUtil.getUserId();
// Reads "token" header from current request
// Verifies JWT signature
// Returns userId claim, or 0L on failure
Related Pages
Implements Principle
Requires Environment
- Environment:A616567126_GPT_WEB_JAVA_Spring_Boot_Runtime
- Environment:A616567126_GPT_WEB_JAVA_Redis_Cache
- Environment:A616567126_GPT_WEB_JAVA_JWT_Auth_Library
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment