Commit 1481cdfd authored by Sara Bertocco's avatar Sara Bertocco
Browse files

Working on task #3635 - Refactoring: create NodeUtils class

parent 46bbd487
Loading
Loading
Loading
Loading
+5 −39
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package it.inaf.oats.vospace;

import it.inaf.ia2.aa.data.User;
import it.inaf.oats.vospace.datamodel.NodeProperties;
import it.inaf.oats.vospace.datamodel.NodeUtils;
import net.ivoa.xml.vospace.v2.Node;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
@@ -60,45 +61,10 @@ public class CreateNodeController extends BaseNodeController {
            }
        }              
        
        // First check if parent node creator is == userid
        List<String> nodeOwner
                = NodeProperties.getNodePropertyByURI(
                        parentNode, NodeProperties.CREATOR_URI);

        if (nodeOwner == null
                || nodeOwner.isEmpty()
                || !nodeOwner.get(0).equals(principal.getName())) {
            // Node owner check has failed: let's check if user can write
            // due to group privileges

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

            // If the user doesn't belong to any groups throw exception
            if (userGroups == null || userGroups.isEmpty()) {
                throw new PermissionDeniedException(path);
            }

            List<String> groupWritePropValues
                    = NodeProperties.getNodePropertyByURI(parentNode,
                            "ivo://ivoa.net/vospace/core#groupwrite");

            // If groupwrite property is absent in Parent Node throw exception
            if (groupWritePropValues == null
                    || groupWritePropValues.isEmpty()) {
        if(!NodeUtils.checkIfWritable(parentNode, principal.getName(), principal.getGroups())) {
            throw new PermissionDeniedException(path);
        }

            List<String> nodeGroups
                    = NodeProperties.parsePropertyStringToList(groupWritePropValues.get(0));

            if (nodeGroups.isEmpty()
                    || !nodeGroups.stream()
                            .anyMatch((i) -> userGroups.contains(i))) {
                throw new PermissionDeniedException(path);
            }

        }

        nodeDao.createNode(node);

        return node;
+2 −11
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package it.inaf.oats.vospace;
import it.inaf.ia2.aa.ServletRapClient;
import it.inaf.ia2.aa.data.User;
import it.inaf.ia2.rap.client.call.TokenExchangeRequest;
import it.inaf.oats.vospace.datamodel.NodeProperties;
import it.inaf.oats.vospace.persistence.NodeDAO;
import java.util.ArrayList;
import java.util.List;
@@ -73,7 +74,7 @@ public class UriService {
        // TODO add token for authenticated access
        String endpoint = fileServiceUrl + relativePath + "?jobId=" + job.getJobId();

        if (!"true".equals(getProperty(node, "publicread"))) {
        if (!"true".equals(NodeProperties.getProperty(node, "publicread"))) {
            endpoint += "&token=" + getEndpointToken(fileServiceUrl + relativePath);
        }

@@ -97,16 +98,6 @@ public class UriService {
        return rapClient.exchangeToken(exchangeRequest, servletRequest);
    }

    private String getProperty(Node node, String propertyName) {

        for (Property property : node.getProperties()) {
            if (property.getUri().equals("ivo://ivoa.net/vospace/core#".concat(propertyName))) {
                return property.getValue();
            }
        }
        return null;
    }

    private Transfer getTransfer(JobSummary job) {
        // TODO add checks on data type
        return (Transfer) job.getJobInfo().getAny().get(0);