fix: 安全加固 — HMAC_SECRET 启动检查 + 登录锁定 + PSK 窗口配置

- SecurityCheck: 启动时 HMAC_SECRET 为空输出 ERROR 日志
- AccountServiceImpl: Caffeine 缓存实现登录失败计数/锁定
  (par.security.login-max-failures=5, login-lock-minutes=30)
- PskService: pskWindowSeconds 从 application.yml 读取
- AdminController: 清理重复 import
This commit is contained in:
mediabot-pt
2026-06-29 17:05:43 +08:00
parent c9dc78b6ef
commit bb96062b7c
4 changed files with 83 additions and 8 deletions

View File

@@ -0,0 +1,29 @@
package com.par.api.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
/**
* 启动时安全配置检查
*/
@Slf4j
@Component
public class SecurityCheck {
@Value("${hmac.secret:}")
private String hmacSecret;
@EventListener(ApplicationReadyEvent.class)
public void checkHmacSecret() {
if (hmacSecret == null || hmacSecret.isBlank()) {
log.error("============================================");
log.error(" HMAC_SECRET is not set!");
log.error(" Set HMAC_SECRET environment variable.");
log.error(" Without it, Bearer tokens are forgeable.");
log.error("============================================");
}
}
}

View File

@@ -21,8 +21,6 @@ import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.List;
/**
* 管理员控制器