|
16 | 16 |
|
17 | 17 | import org.openmrs.api.APIException; |
18 | 18 | import org.openmrs.api.context.Context; |
| 19 | +import org.openmrs.module.VersionComparator; |
19 | 20 | import org.openmrs.module.serialization.xstream.XStreamShortSerializer; |
20 | 21 | import org.openmrs.module.serialization.xstream.mapper.CGLibMapper; |
21 | 22 | import org.openmrs.module.serialization.xstream.mapper.HibernateCollectionMapper; |
|
32 | 33 | import com.thoughtworks.xstream.io.xml.DomDriver; |
33 | 34 | import com.thoughtworks.xstream.mapper.Mapper; |
34 | 35 | import com.thoughtworks.xstream.mapper.MapperWrapper; |
| 36 | +import org.openmrs.util.OpenmrsConstants; |
35 | 37 |
|
36 | 38 |
|
37 | 39 | public class ReportingSerializer extends XStreamShortSerializer { |
@@ -85,6 +87,11 @@ public Object unmarshal(HierarchicalStreamReader reader, Object root) { |
85 | 87 | xstream.registerConverter(new IndicatorConverter(mapper, converterLookup)); |
86 | 88 |
|
87 | 89 | xstream.registerConverter(new ReportDefinitionConverter(mapper, converterLookup)); |
| 90 | + |
| 91 | + // Only setup XStreamSecurity only on versions that are after 2.7.0 |
| 92 | + if (new VersionComparator().compare(OpenmrsConstants.OPENMRS_VERSION, "2.7.0") >= 0) { |
| 93 | + setupXStreamSecurity(xstream); |
| 94 | + } |
88 | 95 | } |
89 | 96 |
|
90 | 97 | @Override |
@@ -115,4 +122,22 @@ public void serializeToStream(Object object, OutputStream out) { |
115 | 122 | throw new IllegalStateException("Unsupported encoding", e); |
116 | 123 | } |
117 | 124 | } |
| 125 | + |
| 126 | + private void setupXStreamSecurity(XStream xstream) throws SerializationException { |
| 127 | + try { |
| 128 | + SimpleXStreamSerializer serializer = Context.getRegisteredComponent("simpleXStreamSerializer", SimpleXStreamSerializer.class); |
| 129 | + if (serializer != null) { |
| 130 | + try { |
| 131 | + Method method = serializer.getClass().getMethod("initXStream", XStream.class); |
| 132 | + method.invoke(serializer, xstream); |
| 133 | + } |
| 134 | + catch (Exception ex) { |
| 135 | + throw new SerializationException("Failed to set up XStream Security", ex); |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + catch (APIException ex) { |
| 140 | + //Ignore APIException("Error during getting registered component) for platform versions below 2.7.0 |
| 141 | + } |
| 142 | + } |
118 | 143 | } |
0 commit comments