NIHVIVO-3404 Require that the statement-based RequestedActions include a reference to an OntModel. So the paradigm changes from "may I do this with this statement?" to "may I do this with this statement and this model?"

This commit is contained in:
j2blake 2012-04-01 15:46:43 +00:00
parent ed2f3ddc12
commit 7aa3b4f469
21 changed files with 204 additions and 131 deletions

View file

@ -23,6 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPro
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.DropDataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.DropObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
/**
* A collection of static methods to help determine whether requested actions
@ -63,15 +64,15 @@ public class PolicyHelper {
* Do the current policies authorize the current user to add all of the
* statements in this model?
*/
public static boolean isAuthorizedToAdd(HttpServletRequest req, Model model) {
if ((req == null) || (model == null)) {
public static boolean isAuthorizedToAdd(VitroRequest vreq, Model model) {
if ((vreq == null) || (model == null)) {
return false;
}
StmtIterator stmts = model.listStatements();
try {
while (stmts.hasNext()) {
if (!isAuthorizedToAdd(req, stmts.next())) {
if (!isAuthorizedToAdd(vreq, stmts.next())) {
return false;
}
}
@ -86,9 +87,8 @@ public class PolicyHelper {
*
* The statement is expected to be fully-populated, with no null fields.
*/
public static boolean isAuthorizedToAdd(HttpServletRequest req,
Statement stmt) {
if ((req == null) || (stmt == null)) {
public static boolean isAuthorizedToAdd(VitroRequest vreq, Statement stmt) {
if ((vreq == null) || (stmt == null)) {
return false;
}
@ -101,28 +101,29 @@ public class PolicyHelper {
RequestedAction action;
if (objectNode.isResource()) {
action = new AddObjectPropertyStatement(subject.getURI(),
predicate.getURI(), objectNode.asResource().getURI());
action = new AddObjectPropertyStatement(vreq.getJenaOntModel(),
subject.getURI(), predicate.getURI(), objectNode
.asResource().getURI());
} else {
action = new AddDataPropertyStatement(subject.getURI(),
predicate.getURI());
action = new AddDataPropertyStatement(vreq.getJenaOntModel(),
subject.getURI(), predicate.getURI());
}
return isAuthorizedForActions(req, action);
return isAuthorizedForActions(vreq, action);
}
/**
* Do the current policies authorize the current user to drop all of the
* statements in this model?
*/
public static boolean isAuthorizedToDrop(HttpServletRequest req, Model model) {
if ((req == null) || (model == null)) {
public static boolean isAuthorizedToDrop(VitroRequest vreq, Model model) {
if ((vreq == null) || (model == null)) {
return false;
}
StmtIterator stmts = model.listStatements();
try {
while (stmts.hasNext()) {
if (!isAuthorizedToDrop(req, stmts.next())) {
if (!isAuthorizedToDrop(vreq, stmts.next())) {
return false;
}
}
@ -138,9 +139,8 @@ public class PolicyHelper {
*
* The statement is expected to be fully-populated, with no null fields.
*/
public static boolean isAuthorizedToDrop(HttpServletRequest req,
Statement stmt) {
if ((req == null) || (stmt == null)) {
public static boolean isAuthorizedToDrop(VitroRequest vreq, Statement stmt) {
if ((vreq == null) || (stmt == null)) {
return false;
}
@ -153,13 +153,14 @@ public class PolicyHelper {
RequestedAction action;
if (objectNode.isResource()) {
action = new DropObjectPropertyStatement(subject.getURI(),
predicate.getURI(), objectNode.asResource().getURI());
action = new DropObjectPropertyStatement(vreq.getJenaOntModel(),
subject.getURI(), predicate.getURI(), objectNode
.asResource().getURI());
} else {
action = new DropDataPropertyStatement(subject.getURI(),
predicate.getURI());
action = new DropDataPropertyStatement(vreq.getJenaOntModel(),
subject.getURI(), predicate.getURI());
}
return isAuthorizedForActions(req, action);
return isAuthorizedForActions(vreq, action);
}
/**

View file

@ -2,7 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
/**
@ -10,17 +11,20 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
* data property statements from a model.
*/
public abstract class AbstractDataPropertyStatementAction extends
RequestedAction {
AbstractPropertyStatementAction {
private final String subjectUri;
private final String predicateUri;
public AbstractDataPropertyStatementAction(String subjectUri,
String predicateUri) {
public AbstractDataPropertyStatementAction(OntModel ontModel,
String subjectUri, String predicateUri) {
super(ontModel);
this.subjectUri = subjectUri;
this.predicateUri = predicateUri;
}
public AbstractDataPropertyStatementAction(DataPropertyStatement dps) {
public AbstractDataPropertyStatementAction(OntModel ontModel,
DataPropertyStatement dps) {
super(ontModel);
this.subjectUri = (dps.getIndividual() == null) ? dps
.getIndividualURI() : dps.getIndividual().getURI();
this.predicateUri = dps.getDatapropURI();

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
/**
@ -14,14 +16,16 @@ public abstract class AbstractObjectPropertyStatementAction extends
private final String predicateUri;
private final String objectUri;
public AbstractObjectPropertyStatementAction(String subjectUri,
public AbstractObjectPropertyStatementAction(OntModel ontModel, String subjectUri,
String predicateUri, String objectUri) {
super(ontModel);
this.subjectUri = subjectUri;
this.predicateUri = predicateUri;
this.objectUri = objectUri;
}
public AbstractObjectPropertyStatementAction(ObjectPropertyStatement ops) {
public AbstractObjectPropertyStatementAction(OntModel ontModel, ObjectPropertyStatement ops) {
super(ontModel);
this.subjectUri = (ops.getSubject() == null) ? ops.getSubjectURI()
: ops.getSubject().getURI();
this.predicateUri = (ops.getProperty() == null) ? ops.getPropertyURI()

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
/**
@ -9,5 +11,13 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAct
* statements from a model.
*/
public abstract class AbstractPropertyStatementAction extends RequestedAction {
private final OntModel ontModel;
public AbstractPropertyStatementAction(OntModel ontModel) {
this.ontModel = ontModel;
}
public OntModel getOntModel() {
return ontModel;
}
}

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
/**
@ -10,12 +12,13 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
public class AddDataPropertyStatement extends
AbstractDataPropertyStatementAction {
public AddDataPropertyStatement(String subjectUri, String predicateUri) {
super(subjectUri, predicateUri);
public AddDataPropertyStatement(OntModel ontModel, String subjectUri,
String predicateUri) {
super(ontModel, subjectUri, predicateUri);
}
public AddDataPropertyStatement(DataPropertyStatement dps) {
super(dps);
public AddDataPropertyStatement(OntModel ontModel, DataPropertyStatement dps) {
super(ontModel, dps);
}
}

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
/**
@ -9,12 +11,13 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
*/
public class AddObjectPropertyStatement extends
AbstractObjectPropertyStatementAction {
public AddObjectPropertyStatement(String uriOfSub, String uriOfPred,
String uriOfObj) {
super(uriOfSub, uriOfPred, uriOfObj);
public AddObjectPropertyStatement(OntModel ontModel, String uriOfSub,
String uriOfPred, String uriOfObj) {
super(ontModel, uriOfSub, uriOfPred, uriOfObj);
}
public AddObjectPropertyStatement(ObjectPropertyStatement ops) {
super(ops);
public AddObjectPropertyStatement(OntModel ontModel,
ObjectPropertyStatement ops) {
super(ontModel, ops);
}
}

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
/**
@ -11,11 +13,13 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
public class DropDataPropertyStatement extends
AbstractDataPropertyStatementAction {
public DropDataPropertyStatement(String subjectUri, String predicateUri) {
super(subjectUri, predicateUri);
public DropDataPropertyStatement(OntModel ontModel, String subjectUri,
String predicateUri) {
super(ontModel, subjectUri, predicateUri);
}
public DropDataPropertyStatement(DataPropertyStatement dps) {
super(dps);
public DropDataPropertyStatement(OntModel ontModel,
DataPropertyStatement dps) {
super(ontModel, dps);
}
}

View file

@ -2,18 +2,23 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
/**
* Should we allow the user to delete this ObjectPropertyStatement from this
* model?
*/
public class DropObjectPropertyStatement extends AbstractObjectPropertyStatementAction {
public DropObjectPropertyStatement(String sub, String pred, String obj) {
super(sub, pred, obj);
public class DropObjectPropertyStatement extends
AbstractObjectPropertyStatementAction {
public DropObjectPropertyStatement(OntModel ontModel, String sub,
String pred, String obj) {
super(ontModel, sub, pred, obj);
}
public DropObjectPropertyStatement(ObjectPropertyStatement ops) {
super(ops);
public DropObjectPropertyStatement(OntModel ontModel,
ObjectPropertyStatement ops) {
super(ontModel, ops);
}
}

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
/**
@ -9,11 +11,13 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
*/
public class EditDataPropertyStatement extends
AbstractDataPropertyStatementAction {
public EditDataPropertyStatement(String subjectUri, String predicateUri) {
super(subjectUri, predicateUri);
public EditDataPropertyStatement(OntModel ontModel, String subjectUri,
String predicateUri) {
super(ontModel, subjectUri, predicateUri);
}
public EditDataPropertyStatement(DataPropertyStatement dps) {
super(dps);
public EditDataPropertyStatement(OntModel ontModel,
DataPropertyStatement dps) {
super(ontModel, dps);
}
}

View file

@ -2,18 +2,22 @@
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
/**
* Should we allow the user to edit this ObjectPropertyStatement in this model?
*/
public class EditObjectPropertyStatement extends AbstractObjectPropertyStatementAction {
public EditObjectPropertyStatement(String subjectUri, String keywordPredUri,
String objectUri) {
super(subjectUri, keywordPredUri, objectUri);
public class EditObjectPropertyStatement extends
AbstractObjectPropertyStatementAction {
public EditObjectPropertyStatement(OntModel ontModel, String subjectUri,
String keywordPredUri, String objectUri) {
super(ontModel, subjectUri, keywordPredUri, objectUri);
}
public EditObjectPropertyStatement(ObjectPropertyStatement ops) {
super(ops);
public EditObjectPropertyStatement(OntModel ontModel,
ObjectPropertyStatement ops) {
super(ontModel, ops);
}
}

View file

@ -89,7 +89,8 @@ public class ShowAuthController extends FreemarkerHttpServlet {
* this individual?
*/
private boolean mayEditIndividual(VitroRequest vreq, String individualUri) {
RequestedAction action = new EditObjectPropertyStatement(individualUri,
RequestedAction action = new EditObjectPropertyStatement(
vreq.getJenaOntModel(), individualUri,
RequestActionConstants.SOME_URI,
RequestActionConstants.SOME_URI);
return PolicyHelper.isAuthorizedForActions(vreq, action);

View file

@ -138,14 +138,16 @@ public class ImageUploadController extends FreemarkerHttpServlet {
RequestedAction ra;
if (ACTION_DELETE.equals(action)
|| ACTION_DELETE_EDIT.equals(action)) {
ra = new DropObjectPropertyStatement(entity.getURI(),
VitroVocabulary.IND_MAIN_IMAGE, imageUri);
ra = new DropObjectPropertyStatement(vreq.getJenaOntModel(),
entity.getURI(), VitroVocabulary.IND_MAIN_IMAGE,
imageUri);
} else if (imageUri != null) {
ra = new EditObjectPropertyStatement(entity.getURI(),
VitroVocabulary.IND_MAIN_IMAGE, imageUri);
ra = new EditObjectPropertyStatement(vreq.getJenaOntModel(),
entity.getURI(), VitroVocabulary.IND_MAIN_IMAGE,
imageUri);
} else {
ra = new AddObjectPropertyStatement(entity.getURI(),
VitroVocabulary.IND_MAIN_IMAGE,
ra = new AddObjectPropertyStatement(vreq.getJenaOntModel(),
entity.getURI(), VitroVocabulary.IND_MAIN_IMAGE,
RequestActionConstants.SOME_URI);
}
return new Actions(ra);

View file

@ -112,9 +112,11 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
* an object property to the Individual being shown.
*/
public boolean isEditable() {
AddDataPropertyStatement adps = new AddDataPropertyStatement(individual.getURI(),
AddDataPropertyStatement adps = new AddDataPropertyStatement(
vreq.getJenaOntModel(), individual.getURI(),
RequestActionConstants.SOME_URI);
AddObjectPropertyStatement aops = new AddObjectPropertyStatement(individual.getURI(),
AddObjectPropertyStatement aops = new AddObjectPropertyStatement(
vreq.getJenaOntModel(), individual.getURI(),
RequestActionConstants.SOME_URI,
RequestActionConstants.SOME_URI);
return PolicyHelper.isAuthorizedForActions(vreq, new Actions(adps).or(aops));

View file

@ -41,7 +41,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
private String makeDeleteUrl() {
// Determine whether the statement can be deleted
DataPropertyStatement dps = makeStatement();
RequestedAction action = new DropDataPropertyStatement(dps);
RequestedAction action = new DropDataPropertyStatement(vreq.getJenaOntModel(), dps);
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
return "";
}
@ -66,7 +66,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
// Determine whether the statement can be edited
DataPropertyStatement dps = makeStatement();
RequestedAction action = new EditDataPropertyStatement(dps);
RequestedAction action = new EditDataPropertyStatement(vreq.getJenaOntModel(), dps);
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
return "";
}

View file

@ -76,7 +76,8 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
}
// Determine whether a new statement can be added
RequestedAction action = new AddDataPropertyStatement(subjectUri, propertyUri);
RequestedAction action = new AddDataPropertyStatement(
vreq.getJenaOntModel(), subjectUri, propertyUri);
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
return;
}

View file

@ -62,7 +62,7 @@ public class NameStatementTemplateModel extends PropertyStatementTemplateModel {
private String makeEditUrl(Literal literal) {
// Determine whether the statement can be edited
DataPropertyStatement dps = makeStatement(literal);
RequestedAction action = new EditDataPropertyStatement(dps);
RequestedAction action = new EditDataPropertyStatement(vreq.getJenaOntModel(), dps);
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
return "";
}

View file

@ -55,7 +55,8 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
}
// Determine whether the statement can be deleted
RequestedAction action = new DropObjectPropertyStatement(subjectUri, propertyUri, objectUri);
RequestedAction action = new DropObjectPropertyStatement(
vreq.getJenaOntModel(), subjectUri, propertyUri, objectUri);
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
return "";
}
@ -96,7 +97,7 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
}
// Determine whether the statement can be edited
RequestedAction action = new EditObjectPropertyStatement(ops);
RequestedAction action = new EditObjectPropertyStatement(vreq.getJenaOntModel(), ops);
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
return "";
}

View file

@ -108,7 +108,9 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
}
// Determine whether a new statement can be added
RequestedAction action = new AddObjectPropertyStatement(subjectUri, propertyUri, RequestActionConstants.SOME_URI);
RequestedAction action = new AddObjectPropertyStatement(
vreq.getJenaOntModel(), subjectUri, propertyUri,
RequestActionConstants.SOME_URI);
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
return;
}