Commit 81286197 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Added check on parent node to CreateNodeController: if it's not typed as

ContainerNode then throw ContainerNodeNotFound exception
parent 54212e6c
Loading
Loading
Loading
Loading
+24 −19
Original line number Diff line number Diff line
@@ -32,8 +32,9 @@ public class CreateNodeController extends BaseNodeController {

        List<String> userGroups = principal.getGroups();

        if (!isValidURI(node.getUri()))
        if (!isValidURI(node.getUri())) {
            throw new InvalidURIException(node.getUri());
        }

        if (!isUrlConsistentWithPayloadURI(node.getUri(), path)) {
            throw new InvalidURIException(node.getUri(), path);
@@ -65,30 +66,34 @@ public class CreateNodeController extends BaseNodeController {
            throw new PermissionDeniedException(path);
        }

        // Check if parent node is a LinkNode and if so throw exception
        // Check if parent node is not a Container node and in case throw
        // appropriate exception

        if (!parentNode.getType().equals("vos:ContainerNode")) {
            if (parentNode.getType().equals("vos:LinkNode")) {
                throw new LinkFoundException(getParentPath(path));
            } else {
                throw new ContainerNotFoundException(getParentPath(path));
            }
        }

        nodeDao.createNode(node);
        return node;
    }

    // Assuming that this service implementation uses only ! as a separator
    // in the authority part of the URI
    private boolean isValidURI(String nodeURI)
    {
    private boolean isValidURI(String nodeURI) {
        String parsedAuthority;
        if(!nodeURI.startsWith("vos://"))
        {
        if (!nodeURI.startsWith("vos://")) {
            return false;
        } else {
            parsedAuthority = nodeURI.replaceAll("vos://", "").split("/", -1)[0];
        }

        if(parsedAuthority.isEmpty() || 
                !parsedAuthority.replace("~","!").equals(authority))
        if (parsedAuthority.isEmpty()
                || !parsedAuthority.replace("~", "!").equals(authority)) {
            return false;
        }

        return true;
    }