Skip to content
Snippets Groups Projects
Commit 47342b33 authored by Sara Bertocco's avatar Sara Bertocco
Browse files

Working on task #3635 - Refactoring: create NodeUtils class

parent 731bc2a7
No related branches found
No related tags found
No related merge requests found
Pipeline #958 passed
......@@ -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;
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment