|
@@ -20,6 +20,7 @@ import org.springframework.core.Ordered;
|
20
|
20
|
import org.springframework.core.io.buffer.DataBuffer;
|
21
|
21
|
import org.springframework.http.HttpHeaders;
|
22
|
22
|
import org.springframework.http.MediaType;
|
|
23
|
+import org.springframework.http.codec.ServerCodecConfigurer;
|
23
|
24
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
24
|
25
|
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
25
|
26
|
import org.springframework.http.server.reactive.ServerHttpResponse;
|
|
@@ -27,12 +28,12 @@ import org.springframework.stereotype.Component;
|
27
|
28
|
import org.springframework.util.CollectionUtils;
|
28
|
29
|
import org.springframework.web.reactive.function.BodyInserter;
|
29
|
30
|
import org.springframework.web.reactive.function.BodyInserters;
|
30
|
|
-import org.springframework.web.reactive.function.server.HandlerStrategies;
|
31
|
31
|
import org.springframework.web.reactive.function.server.ServerRequest;
|
32
|
32
|
import org.springframework.web.server.ServerWebExchange;
|
33
|
33
|
import reactor.core.publisher.Flux;
|
34
|
34
|
import reactor.core.publisher.Mono;
|
35
|
35
|
|
|
36
|
+import javax.annotation.PostConstruct;
|
36
|
37
|
import javax.annotation.Resource;
|
37
|
38
|
import java.util.List;
|
38
|
39
|
import java.util.Map;
|
|
@@ -45,7 +46,7 @@ import java.util.stream.Collectors;
|
45
|
46
|
**/
|
46
|
47
|
@Component
|
47
|
48
|
@Slf4j
|
48
|
|
-public class DecryptRequestionBodyFilter extends JedisUtil implements GlobalFilter, Ordered {
|
|
49
|
+public class DecryptRequestionBodyFilter implements GlobalFilter, Ordered {
|
49
|
50
|
@Value("${Xh-St}")
|
50
|
51
|
private String xhSt;
|
51
|
52
|
@Value("${whitelistAPI}")
|
|
@@ -55,6 +56,16 @@ public class DecryptRequestionBodyFilter extends JedisUtil implements GlobalFilt
|
55
|
56
|
|
56
|
57
|
@Resource
|
57
|
58
|
private ModuleCheckMapper moduleCheckMapper;
|
|
59
|
+ @Resource
|
|
60
|
+ private ServerCodecConfigurer codecConfigurer;
|
|
61
|
+ @Resource
|
|
62
|
+ private JedisUtil jedisUtil;
|
|
63
|
+
|
|
64
|
+ @PostConstruct
|
|
65
|
+ public void init() {
|
|
66
|
+ ServerCodecConfigurer.ServerDefaultCodecs serverDefaultCodecs = codecConfigurer.defaultCodecs();
|
|
67
|
+ serverDefaultCodecs.maxInMemorySize(ConfigKey.paramsize);//设置限制50MB
|
|
68
|
+ }
|
58
|
69
|
|
59
|
70
|
@SneakyThrows
|
60
|
71
|
@Override
|
|
@@ -93,13 +104,13 @@ public class DecryptRequestionBodyFilter extends JedisUtil implements GlobalFilt
|
93
|
104
|
String key = ApiUtil.listToStr(headers.get("Xh-Token-Key"));
|
94
|
105
|
String token = ApiUtil.listToStr(headers.get("Xh-Token-Value"));
|
95
|
106
|
if (!rtn) {//非白名单接口验证token
|
96
|
|
- String redis_token = get(key);//系统缓存中保存的token
|
|
107
|
+ String redis_token = jedisUtil.get(key);//系统缓存中保存的token
|
97
|
108
|
|
98
|
109
|
if (ApiUtil.isEmpty(token) || !token.equals(redis_token)
|
99
|
110
|
|| ApiUtil.isEmpty(key) || !key.split("_")[1].equals(userid)) {
|
100
|
111
|
throw new GatewayException(2, "登录失效");
|
101
|
112
|
} else {
|
102
|
|
- refreshToken(key, redis_token);//刷新token
|
|
113
|
+ jedisUtil.refreshToken(key, redis_token);//刷新token
|
103
|
114
|
}
|
104
|
115
|
}
|
105
|
116
|
|
|
@@ -108,7 +119,7 @@ public class DecryptRequestionBodyFilter extends JedisUtil implements GlobalFilt
|
108
|
119
|
SchoolVo schoolVo = moduleCheckMapper.getSchoolCloudByUserid(Integer.parseInt(userid));
|
109
|
120
|
if(schoolVo.getUsertype() == 1 || schoolVo.getUsertype() == 0){
|
110
|
121
|
String umodule_key = schoolVo.getCloudcode() + "_module_" + schoolVo.getSchoolid() + "_" + userid;
|
111
|
|
- String umodule_value = get(umodule_key);//获取用户的模块权限
|
|
122
|
+ String umodule_value = jedisUtil.get(umodule_key);//获取用户的模块权限
|
112
|
123
|
List<String> userModules = null;//用户模块全新啊
|
113
|
124
|
|
114
|
125
|
if(ApiUtil.isEmpty(umodule_value)){
|
|
@@ -116,7 +127,7 @@ public class DecryptRequestionBodyFilter extends JedisUtil implements GlobalFilt
|
116
|
127
|
userModules = moduleCheckMapper.listModuleurlsByUserid(Integer.parseInt(userid));
|
117
|
128
|
if(ApiUtil.isListNotEmpty(userModules)){
|
118
|
129
|
//用户有模块权限,存入缓存
|
119
|
|
- set(umodule_key, userModules, ConfigKey.redisumtime);
|
|
130
|
+ jedisUtil.set(umodule_key, userModules, ConfigKey.redisumtime);
|
120
|
131
|
}else{
|
121
|
132
|
throw new GatewayException(1, "没有权限");
|
122
|
133
|
}
|
|
@@ -125,12 +136,12 @@ public class DecryptRequestionBodyFilter extends JedisUtil implements GlobalFilt
|
125
|
136
|
}
|
126
|
137
|
|
127
|
138
|
String allmodule_key = "modules_operate";//校验模块对应操作
|
128
|
|
- String allmodule_value = get(allmodule_key);
|
|
139
|
+ String allmodule_value = jedisUtil.get(allmodule_key);
|
129
|
140
|
List<TModuleCheck> allModules = null;//校验模块对应操作
|
130
|
141
|
if(ApiUtil.isEmpty(allmodule_value)){
|
131
|
142
|
allModules = moduleCheckMapper.listAllModuleChecks();
|
132
|
143
|
if(ApiUtil.isListNotEmpty(allModules)){
|
133
|
|
- set(allmodule_key,allModules,ConfigKey.redismoduletime);
|
|
144
|
+ jedisUtil.set(allmodule_key,allModules,ConfigKey.redismoduletime);
|
134
|
145
|
}
|
135
|
146
|
}else{
|
136
|
147
|
allModules = JSON.parseArray(allmodule_value,TModuleCheck.class);
|
|
@@ -187,7 +198,8 @@ public class DecryptRequestionBodyFilter extends JedisUtil implements GlobalFilt
|
187
|
198
|
}
|
188
|
199
|
private Mono<Void> readBody(ServerWebExchange exchange, GatewayFilterChain chain) {
|
189
|
200
|
//重新构造request,参考ModifyRequestBodyGatewayFilterFactory
|
190
|
|
- ServerRequest serverRequest = ServerRequest.create(exchange, HandlerStrategies.withDefaults().messageReaders());
|
|
201
|
+ //ServerRequest serverRequest = ServerRequest.create(exchange, HandlerStrategies.withDefaults().messageReaders());
|
|
202
|
+ ServerRequest serverRequest = ServerRequest.create(exchange, codecConfigurer.getReaders());
|
191
|
203
|
MediaType mediaType = exchange.getRequest().getHeaders().getContentType();
|
192
|
204
|
//重点
|
193
|
205
|
Mono<String> modifiedBody = serverRequest.bodyToMono(String.class).flatMap(body -> {
|