|
|
@@ -1,12 +1,15 @@
|
|
1
|
1
|
package com.unissoft.filter;
|
|
2
|
2
|
|
|
3
|
3
|
|
|
|
4
|
+import com.alibaba.fastjson.JSON;
|
|
|
5
|
+import com.alibaba.fastjson.JSONObject;
|
|
4
|
6
|
import com.google.common.collect.Lists;
|
|
5
|
7
|
import com.unissoft.constant.ContentType;
|
|
6
|
8
|
import com.unissoft.constant.HeaderConstant;
|
|
7
|
9
|
import com.unissoft.constant.OrderedConstant;
|
|
8
|
10
|
import com.unissoft.log.LogHelper;
|
|
9
|
11
|
import com.unissoft.model.Log;
|
|
|
12
|
+import com.unissoft.model.SysUserPO;
|
|
10
|
13
|
import com.unissoft.utils.GenerateIdUtils;
|
|
11
|
14
|
import com.unissoft.utils.IpUtils;
|
|
12
|
15
|
import com.unissoft.utils.RedisUtil;
|
|
|
@@ -23,6 +26,8 @@ import org.springframework.http.HttpHeaders;
|
|
23
|
26
|
import org.springframework.http.MediaType;
|
|
24
|
27
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
25
|
28
|
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
|
|
29
|
+import org.springframework.security.jwt.Jwt;
|
|
|
30
|
+import org.springframework.security.jwt.JwtHelper;
|
|
26
|
31
|
import org.springframework.stereotype.Component;
|
|
27
|
32
|
import org.springframework.util.StopWatch;
|
|
28
|
33
|
import org.springframework.web.reactive.function.server.HandlerStrategies;
|
|
|
@@ -32,10 +37,7 @@ import reactor.core.publisher.Flux;
|
|
32
|
37
|
import reactor.core.publisher.Mono;
|
|
33
|
38
|
|
|
34
|
39
|
import java.net.URI;
|
|
35
|
|
-import java.util.ArrayList;
|
|
36
|
|
-import java.util.Date;
|
|
37
|
|
-import java.util.List;
|
|
38
|
|
-import java.util.Objects;
|
|
|
40
|
+import java.util.*;
|
|
39
|
41
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
40
|
42
|
import java.util.concurrent.atomic.AtomicReference;
|
|
41
|
43
|
import java.util.function.Consumer;
|
|
|
@@ -96,20 +98,27 @@ public class RequestLogFilter implements GlobalFilter, Ordered {
|
|
96
|
98
|
newBody.set(true);
|
|
97
|
99
|
}
|
|
98
|
100
|
}
|
|
99
|
|
- final Log logDTO = new Log();
|
|
100
|
|
- logDTO.setLevel(Log.LEVEL.INFO);
|
|
101
|
|
- logDTO.setRequestUrl(url);
|
|
102
|
|
- logDTO.setRequestBody(requestBody.get());
|
|
103
|
|
- logDTO.setRequestMethod(method);
|
|
104
|
|
- logDTO.setRequestId(requestId.get());
|
|
105
|
|
- logDTO.setIp(IpUtils.getClientIp(request));
|
|
106
|
|
- logDTO.setCreateTime(new Date());
|
|
|
101
|
+
|
|
|
102
|
+ //获取当前操作用户名字
|
|
|
103
|
+ String userName = null;
|
|
|
104
|
+ if (request.getHeaders().get(ContentType.AUTHORIZATION) != null) {
|
|
|
105
|
+ String authorization = request.getHeaders().get(ContentType.AUTHORIZATION).get(0).replace("bearer ","");;
|
|
|
106
|
+ Jwt decode = JwtHelper.decode(authorization);
|
|
|
107
|
+ String claims = decode.getClaims();
|
|
|
108
|
+ JSONObject jsonObject = JSON.parseObject(claims);
|
|
|
109
|
+ Map<String, String> jsonMap = JSONObject.toJavaObject(jsonObject, Map.class);
|
|
|
110
|
+ JSONObject user = JSON.parseObject(jsonMap.get("user_name"));
|
|
|
111
|
+ userName = JSONObject.toJavaObject(user, SysUserPO.class).getPersonnelName();
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
|
114
|
+// final Log logDTO = new Log();
|
|
|
115
|
+ Log logDTO = new Log(Log.LEVEL.INFO, IpUtils.getClientIp(request), url, userName, requestBody.get(), requestId.get(), method, new Date());
|
|
107
|
116
|
//存入redis
|
|
108
|
|
- List<Object> logs = Lists.newArrayList();
|
|
109
|
|
- logs.add(logDTO);
|
|
|
117
|
+ List<Object> logs = Lists.newArrayList(JSON.toJSONString(logDTO));
|
|
|
118
|
+
|
|
110
|
119
|
redisUtil.lSetList(ContentType.REDIS_LOGS, logs);
|
|
111
|
120
|
|
|
112
|
|
- ServerHttpRequest serverHttpRequest = exchange.getRequest().mutate().headers(httpHeadersConsumer).build();
|
|
|
121
|
+ /* ServerHttpRequest serverHttpRequest = exchange.getRequest().mutate().headers(httpHeadersConsumer).build();
|
|
113
|
122
|
ServerWebExchange build = exchange.mutate().request(serverHttpRequest).build();
|
|
114
|
123
|
return build.getSession().flatMap(webSession -> {
|
|
115
|
124
|
logDTO.setSessionId(webSession.getId());
|
|
|
@@ -133,7 +142,8 @@ public class RequestLogFilter implements GlobalFilter, Ordered {
|
|
133
|
142
|
} else {
|
|
134
|
143
|
return chain.filter(exchange).then(LogHelper.doRecord(logDTO));
|
|
135
|
144
|
}
|
|
136
|
|
- });
|
|
|
145
|
+ });*/
|
|
|
146
|
+ return chain.filter(exchange).then(LogHelper.doRecord(logDTO));
|
|
137
|
147
|
} catch (Exception e) {
|
|
138
|
148
|
log.error("请求日志打印出现异常", e);
|
|
139
|
149
|
return chain.filter(exchange);
|