1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.server.serialization; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import com.google.gwt.user.client.rpc.SerializationException; |
22 | |
import com.google.gwt.user.server.rpc.impl.LegacySerializationPolicy; |
23 | |
import com.google.gwt.user.server.rpc.impl.StandardSerializationPolicy; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class KSSerializationPolicy extends StandardSerializationPolicy { |
32 | 0 | LegacySerializationPolicy legacySerializationPolicy = LegacySerializationPolicy.getInstance(); |
33 | |
|
34 | |
public KSSerializationPolicy(Map<Class<?>, Boolean> whitelist) { |
35 | 0 | super(whitelist, whitelist, new HashMap<Class<?>, String>()); |
36 | 0 | } |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
@Override |
42 | |
public boolean shouldDeserializeFields(Class<?> clazz) { |
43 | 0 | return super.shouldDeserializeFields(clazz)||legacySerializationPolicy.shouldDeserializeFields(clazz); |
44 | |
} |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@Override |
51 | |
public boolean shouldSerializeFields(Class<?> clazz) { |
52 | 0 | return super.shouldSerializeFields(clazz)||legacySerializationPolicy.shouldSerializeFields(clazz); |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
@Override |
64 | |
public void validateDeserialize(Class<?> clazz) |
65 | |
throws SerializationException{ |
66 | 0 | boolean throwedFromStandardSerializationPolicy = false; |
67 | 0 | boolean throwedFromLegacySerializationPolicy = false; |
68 | |
try{ |
69 | 0 | super.validateDeserialize(clazz); |
70 | 0 | }catch(SerializationException e){ |
71 | 0 | throwedFromStandardSerializationPolicy = true; |
72 | 0 | } |
73 | |
try{ |
74 | 0 | legacySerializationPolicy.validateDeserialize(clazz); |
75 | 0 | }catch(SerializationException e){ |
76 | 0 | throwedFromLegacySerializationPolicy = true; |
77 | 0 | } |
78 | |
|
79 | 0 | if(throwedFromStandardSerializationPolicy && |
80 | |
throwedFromLegacySerializationPolicy){ |
81 | 0 | throw new SerializationException( |
82 | |
"Type '" |
83 | |
+ clazz.getName() |
84 | |
+ "' was not included in the set of types which can be deserialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be deserialized."); |
85 | |
} |
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
@Override |
96 | |
public void validateSerialize(Class<?> clazz) |
97 | |
throws SerializationException{ |
98 | 0 | boolean throwedFromStandardSerializationPolicy = false; |
99 | 0 | boolean throwedFromLegacySerializationPolicy = false; |
100 | |
try{ |
101 | 0 | super.validateSerialize(clazz); |
102 | 0 | }catch(SerializationException e){ |
103 | 0 | throwedFromStandardSerializationPolicy = true; |
104 | 0 | } |
105 | |
try{ |
106 | 0 | legacySerializationPolicy.validateSerialize(clazz); |
107 | 0 | }catch(SerializationException e){ |
108 | 0 | throwedFromLegacySerializationPolicy = true; |
109 | 0 | } |
110 | |
|
111 | 0 | if(throwedFromStandardSerializationPolicy && |
112 | |
throwedFromLegacySerializationPolicy){ |
113 | 0 | throw new SerializationException( |
114 | |
"Type '" |
115 | |
+ clazz.getName() |
116 | |
+ "' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized."); |
117 | |
} |
118 | 0 | } |
119 | |
} |