重写复现方法

This commit is contained in:
2025-08-28 14:32:12 +08:00
parent f3f919053f
commit 0c26e0911e
8 changed files with 87 additions and 29 deletions

View File

@@ -0,0 +1,24 @@
package com.mini.capi.config;
import com.mini.capi.utils.vToken;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
@Component
public class AuthInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
String token = request.getHeader("Authorization");
if (token == null || !vToken.isValidToken(token)) {
response.sendRedirect(request.getContextPath() + "/login");
return false;
}
return true;
}
}

View File

@@ -0,0 +1,31 @@
package com.mini.capi.config;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {
private final AuthInterceptor authInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authInterceptor)
.addPathPatterns("/**") // 需要拦截的路径
.excludePathPatterns( // 排除的路径
"/login",
"/index.html",
"/assets/**",
"/resource/**",
"/swagger-ui/**",
"/v3/api-docs/**",
"/Sys/jobs/**",
"/Sys/hosts/**",
"/Sys/dbs/**",
"/Sys/login/**"
);
}
}