Commit 008d07e 1 parent 714b1bb commit 008d07e Copy full SHA for 008d07e
File tree 4 files changed +22
-5
lines changed
src/main/java/co/yiiu/pybbs
4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 190
190
<groupId >me.zhyd.oauth</groupId >
191
191
<artifactId >JustAuth</artifactId >
192
192
<version >${justauth.version} </version >
193
+ <!-- 如果用不到第三方登录,可以将下面这个注释掉的 exclusions 打开,将justauth里用到的fastjson排队掉,这样就不会报漏洞了 -->
194
+ <!-- <exclusions>
195
+ <exclusion>
196
+ <groupId>com.alibaba</groupId>
197
+ <artifactId>fastjson</artifactId>
198
+ </exclusion>
199
+ </exclusions>-->
193
200
</dependency >
194
201
195
202
<!-- 云存储 OSS-->
Original file line number Diff line number Diff line change 1
1
package co .yiiu .pybbs .config .websocket ;
2
2
3
+ import co .yiiu .pybbs .util .JsonUtil ;
3
4
import co .yiiu .pybbs .util .Message ;
4
- import com .alibaba .fastjson .JSON ;
5
5
6
6
import javax .websocket .Decoder ;
7
7
import javax .websocket .EndpointConfig ;
8
8
9
9
public class MessageDecoder implements Decoder .Text <Message > {
10
10
@ Override
11
11
public Message decode (String s ) {
12
- return JSON . parseObject (s , Message .class );
12
+ return JsonUtil . jsonToObject (s , Message .class );
13
13
}
14
14
15
15
@ Override
16
16
public boolean willDecode (String s ) {
17
17
// 验证json字符串是否合法,合法才会进入decode()方法进行转换,不合法直接抛异常
18
- return JSON .isValid (s );
18
+ return JsonUtil .isValid (s );
19
19
}
20
20
21
21
@ Override
Original file line number Diff line number Diff line change 1
1
package co .yiiu .pybbs .config .websocket ;
2
2
3
+ import co .yiiu .pybbs .util .JsonUtil ;
3
4
import co .yiiu .pybbs .util .Message ;
4
- import com .alibaba .fastjson .JSON ;
5
5
6
6
import javax .websocket .Encoder ;
7
7
import javax .websocket .EndpointConfig ;
8
8
9
9
public class MessageEncoder implements Encoder .Text <Message > {
10
10
@ Override
11
11
public String encode (Message o ) {
12
- return JSON . toJSONString (o );
12
+ return JsonUtil . objectToJson (o );
13
13
}
14
14
15
15
@ Override
Original file line number Diff line number Diff line change @@ -46,4 +46,14 @@ public static String objectToJson(Object obj) {
46
46
return null ;
47
47
}
48
48
}
49
+
50
+ public static boolean isValid (String json ) {
51
+ try {
52
+ objectMapper .readTree (json );
53
+ return true ;
54
+ } catch (JsonProcessingException e ) {
55
+ log .error ("validate json string error: {}" , e .getMessage ());
56
+ return false ;
57
+ }
58
+ }
49
59
}
You can’t perform that action at this time.
0 commit comments