|
|
@@ -1,19 +1,36 @@
|
|
|
package com.mokamrp.privates.interceptor;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.mokamrp.privates.cache.RedisCache;
|
|
|
+import com.mokamrp.privates.config.RequestWrapper;
|
|
|
+import com.mokamrp.privates.constant.ESKey;
|
|
|
import com.mokamrp.privates.mapper.pojo.User;
|
|
|
import com.mokamrp.privates.service.UserService;
|
|
|
+import com.mokamrp.privates.utils.http.HttpRequestTools;
|
|
|
import com.xxl.sso.core.conf.Conf;
|
|
|
import com.xxl.sso.core.user.XxlSsoUser;
|
|
|
+import org.apache.poi.util.SystemOutLogger;
|
|
|
+import org.elasticsearch.action.index.IndexRequest;
|
|
|
+import org.elasticsearch.action.index.IndexResponse;
|
|
|
+import org.elasticsearch.client.RequestOptions;
|
|
|
+import org.elasticsearch.client.RestHighLevelClient;
|
|
|
+import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.SortedMap;
|
|
|
|
|
|
/**
|
|
|
* @author leon token认证
|
|
|
@@ -32,6 +49,13 @@ public class AuthIntercepotor extends HandlerInterceptorAdapter {
|
|
|
@Value("${xxl-sso.excluded.paths}")
|
|
|
private String xxlSsoExcludedPaths;
|
|
|
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String env;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier(value = "restHighLevelClient")
|
|
|
+ private RestHighLevelClient esClient;
|
|
|
+
|
|
|
@Override
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
//.跨域
|
|
|
@@ -48,14 +72,6 @@ public class AuthIntercepotor extends HandlerInterceptorAdapter {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
-// if (requestUrl.equals("/private/healthy")) {
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (requestUrl.equals("/mochat/weWork/callback")) {
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-
|
|
|
XxlSsoUser xxlSsoUser = (XxlSsoUser) request.getAttribute(Conf.SSO_USER);
|
|
|
Map<String, String> plugininfo = xxlSsoUser.getPlugininfo();
|
|
|
User user = new User();
|
|
|
@@ -79,6 +95,40 @@ public class AuthIntercepotor extends HandlerInterceptorAdapter {
|
|
|
}
|
|
|
request.setAttribute("auth-user", user);
|
|
|
userService.Insert(xxlSsoUser.getPlugininfo(), xxlSsoUser.getUsername());
|
|
|
+ this.setlog(user.getName(),user.getUserId(),requestUrl,request);
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ //.@leon 用户操作日志
|
|
|
+ public Boolean setlog(String userNm,String userId,String url,HttpServletRequest request){
|
|
|
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy.MM.dd");
|
|
|
+ String dateTimeStr = LocalDateTime.now().toString();
|
|
|
+ String dateStr = LocalDate.now().format(dtf);
|
|
|
+ Long timestamp = System.currentTimeMillis()/1000;
|
|
|
+ try {
|
|
|
+ Map<String,Object> log = new HashMap<>();
|
|
|
+ SortedMap<String, String> param = HttpRequestTools.getAllParams(request);
|
|
|
+ log.put("param",param);
|
|
|
+ log.put("url", url);
|
|
|
+ log.put("userNm", userNm);
|
|
|
+ log.put("userId", userId);
|
|
|
+ log.put("datetime",dateTimeStr);
|
|
|
+ log.put("timestamp",timestamp);
|
|
|
+ String paramStr = JSON.toJSONString(log);
|
|
|
+ // 3.创建请求对象,指定索引库、类型、id(可选)
|
|
|
+ IndexRequest indexRequest = new IndexRequest(env + ESKey.MokaPrivateUrlLog + dateStr, "requestBody");
|
|
|
+ // 4.调用source方法将请求数据封装到IndexRequest请求对象中
|
|
|
+ indexRequest.source(paramStr, XContentType.JSON);
|
|
|
+ try {
|
|
|
+ // 5.调用方法进行数据通信
|
|
|
+ IndexResponse indexResponse = esClient.index(indexRequest, RequestOptions.DEFAULT);
|
|
|
+ return true;
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (IOException e1){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|