|
1 | 1 | package org.vcell.restq.handlers; |
2 | 2 |
|
3 | 3 |
|
| 4 | +import cbit.util.xml.XmlUtil; |
4 | 5 | import io.quarkus.security.identity.SecurityIdentity; |
5 | 6 | import jakarta.annotation.security.RolesAllowed; |
6 | 7 | import jakarta.inject.Inject; |
|
9 | 10 | import org.eclipse.microprofile.openapi.annotations.Operation; |
10 | 11 | import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; |
11 | 12 | import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; |
12 | | -import org.vcell.restq.errors.exceptions.DataAccessWebException; |
13 | | -import org.vcell.restq.errors.exceptions.NotAuthenticatedWebException; |
14 | | -import org.vcell.restq.errors.exceptions.NotFoundWebException; |
15 | | -import org.vcell.restq.errors.exceptions.PermissionWebException; |
| 13 | +import org.jdom2.JDOMException; |
| 14 | +import org.vcell.restq.errors.exceptions.*; |
16 | 15 | import org.vcell.restq.services.MathModelService; |
17 | 16 | import org.vcell.restq.services.UserRestService; |
18 | 17 | import org.vcell.util.BigString; |
|
21 | 20 | import org.vcell.util.PermissionException; |
22 | 21 | import org.vcell.util.document.*; |
23 | 22 |
|
| 23 | +import java.io.IOException; |
24 | 24 | import java.util.ArrayList; |
25 | 25 | import java.util.List; |
26 | 26 | import java.util.Optional; |
@@ -59,13 +59,16 @@ public String getMathModel(@PathParam("id") String id) throws DataAccessWebExcep |
59 | 59 | User user = userRestService.getUserOrAnonymousFromIdentity(securityIdentity); |
60 | 60 | try{ |
61 | 61 | BigString result = mathModelService.getMathModelVCML(user, new KeyValue(id)); |
| 62 | + XmlUtil.vetXMLForMaliciousEntities(result.toString()); |
62 | 63 | return result.toString(); |
63 | 64 | } catch (ObjectNotFoundException e){ |
64 | 65 | throw new NotFoundWebException(e.getMessage(), e); |
65 | 66 | } catch (PermissionException e){ |
66 | 67 | throw new PermissionWebException(e.getMessage(), e); |
67 | 68 | } catch (DataAccessException e) { |
68 | 69 | throw new DataAccessWebException(e.getMessage(), e); |
| 70 | + } catch (IOException | JDOMException e) { |
| 71 | + throw new RuntimeWebException("The MathModel you are trying to retrieve seems to be malformed, please contact VCell support with the Math Model ID: " + id, e); |
69 | 72 | } |
70 | 73 | } |
71 | 74 |
|
@@ -124,13 +127,17 @@ public String save(@RequestBody(name = "mathModelVCML", required = true) String |
124 | 127 | @Parameter(name = "newName", required = false, description = "Name to save new MathModel under. Leave blank if re-saving existing MathModel.") |
125 | 128 | @QueryParam("newName") Optional<String> newName, |
126 | 129 | @Parameter(name = "simNames", required = false, description = BioModelResource.simsRequiringUpdatesDescription) |
127 | | - @QueryParam("simsRequiringUpdates") List<String> simNames) throws DataAccessWebException, NotAuthenticatedWebException { |
| 130 | + @QueryParam("simsRequiringUpdates") List<String> simNames) throws DataAccessWebException, NotAuthenticatedWebException, UnprocessableContentWebException { |
128 | 131 | User user = userRestService.getUserFromIdentity(securityIdentity); |
129 | 132 | try{ |
| 133 | + XmlUtil.vetXMLForMaliciousEntities(mathModelVCML); |
130 | 134 | BigString result = mathModelService.saveModel(user, new BigString(mathModelVCML), newName.orElse(null), simNames.toArray(new String[0])); |
| 135 | + XmlUtil.vetXMLForMaliciousEntities(result.toString()); // partial saves might include already saved XML |
131 | 136 | return result.toString(); |
132 | 137 | } catch (DataAccessException e) { |
133 | 138 | throw new DataAccessWebException(e.getMessage(), e); |
| 139 | + } catch (IOException | JDOMException e) { |
| 140 | + throw new UnprocessableContentWebException(e.getMessage(), e); |
134 | 141 | } |
135 | 142 | } |
136 | 143 |
|
|
0 commit comments