Files
springboot-template/src/main/java/com/aisi/template/constants/SecurityConstants.java
shenjianZ 40c85c3c1f feat: 实现完整的 RBAC 权限管理系统与基础设施增强
在初始认证基础上,新增完整的 RBAC 权限模型(角色、权限、菜单三级管理),
  集成审计日志、接口限流、登录失败锁定、Refresh Token 机制、Redis 分布式缓存与锁、
  RocketMQ 消息队列,并引入 Flyway 数据库版本管理,同时补充项目文档与使用示例
2026-04-10 10:58:22 +08:00

104 lines
2.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.aisi.template.constants;
/**
* 安全相关常量类
* 定义系统中的安全相关常量
*
* 主要分类:
* 1. Token 相关Token 前缀、过期时间
* 2. Redis 键前缀:黑名单、刷新令牌、限流、登录尝试
* 3. 安全配置:最大失败次数、锁定时长
*
* @author Claude
* @since 2024-04-09
*/
public class SecurityConstants {
/**
* JWT Token 请求头名称
* - HTTP 请求头Authorization
* - 示例Authorization: Bearer {token}
*/
public static final String TOKEN_HEADER = "Authorization";
/**
* JWT Token 前缀
* - Bearer 认证方案
* - 示例Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
*/
public static final String TOKEN_PREFIX = "Bearer ";
/**
* JWT Token 类型
* - 用于文档标识
* - 值Bearer
*/
public static final String TOKEN_TYPE = "Bearer";
/**
* Token 黑名单 Redis 键前缀
* - 格式token:blacklist:{jti}
* - jtiJWT IDJWT 唯一标识)
* - 示例token:blacklist:abc123-def456
*/
public static final String REDIS_KEY_BLACKLIST_PREFIX = "token:blacklist:";
/**
* Refresh Token Redis 键前缀
* - 格式refresh_token:{tokenHash}
* - tokenHashToken 的 SHA-256 哈希值
* - 示例refresh_token:a1b2c3...
*/
public static final String REDIS_KEY_REFRESH_TOKEN_PREFIX = "refresh_token:";
/**
* 限流 Redis 键前缀
* - 格式rate_limit:{type}:{identifier}
* - typeip按 IP、user按用户、global全局
* - identifierIP 地址、用户ID 等
* - 示例rate_limit:ip:192.168.1.1
*/
public static final String REDIS_KEY_RATE_LIMIT_PREFIX = "rate_limit:";
/**
* 登录尝试 Redis 键前缀
* - 格式login_attempts:{username}
* - 示例login_attempts:user01
*/
public static final String REDIS_KEY_LOGIN_ATTEMPTS_PREFIX = "login_attempts:";
/**
* 默认 Access Token 过期时间(秒)
* - 1 小时 = 3600 秒
*/
public static final long DEFAULT_ACCESS_TOKEN_EXPIRATION = 3600;
/**
* 默认 Refresh Token 过期时间(秒)
* - 7 天 = 604800 秒
*/
public static final long DEFAULT_REFRESH_TOKEN_EXPIRATION = 604800;
/**
* 最大登录失败次数
* - 超过此次数后锁定账户
* - 默认5 次
*/
public static final int MAX_LOGIN_ATTEMPTS = 5;
/**
* 默认账户锁定时长(分钟)
* - 连续失败达到阈值后的锁定时长
* - 默认30 分钟
*/
public static final int DEFAULT_LOCK_DURATION_MINUTES = 30;
/**
* 私有构造函数
* - 防止实例化
*/
private SecurityConstants() {
// 防止实例化
}
}