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

Implementation:A616567126 GPT WEB JAVA AuthorizationInterceptor

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

Overview

Concrete tool for intercepting HTTP requests to validate JWT tokens against Redis-stored hashes and enforce URL whitelist and admin path access control, provided by the Spring MVC framework.

Description

The AuthorizationInterceptor class implements HandlerInterceptor and runs before every controller method. The preHandle() method:

  1. Checks if the request path is in the URL whitelist (CommandLineInitResource.urlList); rejects if not
  2. Blocks non-admin users (type != -1) from accessing paths containing "sys"
  3. Extracts userId from JWT and validates the MD5(token) against the Redis-stored hash
  4. Returns 403 with JSON error if any check fails

This provides a hybrid stateless/stateful authentication: the JWT signature is verified (stateless), and the token is also checked against Redis (stateful, enabling server-side revocation).

Usage

Import this interceptor when you need to:

  • Understand request authentication flow
  • Add or modify URL whitelist entries
  • Debug authentication failures

Code Reference

Source Location

  • Repository: GPT-WEB-JAVA
  • File: src/main/java/com/intelligent/bot/config/interceptor/AuthorizationInterceptor.java

Signature

@Component
public class AuthorizationInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse httpServletResponse, Object handler) throws IOException;
}

Import

import com.intelligent.bot.config.interceptor.AuthorizationInterceptor;

I/O Contract

Inputs

Name Type Required Description
request HttpServletRequest Yes Current HTTP request with "token" header

Outputs

Name Type Description
preHandle returns boolean true if request allowed, false if blocked (with JSON error response)

Usage Examples

Authentication Flow

// preHandle() executes on every request:
// 1. Check URL whitelist: CommandLineInitResource.urlList.contains(servletPath)
//    → If not found: return 403 "Illegal exception request"
// 2. Check admin access: JwtUtil.getType() != -1 && path.contains("sys")
//    → If non-admin accessing /sys: return 403 "暂无访问权限"
// 3. Validate token: Redis token hash == MD5(request token)
//    → If mismatch: return 403 "身份校验失败,请重新登录"
// 4. Return true (request proceeds to controller)

Registered in InterceptorConfiguration

// InterceptorConfiguration registers the interceptor:
// registry.addInterceptor(authorizationInterceptor)
//         .addPathPatterns("/**")
//         .excludePathPatterns(WhiteApiList.WHITE_API_LIST);

Related Pages

Implements Principle

Requires Environment

Page Connections

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