Commit 9e244f14 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Allowed external http and https targets for LinkNodes

parent 1907e7fb
Loading
Loading
Loading
Loading
+19 −8
Original line number Original line Diff line number Diff line
@@ -48,13 +48,24 @@ public abstract class BaseNodeController {


    }
    }


    protected void validateInternalLinkNode(LinkNode linkNode) {
    protected void validateLinkNode(LinkNode linkNode) {
        String target = linkNode.getTarget();
        String target = linkNode.getTarget();
        // I validate it here to add context easily
        // I validate it here to add context easily
        if (target == null) {
        if (target == null) {
            throw new InvalidArgumentException("LinkNode in payload has no target element specified");
            throw new InvalidArgumentException("LinkNode in payload has no target element specified");
        }
        }


        if (URIUtils.isURIInternal(target)) {
            URIUtils.returnVosPathFromNodeURI(linkNode.getTarget(), authority);
            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);
            }

        }
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -44,7 +44,7 @@ public class CreateNodeController extends BaseNodeController {
    private void validateInputNode(Node node) {
    private void validateInputNode(Node node) {


        if (node instanceof LinkNode) {
        if (node instanceof LinkNode) {
            this.validateInternalLinkNode((LinkNode) node);
            this.validateLinkNode((LinkNode) node);
        }
        }


    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -73,7 +73,7 @@ public class SetNodeController extends BaseNodeController {
        if (node instanceof DataNode) {
        if (node instanceof DataNode) {
            checkViews((DataNode) node, (DataNode) toBeModifiedNode);
            checkViews((DataNode) node, (DataNode) toBeModifiedNode);
        } else if(node instanceof LinkNode) {
        } 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 
        //The service SHOULD throw a HTTP 500 status code including an InternalFault fault