Skip to content
Snippets Groups Projects
Commit 9e244f14 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Allowed external http and https targets for LinkNodes

parent 1907e7fb
No related branches found
No related tags found
No related merge requests found
......@@ -19,11 +19,11 @@ public abstract class BaseNodeController {
@Autowired
private HttpServletRequest servletRequest;
@Value("${vospace-authority}")
protected String authority;
protected String getPath() {
protected String getPath() {
String requestURL = servletRequest.getRequestURL().toString();
try {
return NodeUtils.getPathFromRequestURLString(requestURL);
......@@ -35,7 +35,7 @@ public abstract class BaseNodeController {
protected String getParentPath(String path) {
return NodeUtils.getParentPath(path);
}
protected void validateAndCheckPayloadURIConsistence(Node node) {
// Get Node path (and validates it too)
String decodedURIPathFromNode = URIUtils.returnVosPathFromNodeURI(node.getUri(), this.authority);
......@@ -45,16 +45,27 @@ public abstract class BaseNodeController {
if (!decodedURIPathFromNode.equals(this.getPath())) {
throw new InvalidURIException(decodedURIPathFromNode, requestPath);
}
}
protected void validateInternalLinkNode(LinkNode linkNode) {
protected void validateLinkNode(LinkNode linkNode) {
String target = linkNode.getTarget();
// I validate it here to add context easily
if (target == null) {
throw new InvalidArgumentException("LinkNode in payload has no target element specified");
}
URIUtils.returnVosPathFromNodeURI(linkNode.getTarget(), authority);
if (URIUtils.isURIInternal(target)) {
URIUtils.returnVosPathFromNodeURI(linkNode.getTarget(), authority);
} else {
// Let's discuss if we need to combine this validation with
// protocol endpoints management (URIService, ProtocolType)
// Let's start with http and https only for now
if (!(target.toLowerCase().startsWith("http://")
|| target.toLowerCase().startsWith("https://"))) {
throw new InvalidArgumentException("LinkNode target malformed or unsupported protocol: " + target);
}
}
}
}
......@@ -44,7 +44,7 @@ public class CreateNodeController extends BaseNodeController {
private void validateInputNode(Node node) {
if (node instanceof LinkNode) {
this.validateInternalLinkNode((LinkNode) node);
this.validateLinkNode((LinkNode) node);
}
}
......
......@@ -73,7 +73,7 @@ public class SetNodeController extends BaseNodeController {
if (node instanceof DataNode) {
checkViews((DataNode) node, (DataNode) toBeModifiedNode);
} else if(node instanceof LinkNode) {
this.validateInternalLinkNode((LinkNode) node);
this.validateLinkNode((LinkNode) node);
}
//The service SHOULD throw a HTTP 500 status code including an InternalFault fault
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment