VIVO-682 Modify some auth code to work better with faux properties.
This commit is contained in:
parent
c08ac9eda0
commit
0bc3f211bb
19 changed files with 276 additions and 229 deletions
|
@ -15,7 +15,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayObje
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
|
||||
/**
|
||||
|
@ -111,11 +110,9 @@ public class DisplayByRolePermission extends Permission {
|
|||
* subject, its predicate, and its object.
|
||||
*/
|
||||
private boolean isAuthorized(DisplayObjectPropertyStatement action) {
|
||||
ObjectPropertyStatement stmt = action.getObjectPropertyStatement();
|
||||
String subjectUri = stmt.getSubjectURI();
|
||||
String objectUri = stmt.getObjectURI();
|
||||
Property op = (stmt.getProperty() != null)
|
||||
? stmt.getProperty() : new Property(stmt.getPropertyURI());
|
||||
String subjectUri = action.getSubjectUri();
|
||||
String objectUri = action.getObjectUri();
|
||||
Property op = action.getProperty();
|
||||
return canDisplayResource(subjectUri)
|
||||
&& canDisplayPredicate(op)
|
||||
&& canDisplayResource(objectUri);
|
||||
|
|
|
@ -95,7 +95,7 @@ public class DisplayRestrictedDataToSelfPolicy implements PolicyIface {
|
|||
String subjectUri = stmt.getIndividualURI();
|
||||
Property predicate = new Property(stmt.getDatapropURI());
|
||||
if (canDisplayResource(subjectUri) && canDisplayPredicate(predicate)
|
||||
&& isAboutAssociatedIndividual(individuals, stmt)) {
|
||||
&& isAboutAssociatedIndividual(individuals, subjectUri)) {
|
||||
return authorized("user may view DataPropertyStatement "
|
||||
+ subjectUri + " ==> " + predicate.getURI());
|
||||
} else {
|
||||
|
@ -112,19 +112,17 @@ public class DisplayRestrictedDataToSelfPolicy implements PolicyIface {
|
|||
*/
|
||||
private PolicyDecision isAuthorized(DisplayObjectPropertyStatement action,
|
||||
Collection<String> individuals) {
|
||||
ObjectPropertyStatement stmt = action.getObjectPropertyStatement();
|
||||
String subjectUri = stmt.getSubjectURI();
|
||||
String predicateUri = stmt.getPropertyURI();
|
||||
String objectUri = stmt.getObjectURI();
|
||||
if (canDisplayResource(subjectUri) && canDisplayPredicate(new Property
|
||||
(predicateUri))
|
||||
String subjectUri = action.getSubjectUri();
|
||||
Property predicate = action.getProperty();
|
||||
String objectUri = action.getObjectUri();
|
||||
if (canDisplayResource(subjectUri) && canDisplayPredicate(predicate)
|
||||
&& canDisplayResource(objectUri)
|
||||
&& isAboutAssociatedIndividual(individuals, stmt)) {
|
||||
&& isAboutAssociatedIndividual(individuals, subjectUri, objectUri)) {
|
||||
return authorized("user may view ObjectPropertyStatement "
|
||||
+ subjectUri + " ==> " + predicateUri + " ==> " + objectUri);
|
||||
+ subjectUri + " ==> " + predicate.getURI() + " ==> " + objectUri);
|
||||
} else {
|
||||
return defaultDecision("user may not view ObjectPropertyStatement "
|
||||
+ subjectUri + " ==> " + predicateUri + " ==> " + objectUri);
|
||||
+ subjectUri + " ==> " + predicate.getURI() + " ==> " + objectUri);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,9 +149,9 @@ public class DisplayRestrictedDataToSelfPolicy implements PolicyIface {
|
|||
}
|
||||
|
||||
private boolean isAboutAssociatedIndividual(Collection<String> selves,
|
||||
DataPropertyStatement stmt) {
|
||||
String subjectUri) {
|
||||
for (String self : selves) {
|
||||
if (self.equals(stmt.getIndividualURI())) {
|
||||
if (self.equals(subjectUri)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -161,10 +159,9 @@ public class DisplayRestrictedDataToSelfPolicy implements PolicyIface {
|
|||
}
|
||||
|
||||
private boolean isAboutAssociatedIndividual(Collection<String> selves,
|
||||
ObjectPropertyStatement stmt) {
|
||||
String subjectUri, String objectUri) {
|
||||
for (String self : selves) {
|
||||
if (self.equals(stmt.getSubjectURI())
|
||||
|| self.equals(stmt.getObjectURI())) {
|
||||
if (self.equals(subjectUri) || self.equals(objectUri)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_URI;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -26,6 +28,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.beans.Property;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
||||
|
||||
|
@ -125,8 +128,7 @@ public class PolicyHelper {
|
|||
}
|
||||
|
||||
Resource subject = stmt.getSubject();
|
||||
edu.cornell.mannlib.vitro.webapp.beans.Property predicate = new edu.cornell.mannlib.vitro.webapp.beans.Property(
|
||||
stmt.getPredicate().getURI());
|
||||
com.hp.hpl.jena.rdf.model.Property predicate = stmt.getPredicate();
|
||||
RDFNode objectNode = stmt.getObject();
|
||||
if ((subject == null) || (predicate == null) || (objectNode == null)) {
|
||||
return false;
|
||||
|
@ -134,8 +136,11 @@ public class PolicyHelper {
|
|||
|
||||
RequestedAction action;
|
||||
if (objectNode.isResource()) {
|
||||
Property property = new Property(predicate.getURI());
|
||||
property.setDomainVClassURI(SOME_URI);
|
||||
property.setRangeVClassURI(SOME_URI);
|
||||
action = new AddObjectPropertyStatement(modelToBeModified,
|
||||
subject.getURI(), predicate, objectNode.asResource()
|
||||
subject.getURI(), property, objectNode.asResource()
|
||||
.getURI());
|
||||
} else {
|
||||
action = new AddDataPropertyStatement(modelToBeModified,
|
||||
|
@ -158,8 +163,7 @@ public class PolicyHelper {
|
|||
}
|
||||
|
||||
Resource subject = stmt.getSubject();
|
||||
edu.cornell.mannlib.vitro.webapp.beans.Property predicate = new edu.cornell.mannlib.vitro.webapp.beans.Property();
|
||||
predicate.setURI(stmt.getPredicate().getURI());
|
||||
com.hp.hpl.jena.rdf.model.Property predicate = stmt.getPredicate();
|
||||
RDFNode objectNode = stmt.getObject();
|
||||
if ((subject == null) || (predicate == null) || (objectNode == null)) {
|
||||
return false;
|
||||
|
@ -167,8 +171,11 @@ public class PolicyHelper {
|
|||
|
||||
RequestedAction action;
|
||||
if (objectNode.isResource()) {
|
||||
Property property = new Property(predicate.getURI());
|
||||
property.setDomainVClassURI(SOME_URI);
|
||||
property.setRangeVClassURI(SOME_URI);
|
||||
action = new DropObjectPropertyStatement(modelToBeModified,
|
||||
subject.getURI(), predicate, objectNode.asResource()
|
||||
subject.getURI(), property, objectNode.asResource()
|
||||
.getURI());
|
||||
} else {
|
||||
action = new DropDataPropertyStatement(modelToBeModified,
|
||||
|
|
|
@ -209,7 +209,9 @@ public class PropertyRestrictionPolicyHelper {
|
|||
role = faux.getHiddenFromPublishBelowRoleLevel();
|
||||
}
|
||||
if (role != null) {
|
||||
log.debug("Putting D:" + faux.getDomainVClassURI() + " P:" + faux.getURI() + " R:" + faux.getRangeVClassURI() + " ==> L:" + role);
|
||||
log.debug("Putting D:" + faux.getDomainVClassURI() + " P:"
|
||||
+ faux.getURI() + " R:" + faux.getRangeVClassURI()
|
||||
+ " ==> L:" + role);
|
||||
map.put(new Pair<String,Pair<String,String>>(
|
||||
faux.getDomainVClassURI(), new Pair<String,String>(
|
||||
faux.getURI(), faux.getRangeVClassURI())), role);
|
||||
|
|
|
@ -3,27 +3,37 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
|
||||
/** Should we let the user see this ObjectPropertyStatement? */
|
||||
public class DisplayObjectPropertyStatement extends RequestedAction {
|
||||
private final ObjectPropertyStatement objectPropertyStatement;
|
||||
private final String subjectUri;
|
||||
private final ObjectProperty property;
|
||||
private final String objectUri;
|
||||
|
||||
public DisplayObjectPropertyStatement(
|
||||
ObjectPropertyStatement objectPropertyStatement) {
|
||||
this.objectPropertyStatement = objectPropertyStatement;
|
||||
public DisplayObjectPropertyStatement(String subjectUri,
|
||||
ObjectProperty property, String objectUri) {
|
||||
this.subjectUri = subjectUri;
|
||||
this.property = property;
|
||||
this.objectUri = objectUri;
|
||||
}
|
||||
|
||||
public ObjectPropertyStatement getObjectPropertyStatement() {
|
||||
return objectPropertyStatement;
|
||||
public String getSubjectUri() {
|
||||
return subjectUri;
|
||||
}
|
||||
|
||||
public ObjectProperty getProperty() {
|
||||
return property;
|
||||
}
|
||||
|
||||
public String getObjectUri() {
|
||||
return objectUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DisplayObjectPropertyStatement["
|
||||
+ objectPropertyStatement.getSubjectURI() + "==>"
|
||||
+ objectPropertyStatement.getPropertyURI() + "==>"
|
||||
+ objectPropertyStatement.getObjectURI() + "]";
|
||||
return "DisplayObjectPropertyStatement[" + subjectUri + "==>"
|
||||
+ property.getURI() + "==>" + objectUri + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
|
|||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
|
||||
/**
|
||||
|
@ -26,23 +24,6 @@ public abstract class AbstractObjectPropertyStatementAction extends
|
|||
this.objectUri = objectUri;
|
||||
}
|
||||
|
||||
public AbstractObjectPropertyStatementAction(OntModel ontModel,
|
||||
ObjectPropertyStatement ops) {
|
||||
super(ontModel);
|
||||
this.subjectUri = (ops.getSubject() == null) ? ops.getSubjectURI()
|
||||
: ops.getSubject().getURI();
|
||||
this.predicate = (ops.getProperty() == null) ? createProperty(ops
|
||||
.getPropertyURI()) : ops.getProperty();
|
||||
this.objectUri = (ops.getObject() == null) ? ops.getObjectURI() : ops
|
||||
.getObject().getURI();
|
||||
}
|
||||
|
||||
private ObjectProperty createProperty(String propertyURI) {
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI(propertyURI);
|
||||
return op;
|
||||
}
|
||||
|
||||
public String getSubjectUri() {
|
||||
return subjectUri;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
|
|||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
|
||||
/**
|
||||
|
@ -17,8 +16,4 @@ public class AddObjectPropertyStatement extends
|
|||
super(ontModel, uriOfSub, predicate, uriOfObj);
|
||||
}
|
||||
|
||||
public AddObjectPropertyStatement(OntModel ontModel,
|
||||
ObjectPropertyStatement ops) {
|
||||
super(ontModel, ops);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
|
|||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
|
||||
/**
|
||||
|
@ -17,9 +16,4 @@ public class DropObjectPropertyStatement extends
|
|||
Property pred, String obj) {
|
||||
super(ontModel, sub, pred, obj);
|
||||
}
|
||||
|
||||
public DropObjectPropertyStatement(OntModel ontModel,
|
||||
ObjectPropertyStatement ops) {
|
||||
super(ontModel, ops);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt;
|
|||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
|
||||
/**
|
||||
|
@ -16,9 +15,4 @@ public class EditObjectPropertyStatement extends
|
|||
Property keywordPred, String objectUri) {
|
||||
super(ontModel, subjectUri, keywordPred, objectUri);
|
||||
}
|
||||
|
||||
public EditObjectPropertyStatement(OntModel ontModel,
|
||||
ObjectPropertyStatement ops) {
|
||||
super(ontModel, ops);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish;
|
|||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AbstractObjectPropertyStatementAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
|
||||
/**
|
||||
|
@ -20,9 +20,20 @@ public class PublishObjectPropertyStatement extends
|
|||
super(ontModel, subjectUri, keywordPred, objectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* We don't need to know range and domain because publishing never involves
|
||||
* faux properties.
|
||||
*/
|
||||
public PublishObjectPropertyStatement(OntModel ontModel,
|
||||
ObjectPropertyStatement ops) {
|
||||
super(ontModel, ops);
|
||||
String subjectUri,
|
||||
String predicateUri, String objectUri) {
|
||||
this(ontModel, subjectUri, populateProperty(predicateUri), objectUri);
|
||||
}
|
||||
|
||||
private static Property populateProperty(String predicateUri) {
|
||||
Property prop = new Property(predicateUri);
|
||||
prop.setDomainVClassURI(RequestActionConstants.SOME_URI);
|
||||
prop.setRangeVClassURI(RequestActionConstants.SOME_URI);
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishData
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RdfResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
|
@ -171,15 +169,16 @@ public class IndividualRdfAssembler {
|
|||
+ "WHERE { <%1$s> ?predicate ?object ."
|
||||
+ " ?object <%2$s> ?label . } ", individualUri,
|
||||
RDFS.label)));
|
||||
m.add(runConstructQuery(String
|
||||
.format("CONSTRUCT { ?subject <%2$s> ?type . } "
|
||||
m.add(runConstructQuery(String.format(
|
||||
"CONSTRUCT { ?subject <%2$s> ?type . } "
|
||||
+ "WHERE { ?subject ?predicate <%1$s> ."
|
||||
+ " ?subject <%2$s> ?type . } ", individualUri, RDF.type)));
|
||||
+ " ?subject <%2$s> ?type . } ", individualUri,
|
||||
RDF.type)));
|
||||
m.add(runConstructQuery(String.format(
|
||||
"CONSTRUCT { ?subject <%2$s> ?label . } "
|
||||
+ "WHERE { ?subject ?predicate <%1$s> ."
|
||||
+ " ?subject <%2$s> ?label . } ", individualUri,
|
||||
RDFS.label)));
|
||||
RDFS.label)));
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -213,9 +212,8 @@ public class IndividualRdfAssembler {
|
|||
}
|
||||
} else if (stmt.getObject().isURIResource()) {
|
||||
String objectUri = stmt.getObject().asResource().getURI();
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(
|
||||
RequestedAction pops = new PublishObjectPropertyStatement(o,
|
||||
subjectUri, predicateUri, objectUri);
|
||||
RequestedAction pops = new PublishObjectPropertyStatement(o, ops);
|
||||
if (!PolicyHelper.isAuthorizedForActions(vreq, pops)) {
|
||||
log.debug("not authorized: " + pops);
|
||||
stmts.remove();
|
||||
|
|
|
@ -20,11 +20,13 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayData
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayDataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
|
||||
/**
|
||||
* Filter the properties depending on what DisplayByRolePermission is on the
|
||||
|
@ -117,7 +119,30 @@ public class FilterByRoleLevelPermission extends VitroFiltersImpl {
|
|||
UnaryFunctor<ObjectPropertyStatement, Boolean> {
|
||||
@Override
|
||||
public Boolean fn(ObjectPropertyStatement ops) {
|
||||
return checkAuthorization(new DisplayObjectPropertyStatement(ops));
|
||||
String subjectUri = ops.getSubjectURI();
|
||||
ObjectProperty predicate = getOrCreateProperty(ops);
|
||||
String objectUri = ops.getObjectURI();
|
||||
return checkAuthorization(new DisplayObjectPropertyStatement(
|
||||
subjectUri, predicate, objectUri));
|
||||
}
|
||||
|
||||
/**
|
||||
* It would be nice if every ObjectPropertyStatement held a real
|
||||
* ObjectProperty. If it doesn't, we do the next best thing, but it
|
||||
* won't recognize any applicaable Faux properties.
|
||||
*/
|
||||
private ObjectProperty getOrCreateProperty(ObjectPropertyStatement ops) {
|
||||
if (ops.getProperty() != null) {
|
||||
return ops.getProperty();
|
||||
}
|
||||
if (ops.getPropertyURI() == null) {
|
||||
return null;
|
||||
}
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI(ops.getPropertyURI());
|
||||
op.setDomainVClassURI(RequestActionConstants.SOME_URI);
|
||||
op.setRangeVClassURI(RequestActionConstants.SOME_URI);
|
||||
return op;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayData
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayDataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
|
@ -88,7 +89,31 @@ public class HideFromDisplayByPolicyFilter extends VitroFiltersImpl {
|
|||
UnaryFunctor<ObjectPropertyStatement, Boolean> {
|
||||
@Override
|
||||
public Boolean fn(ObjectPropertyStatement ops) {
|
||||
return checkAuthorization(new DisplayObjectPropertyStatement(ops));
|
||||
String subjectUri = ops.getSubjectURI();
|
||||
ObjectProperty predicate = getOrCreateProperty(ops);
|
||||
String objectUri = ops.getObjectURI();
|
||||
return checkAuthorization(new DisplayObjectPropertyStatement(
|
||||
subjectUri, predicate, objectUri));
|
||||
}
|
||||
|
||||
/**
|
||||
* It would be nice if every ObjectPropertyStatement held a real
|
||||
* ObjectProperty. If it doesn't, we do the next best thing, but it
|
||||
* won't recognize any applicaable Faux properties.
|
||||
*/
|
||||
private ObjectProperty getOrCreateProperty(ObjectPropertyStatement ops) {
|
||||
if (ops.getProperty() != null) {
|
||||
return ops.getProperty();
|
||||
}
|
||||
if (ops.getPropertyURI() == null) {
|
||||
return null;
|
||||
}
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI(ops.getPropertyURI());
|
||||
op.setDomainVClassURI(RequestActionConstants.SOME_URI);
|
||||
op.setRangeVClassURI(RequestActionConstants.SOME_URI);
|
||||
return op;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAct
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.DropObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||
|
@ -33,9 +30,9 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
|||
private final String editUrl;
|
||||
private final String deleteUrl;
|
||||
|
||||
public ObjectPropertyStatementTemplateModel(String subjectUri, ObjectProperty predicate, String objectKey,
|
||||
public ObjectPropertyStatementTemplateModel(String subjectUri, ObjectProperty property, String objectKey,
|
||||
Map<String, String> data, String templateName, VitroRequest vreq) {
|
||||
super(subjectUri, predicate, vreq);
|
||||
super(subjectUri, property, vreq);
|
||||
|
||||
this.data = Collections.unmodifiableMap(new HashMap<String, String>(data));
|
||||
this.objectUri = data.get(objectKey);
|
||||
|
@ -43,15 +40,12 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
|||
//to keep track of later
|
||||
this.objectKey = objectKey;
|
||||
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(subjectUri, property.getURI(), objectUri);
|
||||
ops.setProperty(predicate);
|
||||
|
||||
// Do delete url first, since it is used in building edit url
|
||||
this.deleteUrl = makeDeleteUrl(ops);
|
||||
this.editUrl = makeEditUrl(ops);
|
||||
this.deleteUrl = makeDeleteUrl();
|
||||
this.editUrl = makeEditUrl();
|
||||
}
|
||||
|
||||
private String makeDeleteUrl(ObjectPropertyStatement ops) {
|
||||
private String makeDeleteUrl() {
|
||||
// Is the delete link suppressed for this property?
|
||||
if (property.isDeleteLinkSuppressed()) {
|
||||
return "";
|
||||
|
@ -87,11 +81,11 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
|||
}
|
||||
}
|
||||
|
||||
if (ops.getProperty()!= null && ops.getProperty().getDomainVClassURI() != null) {
|
||||
params.put("domainUri", ops.getProperty().getDomainVClassURI());
|
||||
if (property!= null && property.getDomainVClassURI() != null) {
|
||||
params.put("domainUri", property.getDomainVClassURI());
|
||||
}
|
||||
if (ops.getProperty()!= null && ops.getProperty().getRangeVClassURI() != null) {
|
||||
params.put("rangeUri", ops.getProperty().getRangeVClassURI());
|
||||
if (property!= null && property.getRangeVClassURI() != null) {
|
||||
params.put("rangeUri", property.getRangeVClassURI());
|
||||
}
|
||||
|
||||
params.put("templateName", templateName);
|
||||
|
@ -100,14 +94,14 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
|||
return UrlBuilder.getUrl(EDIT_PATH, params);
|
||||
}
|
||||
|
||||
private String makeEditUrl(ObjectPropertyStatement ops) {
|
||||
private String makeEditUrl() {
|
||||
// Is the edit link suppressed for this property?
|
||||
if (property.isEditLinkSuppressed()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// Determine whether the statement can be edited
|
||||
RequestedAction action = new EditObjectPropertyStatement(vreq.getJenaOntModel(), ops);
|
||||
RequestedAction action = new EditObjectPropertyStatement(vreq.getJenaOntModel(), subjectUri, property, objectUri);
|
||||
if ( ! PolicyHelper.isAuthorizedForActions(vreq, action) ) {
|
||||
return "";
|
||||
}
|
||||
|
@ -125,11 +119,11 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
|
|||
params.put("deleteProhibited", "prohibited");
|
||||
}
|
||||
|
||||
if (ops.getProperty()!= null && ops.getProperty().getDomainVClassURI() != null) {
|
||||
params.put("domainUri", ops.getProperty().getDomainVClassURI());
|
||||
if (property!= null && property.getDomainVClassURI() != null) {
|
||||
params.put("domainUri", property.getDomainVClassURI());
|
||||
}
|
||||
if (ops.getProperty()!= null && ops.getProperty().getRangeVClassURI() != null) {
|
||||
params.put("rangeUri", ops.getProperty().getRangeVClassURI());
|
||||
if (property!= null && property.getRangeVClassURI() != null) {
|
||||
params.put("rangeUri", property.getRangeVClassURI());
|
||||
}
|
||||
|
||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||
|
|
|
@ -21,8 +21,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
@ -82,9 +80,8 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
|||
return true;
|
||||
}
|
||||
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(
|
||||
subject.getURI(), op.getURI(), SOME_URI);
|
||||
RequestedAction dops = new DisplayObjectPropertyStatement(ops);
|
||||
RequestedAction dops = new DisplayObjectPropertyStatement(
|
||||
subject.getURI(), op, SOME_URI);
|
||||
if (PolicyHelper.isAuthorizedForActions(vreq, dops)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -122,7 +119,8 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
|||
}
|
||||
|
||||
|
||||
public String toString(){
|
||||
@Override
|
||||
public String toString(){
|
||||
String ptmStr ="";
|
||||
for( int i=0; i < properties.size() ; i ++ ){
|
||||
PropertyTemplateModel ptm = properties.get(i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue