修改用户模块
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package com.label.common.context;
|
||||
|
||||
public class CompanyContext {
|
||||
private static final ThreadLocal<Long> COMPANY_ID = new ThreadLocal<>();
|
||||
private static final ThreadLocal<Long> COMPANY_ID = new ThreadLocal<>().withInitial(() -> -1L);
|
||||
|
||||
public static void set(Long companyId) {
|
||||
COMPANY_ID.set(companyId);
|
||||
}
|
||||
|
||||
public static Long get() {
|
||||
if (COMPANY_ID.get() == null) {
|
||||
throw new IllegalStateException("Company ID not set");
|
||||
}
|
||||
return COMPANY_ID.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,12 +67,12 @@ public class TokenFilter extends OncePerRequestFilter {
|
||||
|| path.equals("/api/auth/login")
|
||||
|| path.equals("/api/video/callback")
|
||||
|| path.startsWith("/swagger-ui")
|
||||
|| path.startsWith("/v3/api-docs"); // AI 服务内部回调,不走用户 Token 认证
|
||||
|| path.startsWith("/v3/api-docs"); // AI 服务内部回调,不走用户 Token 认证
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
|
||||
FilterChain filterChain) throws ServletException, IOException {
|
||||
FilterChain filterChain) throws ServletException, IOException {
|
||||
try {
|
||||
if (!authEnabled) {
|
||||
TokenPrincipal principal = new TokenPrincipal(
|
||||
@@ -85,12 +85,17 @@ public class TokenFilter extends OncePerRequestFilter {
|
||||
}
|
||||
|
||||
String authHeader = request.getHeader("Authorization");
|
||||
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
||||
if (authHeader == null || !authHeader.toLowerCase().startsWith("bearer ")) {
|
||||
writeUnauthorized(response, "缺少或无效的认证令牌");
|
||||
return;
|
||||
}
|
||||
|
||||
String token = authHeader.substring(7).trim();
|
||||
String[] parts = authHeader.split("\\s+");
|
||||
if (parts.length != 2 || !"Bearer".equalsIgnoreCase(parts[0])) {
|
||||
writeUnauthorized(response, "无效的认证格式");
|
||||
return;
|
||||
}
|
||||
String token = parts[1];
|
||||
//String token = authHeader.substring(7).trim();
|
||||
Map<Object, Object> tokenData = redisService.hGetAll(RedisKeyManager.tokenKey(token));
|
||||
|
||||
if (tokenData == null || tokenData.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user