重写复现方法
This commit is contained in:
24
src/main/java/com/mini/capi/config/AuthInterceptor.java
Normal file
24
src/main/java/com/mini/capi/config/AuthInterceptor.java
Normal 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;
|
||||
}
|
||||
}
|
||||
31
src/main/java/com/mini/capi/config/WebMvcConfig.java
Normal file
31
src/main/java/com/mini/capi/config/WebMvcConfig.java
Normal 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/**"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user