Skip to content

Commit

Permalink
fix: support values object property in SPARQL query to load acess pol…
Browse files Browse the repository at this point in the history
…icy.
  • Loading branch information
litvinovg committed Dec 18, 2023
1 parent 1643a5e commit f14f2e4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,37 @@ public class PolicyLoader {
+ "SELECT DISTINCT ?policyUri ?rule ?check ?testId ?typeId ?value ?lit_value ?decision_id \n"
+ "WHERE {\n"
+ " GRAPH <http://vitro.mannlib.cornell.edu/default/access-control> {\n"
+ "?policy a access:Policy .\n"
+ "?policy access:hasRule ?rule . \n"
+ "?rule access:requiresCheck ?check .\n"
+ "OPTIONAL {\n"
+ " ?check access:useOperator ?checkTest .\n"
+ " OPTIONAL {\n"
+ " ?checkTest access:id ?testId . \n"
+ " }\n"
+ "}"
+ "OPTIONAL {\n"
+ " ?check access:hasTypeToCheck ?checkType . \n"
+ " OPTIONAL {\n"
+ " ?checkType access:id ?typeId . \n"
+ " }\n"
+ "}\n"
+ "OPTIONAL {\n"
+ " ?rule access:hasDecision ?decision . \n"
+ " ?decision access:id ?decision_id . \n"
+ "}\n"
+ "?check access:value ?value . \n"
+ "OPTIONAL {?value access:id ?lit_value . }\n"
+ " ?policy a access:Policy .\n"
+ " ?policy access:hasRule ?rule . \n"
+ " ?rule access:requiresCheck ?check .\n"
+ " OPTIONAL {\n"
+ " ?check access:useOperator ?checkTest .\n"
+ " OPTIONAL {\n"
+ " ?checkTest access:id ?testId . \n"
+ " }\n"
+ " }\n"
+ " OPTIONAL {\n"
+ " ?check access:hasTypeToCheck ?checkType . \n"
+ " OPTIONAL {\n"
+ " ?checkType access:id ?typeId . \n"
+ " }\n"
+ " }\n"
+ " OPTIONAL {\n"
+ " ?rule access:hasDecision ?decision . \n"
+ " ?decision access:id ?decision_id . \n"
+ " }\n"
+ " {\n"
+ " ?check access:values ?attributeValue .\n"
+ " ?attributeValue access:value ?value .\n"
+ " OPTIONAL { ?value access:id ?lit_value . }\n"
+ " }\n"
+ " UNION \n"
+ " {\n"
+ " ?check access:value ?value .\n"
+ " OPTIONAL {?value access:id ?lit_value . }\n"
+ " }\n"
+ " BIND(?policy as ?policyUri)\n"
+ " }\n"
+ "BIND(?policy as ?policyUri)\n"
+ "} ORDER BY ?rule ?check";

private static final String DATASET_RULES_QUERY = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

import edu.cornell.mannlib.vitro.webapp.auth.attributes.AttributeValueKey;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
Expand Down Expand Up @@ -53,7 +56,7 @@ public void getRoleDataSetDraftKeyTemplateTest() {
@Test
public void getDataSetUriByKeyTest() {
load(DATA_SET);
String uri = PolicyLoader.getInstance().getDataSetUriByKey(new String[] { },
String uri = PolicyLoader.getInstance().getDataSetUriByKey(new String[] {},
new String[] { NAMED_OBJECT.toString(), EXECUTE.toString(), PUBLIC });
assertEquals(PREFIX + "PublicDataSet", uri);
}
Expand All @@ -75,7 +78,6 @@ public void getDataSetKeyTest() {
expectedKey.setObjectType(NAMED_OBJECT);
AttributeValueKey compositeKey = PolicyLoader.getInstance().getDataSetKey(PREFIX + "PublicDataSet");
assertEquals(expectedKey, compositeKey);

}

@Test
Expand All @@ -91,4 +93,17 @@ public void getSubjectRoleValuePatternTest() {
assertTrue(!patterns.isEmpty());
assertEquals(1, patterns.size());
}

@Test
public void testLoadPolicyWithValues() {
load(RESOURCES_RULES_PREFIX + "policy_values.n3");
String policyUri = VitroVocabulary.AUTH_INDIVIDUAL_PREFIX + "policy-values-test/Policy";
Set<DynamicPolicy> policies = loader.loadPolicies(policyUri);
assertEquals(1, policies.size());
DynamicPolicy policy = policies.iterator().next();
assertTrue(policy != null);
assertEquals(100, policy.getPriority());
countRulesAndAttributes(policy, 1, Collections.singleton(1));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# $This file is distributed under the terms of the license in LICENSE$

@prefix access-individual: <https://vivoweb.org/ontology/vitro-application/auth/individual/> .
@prefix access: <https://vivoweb.org/ontology/vitro-application/auth/vocabulary/> .
@prefix : <https://vivoweb.org/ontology/vitro-application/auth/individual/policy-values-test/> .

:Policy a access:Policy ;
access:priority 100 ;
access:hasRule :TestRule .

:TestRule a access:Rule;
access:requiresCheck :OperationCheck ;
.

:OperationCheck a access:Check ;
access:useOperator access-individual:Equals ;
access:hasTypeToCheck access-individual:Operation ;
access:values access-individual:DisplayOperationValueSet ;
.



0 comments on commit f14f2e4

Please sign in to comment.