|
@@ -0,0 +1,53 @@
|
|
|
+package com.persagy.apm.common.handler;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.persagy.apm.common.constant.AppContextConstants;
|
|
|
+import com.persagy.apm.common.context.AppContext;
|
|
|
+import com.persagy.apm.common.context.DefaultAppContext;
|
|
|
+import com.persagy.apm.common.context.poems.PoemsContext;
|
|
|
+import com.persagy.apm.common.utils.SecureAES;
|
|
|
+import com.persagy.security.exception.AESDecryptException;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2021/3/8 9:35 上午
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+public class PoemsContextHandler extends HandlerInterceptorAdapter {
|
|
|
+
|
|
|
+ /** 忽略的url - swagger的文档不校验 */
|
|
|
+ private static final String[] IGNORE_URL = {".html", ".js", ".css", "/swagger-resources"};
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
+ String requestURI = request.getRequestURI();
|
|
|
+ if (StringUtils.containsAny(requestURI, IGNORE_URL)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ String userId = request.getParameter("userId");
|
|
|
+ String loginDevice = request.getParameter("loginDevice");
|
|
|
+ String pd = request.getParameter("pd");
|
|
|
+
|
|
|
+ PoemsContext.setContext(userId, loginDevice, pd);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
|
|
+ PoemsContext.unloadContext();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
|
|
+ PoemsContext.unloadContext();
|
|
|
+ }
|
|
|
+}
|