Skip to content

Commit

Permalink
style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg committed Oct 24, 2023
1 parent bbbdada commit 7cc4dc1
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class PolicyLoader {
+ " BIND(COALESCE(?set_priority, 0 ) as ?" + PRIORITY + " ) .\n"
+ " }\n"
+ "} ORDER BY ?" + PRIORITY;


private static final String DATASET_PRIORITY_QUERY = "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
+ "prefix owl: <http://www.w3.org/2002/07/owl#>\n"
Expand Down Expand Up @@ -115,7 +115,8 @@ public class PolicyLoader {
+ "prefix auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#>\n"
+ "prefix ai: <https://vivoweb.org/ontology/vitro-application/auth/individual/>\n"
+ "prefix ao: <https://vivoweb.org/ontology/vitro-application/auth/vocabulary/>\n"
+ "SELECT DISTINCT ?policyUri ?rules ?rule ?check ?testId ?typeId ?value ?lit_value ?decision_id \n" + "WHERE {\n"
+ "SELECT DISTINCT ?policyUri ?rules ?rule ?check ?testId ?typeId ?value ?lit_value ?decision_id \n"
+ "WHERE {\n"
+ " GRAPH <http://vitro.mannlib.cornell.edu/default/access-control> {\n"
+ "?policy rdf:type ao:Policy .\n"
+ "?policy ao:rules ?rules . \n"
Expand Down Expand Up @@ -150,7 +151,8 @@ public class PolicyLoader {
+ "prefix auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#>\n"
+ "prefix ai: <https://vivoweb.org/ontology/vitro-application/auth/individual/>\n"
+ "prefix ao: <https://vivoweb.org/ontology/vitro-application/auth/vocabulary/>\n"
+ "SELECT DISTINCT ?policyUri ?rules ?rule ?check ?testId ?typeId ?value ?lit_value ?decision_id ?dataSetUri \n"
+ "SELECT DISTINCT ?policyUri ?rules ?rule ?check ?testId ?typeId ?value ?lit_value ?decision_id"
+ " ?dataSetUri \n"
+ "WHERE {\n"
+ " GRAPH <http://vitro.mannlib.cornell.edu/default/access-control> {\n"
+ " ?policy a ao:PolicyTemplate .\n"
Expand Down Expand Up @@ -188,7 +190,7 @@ public class PolicyLoader {
+ " OPTIONAL {\n"
+ " ?check ao:value ?value .\n"
+ " OPTIONAL {?value ao:id ?lit_value . }\n"
+ " }\n"
+ " }\n"
+ " BIND(?dataSet as ?dataSetUri)\n"
+ " BIND(?policy as ?policyUri)\n"
+ " }\n"
Expand Down Expand Up @@ -217,7 +219,8 @@ public class PolicyLoader {
+ " }\n"
+ " ?dataSetKeyUri ao:keyComponent ?key .\n";

private static final String policyKeyTemplateSuffix = "}} GROUP BY ?" + POLICY + " ?dataSet ?value ?valueId ?testData ?valueContainer";
private static final String policyKeyTemplateSuffix =
"}} GROUP BY ?" + POLICY + " ?dataSet ?value ?valueId ?testData ?valueContainer";

private static final String policyStatementByKeyTemplatePrefix =
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
Expand Down Expand Up @@ -253,7 +256,7 @@ public class PolicyLoader {
+ " ?dataSetTemplateKey ao:templateKey ?key .\n"
+ " }\n"
+ "}\n"
+ "GROUP BY ?dataSetTemplate ?dataSets";
+ "GROUP BY ?dataSetTemplate ?dataSets";

public static final String DATA_SET_KEY_TEMPLATE_QUERY = ""
+ "prefix ao: <https://vivoweb.org/ontology/vitro-application/auth/vocabulary/>\n"
Expand All @@ -264,8 +267,8 @@ public class PolicyLoader {
+ " ?dataSetTemplate ao:dataSetKeyTemplate ?dataSetKeyTemplate .\n"
+ " ?dataSetKeyTemplate ao:keyComponent ?keyComponent .\n"
+ " }\n"
+ "}\n";
+ "}\n";

public static final String DATA_SET_KEY_TEMPLATES_TEMPLATE_QUERY = ""
+ "prefix ao: <https://vivoweb.org/ontology/vitro-application/auth/vocabulary/>\n"
+ "prefix ai: <https://vivoweb.org/ontology/vitro-application/auth/individual/>\n"
Expand All @@ -275,8 +278,8 @@ public class PolicyLoader {
+ " ?dataSetTemplate ao:dataSetKeyTemplate ?dataSetKeyTemplate .\n"
+ " ?dataSetKeyTemplate ao:keyComponentTemplate ?keyComponentTemplate .\n"
+ " }\n"
+ "}\n";
+ "}\n";

public static final String DATA_SET_VALUE_TEMPLATE_QUERY = ""
+ "prefix ao: <https://vivoweb.org/ontology/vitro-application/auth/vocabulary/>\n"
+ "prefix ai: <https://vivoweb.org/ontology/vitro-application/auth/individual/>\n"
Expand All @@ -285,9 +288,8 @@ public class PolicyLoader {
+ " GRAPH <http://vitro.mannlib.cornell.edu/default/access-control> {\n"
+ " ?dataSetTemplate ao:dataSetValues ?valueContainer .\n"
+ " }\n"
+ "}\n";


+ "}\n";

public static final String DATA_SET_VALUE_CONTAINER_TEMPLATES_TEMPLATE_QUERY = ""
+ "prefix ao: <https://vivoweb.org/ontology/vitro-application/auth/vocabulary/>\n"
+ "prefix ai: <https://vivoweb.org/ontology/vitro-application/auth/individual/>\n"
Expand All @@ -297,7 +299,7 @@ public class PolicyLoader {
+ " ?dataSetTemplate ao:dataSetValueTemplate ?valueContainerTemplate .\n"
+ " }\n"
+ "}\n";

public static final String CONSTRUCT_VALUE_CONTAINER_QUERY = ""
+ "prefix ai: <https://vivoweb.org/ontology/vitro-application/auth/individual/>\n"
+ "prefix ao: <https://vivoweb.org/ontology/vitro-application/auth/vocabulary/>\n"
Expand All @@ -321,7 +323,7 @@ public class PolicyLoader {
+ " }"
+ " }"
+ "}\n";

private RDFService rdfService;
public static final String RULE = "rule";
public static final String LITERAL_VALUE = "lit_value";
Expand Down Expand Up @@ -377,7 +379,7 @@ protected void processQuerySolution(QuerySolution qs) {

return policyUris;
}

@Deprecated
public DynamicPolicy loadPolicy(String uri) {
List<String> dataSetNames = getDataSetNames(uri);
Expand All @@ -401,7 +403,7 @@ public DynamicPolicy loadPolicy(String uri) {
policy.addRules(rules);
return policy;
}

public DynamicPolicy loadPolicyFromTemplateDataSet(String dataSetUri) {
Set<AccessRule> rules = new HashSet<>();
long priority = getPriorityFromDataSet(dataSetUri);
Expand Down Expand Up @@ -581,7 +583,8 @@ private static String getDataSetByKeyQuery(String[] uris, String[] ids) {
}
int i = 0;
for (String id : ids) {
query.append(String.format(" ?dataSetKeyUri ao:keyComponent ?uri%d .\n ?uri%d ao:id \"%s\" . \n", i, i, id));
query.append(
String.format(" ?dataSetKeyUri ao:keyComponent ?uri%d .\n ?uri%d ao:id \"%s\" . \n", i, i, id));
i++;
}
query.append(policyKeyTemplateSuffix);
Expand Down Expand Up @@ -769,7 +772,8 @@ private static boolean isInvalidPolicySolution(QuerySolution qs) {
}
String check = qs.get("check").asResource().getLocalName();
if (!qs.contains("value")) {
log.error(String.format("Query solution for policy <%s> rule %s check %s doesn't contain value", policy, rule, check));
log.error(String.format("Query solution for policy <%s> rule %s check %s doesn't contain value", policy,
rule, check));
return true;
}
if (!qs.contains("typeId") || !qs.get("typeId").isLiteral()) {
Expand Down Expand Up @@ -830,8 +834,8 @@ protected void processQuerySolution(QuerySolution qs) {
return uri[0];
}

public Map<String,String> getRoleDataSetTemplates() {
Map<String,String> dataSetTemplates = new HashMap<>();
public Map<String, String> getRoleDataSetTemplates() {
Map<String, String> dataSetTemplates = new HashMap<>();
long expectedSize = 1;
final String queryText = DATA_SET_TEMPLATES_QUERY;
debug("SPARQL Query to get data set templates:\n %s", queryText);
Expand All @@ -847,13 +851,12 @@ protected void processQuerySolution(QuerySolution qs) {
return;
}
if (!qs.contains("dataSetTemplate") || !qs.get("dataSetTemplate").isResource()) {
return;
return;
}
if (!qs.contains("dataSets") || !qs.get("dataSets").isResource()) {
return;
}
dataSetTemplates.put(
qs.getResource("dataSetTemplate").getURI(),
}
dataSetTemplates.put(qs.getResource("dataSetTemplate").getURI(),
qs.getResource("dataSets").getURI());
}
});
Expand Down Expand Up @@ -961,5 +964,5 @@ public void constructValueContainer(String valueContainerTemplateUri, String val
log.error(e, e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,25 @@ private static void createRoleDataSet(String dataSetTemplateUri, String roleUri,
}
Model dataSetModel = VitroModelFactory.createModel();
// Add ?dataSets ao:policyDataSet dataSetUri .
dataSetModel.add(new StatementImpl(
dataSetModel.createResource(dataSetsUri),
dataSetModel.createProperty(PREFIX_AO + "policyDataSet"),
dataSetModel.createResource(dataSetUri)));

dataSetModel.add(new StatementImpl(
dataSetModel.createResource(dataSetUri),
dataSetModel.add(new StatementImpl(dataSetModel.createResource(dataSetsUri),
dataSetModel.createProperty(PREFIX_AO + "policyDataSet"), dataSetModel.createResource(dataSetUri)));

dataSetModel.add(new StatementImpl(dataSetModel.createResource(dataSetUri),
dataSetModel.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
dataSetModel.createResource(PREFIX_AO + "PolicyDataSet")));

dataSetModel.add(new StatementImpl(
dataSetModel.createResource(dataSetUri),
dataSetModel.createProperty(PREFIX_AO + "dataSetKey"),
dataSetModel.createResource(dataSetKeyUri)));


dataSetModel.add(new StatementImpl(dataSetModel.createResource(dataSetUri),
dataSetModel.createProperty(PREFIX_AO + "dataSetKey"), dataSetModel.createResource(dataSetKeyUri)));

for (String key : keys) {
dataSetModel.add(new StatementImpl(
dataSetModel.createResource(dataSetKeyUri),
dataSetModel.createProperty(PREFIX_AO + "keyComponent"),
dataSetModel.createResource(key)));
dataSetModel.add(new StatementImpl(dataSetModel.createResource(dataSetKeyUri),
dataSetModel.createProperty(PREFIX_AO + "keyComponent"), dataSetModel.createResource(key)));
}

List<String> valueContainerUris = policyLoader.getDataSetValuesFromTemplate(dataSetTemplateUri);
for (String valueContainerUri : valueContainerUris) {
// Add ?dataSetUri ao:dataSetValues ?valueContainerUri .
dataSetModel.add(new StatementImpl(
dataSetModel.createResource(dataSetUri),
dataSetModel.add(new StatementImpl(dataSetModel.createResource(dataSetUri),
dataSetModel.createProperty(PREFIX_AO + "dataSetValues"),
dataSetModel.createResource(valueContainerUri)));
}
Expand All @@ -79,11 +71,10 @@ private static void createRoleDataSet(String dataSetTemplateUri, String roleUri,

for (String valueContainerTemplateUri : valueContainerTemplateUris) {
String valueContainerUri = getUriFromTemplate(valueContainerTemplateUri, role);
dataSetModel.add(new StatementImpl(
dataSetModel.createResource(dataSetUri),
dataSetModel.add(new StatementImpl(dataSetModel.createResource(dataSetUri),
dataSetModel.createProperty(PREFIX_AO + "dataSetValues"),
dataSetModel.createResource(valueContainerUri)));

policyLoader.constructValueContainer(valueContainerTemplateUri, valueContainerUri, roleUri, dataSetModel);
// TODO: Check uri doesn't exists in access control graph
// If value container template is subject role, then role uri should be added to the container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.List;
import java.util.Set;

import edu.cornell.mannlib.vitro.webapp.auth.attributes.Check;
import edu.cornell.mannlib.vitro.webapp.auth.attributes.Attribute;
import edu.cornell.mannlib.vitro.webapp.auth.attributes.Check;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;

public interface AccessRule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import edu.cornell.mannlib.vitro.webapp.auth.attributes.Check;
import edu.cornell.mannlib.vitro.webapp.auth.attributes.Attribute;
import edu.cornell.mannlib.vitro.webapp.auth.attributes.Check;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected void collectAdditions(Map<AccessObjectType, Set<String>> entityTypeMap
for (AccessOperation ao : OperationGroup.getOperations(og)) {
for (String entityUri : intersectionEntities) {
EntityPolicyController.getDataValueStatements(entityUri, type, ao,
Collections.singleton(newRole), additions);
Collections.singleton(newRole), additions);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void testPolicy() {
}
EntityPolicyController.updateEntityDataSet("test:entity", type, ao, Arrays.asList(roleUri), roles);
DynamicPolicy policy = null;
String dataSet = loader.getDataSetUriByKey(new String[] { roleUri }, new String[] { ao.toString(), type.toString() });
String dataSet =
loader.getDataSetUriByKey(new String[] { roleUri }, new String[] { ao.toString(), type.toString() });

policy = loader.loadPolicyFromTemplateDataSet(dataSet);
countRulesAndAttributes(policy, rulesCount, attrCount);
Expand All @@ -59,26 +60,26 @@ public void testPolicy() {
@Parameterized.Parameters
public static Collection<Object[]> requests() {
return Arrays.asList(new Object[][] {
{ DISPLAY, CLASS, PUBLIC, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, SELF_EDITOR, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, EDITOR, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, CURATOR, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, ADMIN, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, CUSTOM, 1, Collections.singleton(4) },

{ PUBLISH, CLASS, SELF_EDITOR, 1, Collections.singleton(4) },
{ PUBLISH, CLASS, EDITOR, 1, Collections.singleton(4) },
{ PUBLISH, CLASS, CURATOR, 1, Collections.singleton(4) },
{ PUBLISH, CLASS, ADMIN, 1, Collections.singleton(4) },
{ PUBLISH, CLASS, CUSTOM, 1, Collections.singleton(4) },

{ UPDATE, CLASS, PUBLIC, 1, Collections.singleton(4) },
{ UPDATE, CLASS, SELF_EDITOR, 1, Collections.singleton(4) },
{ UPDATE, CLASS, EDITOR, 1, Collections.singleton(4) },
{ UPDATE, CLASS, CURATOR, 1, Collections.singleton(4) },
{ UPDATE, CLASS, ADMIN, 1, Collections.singleton(4) },
{ UPDATE, CLASS, CUSTOM, 1, Collections.singleton(4) },});
{ DISPLAY, CLASS, PUBLIC, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, SELF_EDITOR, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, EDITOR, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, CURATOR, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, ADMIN, 1, Collections.singleton(4) },
{ DISPLAY, CLASS, CUSTOM, 1, Collections.singleton(4) },

{ PUBLISH, CLASS, SELF_EDITOR, 1, Collections.singleton(4) },
{ PUBLISH, CLASS, EDITOR, 1, Collections.singleton(4) },
{ PUBLISH, CLASS, CURATOR, 1, Collections.singleton(4) },
{ PUBLISH, CLASS, ADMIN, 1, Collections.singleton(4) },
{ PUBLISH, CLASS, CUSTOM, 1, Collections.singleton(4) },

{ UPDATE, CLASS, PUBLIC, 1, Collections.singleton(4) },
{ UPDATE, CLASS, SELF_EDITOR, 1, Collections.singleton(4) },
{ UPDATE, CLASS, EDITOR, 1, Collections.singleton(4) },
{ UPDATE, CLASS, CURATOR, 1, Collections.singleton(4) },
{ UPDATE, CLASS, ADMIN, 1, Collections.singleton(4) },
{ UPDATE, CLASS, CUSTOM, 1, Collections.singleton(4) }, });

}

}
Loading

0 comments on commit 7cc4dc1

Please sign in to comment.