|
|
@@ -4,16 +4,22 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.zswl.dataservice.model.user.LoginUser;
|
|
|
import com.zswl.dataservice.service.base.RedisService;
|
|
|
+import com.zswl.dataservice.service.openApi.OpenApiVerifyService;
|
|
|
import com.zswl.dataservice.utils.exception.UnauthorizedException;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.codec.binary.StringUtils;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
-//@Slf4j
|
|
|
+import javax.crypto.Mac;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
public class UserContextInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
private JWTManager jwtManager;
|
|
|
@@ -22,6 +28,8 @@ public class UserContextInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
private RedisService redisService;
|
|
|
|
|
|
+ private OpenApiVerifyService openApiVerifyService;
|
|
|
+
|
|
|
public UserContextInterceptor(AuthSettings authSettings, JWTManager jwtManager, RedisService redisService) {
|
|
|
this.authSettings = authSettings;
|
|
|
this.jwtManager = jwtManager;
|
|
|
@@ -34,9 +42,10 @@ public class UserContextInterceptor implements HandlerInterceptor {
|
|
|
if (method != null && "OPTIONS".equals(method)) {
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+ if (UserAuthUtil.isFree(authSettings, request)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
String token = request.getHeader(authSettings.getTokenHeaderName());
|
|
|
-
|
|
|
if (token != null && token.length() > 0) {
|
|
|
try {
|
|
|
LoginUser user = verifyUser(token);
|
|
|
@@ -113,12 +122,10 @@ public class UserContextInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
@Override
|
|
|
public void postHandle(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void afterCompletion(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
|
|
- UserContext.shutdown();
|
|
|
}
|
|
|
|
|
|
private LoginUser verifyUser(String token) throws UnauthorizedException {
|