|
|
@@ -1,6 +1,7 @@
|
|
|
package com.jzg.filter;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.jzg.commons.exception.TokenExpireException;
|
|
|
import com.jzg.config.JzgTokenService;
|
|
|
import jakarta.servlet.FilterChain;
|
|
|
import jakarta.servlet.ServletException;
|
|
|
@@ -12,6 +13,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.filter.OncePerRequestFilter;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -20,6 +22,7 @@ import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
+@Component
|
|
|
public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
|
|
|
|
|
private AuthenticationManager authenticationManager;
|
|
|
@@ -58,6 +61,16 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
|
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
|
filterChain.doFilter(request,response);
|
|
|
return;
|
|
|
+ }else{
|
|
|
+ response.setContentType("application/json");
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("code",401);
|
|
|
+ json.put("msg","token valied failed");
|
|
|
+ // 将 Token 返回给前端
|
|
|
+ response.getWriter().write(json.toJSONString());
|
|
|
+
|
|
|
+ // 确保状态码为 200 OK,不进行重定向
|
|
|
+ response.setStatus(HttpServletResponse.SC_OK);
|
|
|
}
|
|
|
}
|
|
|
}
|