Merge branch 'maint-rel-1.6' into develop

This commit is contained in:
j2blake 2014-03-25 15:44:59 -04:00
commit 09dd8da784
19 changed files with 276 additions and 229 deletions

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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,

View file

@ -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);

View file

@ -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 + "]";
}
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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,10 +169,11 @@ 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> ."
@ -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();

View file

@ -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;
}
}

View file

@ -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;
}
}
}

View file

@ -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));

View file

@ -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,6 +119,7 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
}
@Override
public String toString(){
String ptmStr ="";
for( int i=0; i < properties.size() ; i ++ ){

View file

@ -4,11 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy;
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_LITERAL;
import java.io.InputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -19,7 +16,6 @@ import stubs.javax.servlet.ServletContextStub;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
@ -81,19 +77,6 @@ public class SelfEditingPolicy_2_Test extends AbstractTestClass {
@Before
public void setUp() throws Exception {
InputStream is = getClass().getResourceAsStream(
"./SelfEditingPolicy_2_Test.xml");
Assert.assertNotNull(is);
// suppress the warning messages from loading the model.
setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF);
// TODO This doesn't appear to be used for anything. Can it go away, along with the data file?
OntModel model = ModelFactory.createOntologyModel();
model.read(is, "");
Assert.assertNotNull(model);
Assert.assertTrue(model.size() > 0);
ServletContextStub ctx = new ServletContextStub();
PropertyRestrictionPolicyHelper.setBean(ctx,
PropertyRestrictionPolicyHelperStub

View file

@ -1,45 +0,0 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<rdf:RDF
xmlns:owl ="http://www.w3.org/2002/07/owl#"
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs ="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd ="http://www.w3.org/2001/XMLSchema#"
xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
xmlns =""
>
<owl:Ontology rdf:about="">
<rdfs:comment>
An ontology with a property with a prohibited annotation for unit testing.
</rdfs:comment>
</owl:Ontology>
<owl:AnnotationProperty rdf:about="vitro:selfEditProhibitedAnnot"/>
<owl:ObjectProperty rdf:about="vitro:hasSuperPowers">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="vitro:mayPrintMoney">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="vitro:getsOutOfJailFree">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="vitro:canDeleteModel">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:ObjectProperty>
<owl:DatatypeProperty rdf:about="vitro:felonies">
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
</owl:DatatypeProperty>
</rdf:RDF>

View file

@ -2,7 +2,9 @@
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
import static edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants.SOME_URI;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@ -82,12 +84,22 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
private static final String URI_VISIBLE_OBJECT_ORDINARY = "object://visible_on_ordinary";
private static final String URI_MAYBE_OBJECT_ORDINARY = "object://maybe_on_ordinary";
private static final String FAUX_DOMAIN_VISIBLE = "faux://visibleDomain";
private static final String FAUX_RANGE_VISIBLE = "faux://visibleRange";
private static final String FAUX_DOMAIN_HIDDEN = "faux://hiddenDomain";
private static final String FAUX_RANGE_HIDDEN = "faux://hiddenRange";
private static final String URI_FAUX_VISIBLE_ORDINARY = "object://faux_visible_on_ordinary";
private static final String URI_FAUX_HIDDEN_ORDINARY = "object://faux_hidden_on_ordinary";
private IndividualStub indSpecial;
private IndividualStub indOrdinary;
private Individual filteredSpecial;
private Individual filteredOrdinary;
@Before
public void createIndividuals() {
IndividualStub indSpecial = new IndividualStub(URI_INDIVIDUAL_SPECIAL);
indSpecial = new IndividualStub(URI_INDIVIDUAL_SPECIAL);
indSpecial.addDataPropertyStatement(PROPERTY_DATA_HIDDEN,
VALUE_HIDDEN_DATA_SPECIAL);
@ -96,17 +108,17 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
indSpecial.addDataPropertyStatement(PROPERTY_DATA_MAYBE,
VALUE_MAYBE_DATA_SPECIAL);
indSpecial.addObjectPropertyStatement(PROPERTY_OBJECT_HIDDEN,
indSpecial.addObjectPropertyStatement(property(PROPERTY_OBJECT_HIDDEN),
URI_HIDDEN_OBJECT_SPECIAL);
indSpecial.addObjectPropertyStatement(PROPERTY_OBJECT_VISIBLE,
URI_VISIBLE_OBJECT_SPECIAL);
indSpecial.addObjectPropertyStatement(PROPERTY_OBJECT_MAYBE,
indSpecial.addObjectPropertyStatement(
property(PROPERTY_OBJECT_VISIBLE), URI_VISIBLE_OBJECT_SPECIAL);
indSpecial.addObjectPropertyStatement(property(PROPERTY_OBJECT_MAYBE),
URI_MAYBE_OBJECT_SPECIAL);
filteredSpecial = new IndividualFiltering(indSpecial,
new IndividualBasedFilter());
IndividualStub indOrdinary = new IndividualStub("someOtherUri");
indOrdinary = new IndividualStub("someOtherUri");
indOrdinary.addDataPropertyStatement(PROPERTY_DATA_HIDDEN,
VALUE_HIDDEN_DATA_ORDINARY);
@ -115,17 +127,30 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
indOrdinary.addDataPropertyStatement(PROPERTY_DATA_MAYBE,
VALUE_MAYBE_DATA_ORDINARY);
indOrdinary.addObjectPropertyStatement(PROPERTY_OBJECT_HIDDEN,
URI_HIDDEN_OBJECT_ORDINARY);
indOrdinary.addObjectPropertyStatement(PROPERTY_OBJECT_VISIBLE,
URI_VISIBLE_OBJECT_ORDINARY);
indOrdinary.addObjectPropertyStatement(PROPERTY_OBJECT_MAYBE,
indOrdinary.addObjectPropertyStatement(
property(PROPERTY_OBJECT_HIDDEN), URI_HIDDEN_OBJECT_ORDINARY);
indOrdinary.addObjectPropertyStatement(
property(PROPERTY_OBJECT_VISIBLE), URI_VISIBLE_OBJECT_ORDINARY);
indOrdinary.addObjectPropertyStatement(property(PROPERTY_OBJECT_MAYBE),
URI_MAYBE_OBJECT_ORDINARY);
filteredOrdinary = new IndividualFiltering(indOrdinary,
new IndividualBasedFilter());
}
private ObjectProperty property(String propertyUri) {
return property(propertyUri, SOME_URI, SOME_URI);
}
private ObjectProperty property(String propertyUri, String domainUri,
String rangeUri) {
ObjectProperty op = new ObjectProperty();
op.setURI(propertyUri);
op.setDomainVClassURI(domainUri);
op.setRangeVClassURI(rangeUri);
return op;
}
// ----------------------------------------------------------------------
// Tests on data properties
// ----------------------------------------------------------------------
@ -363,6 +388,41 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
fail("onOrdinary_getPopulatedObjectPropertyList not implemented");
}
// ----------------------------------------------------------------------
// Tests on Faux object properties
// ----------------------------------------------------------------------
@Test
public void hiddenFauxWithVisibleBase() {
indOrdinary.addObjectPropertyStatement(
property(PROPERTY_OBJECT_VISIBLE, FAUX_DOMAIN_HIDDEN,
FAUX_RANGE_HIDDEN), URI_FAUX_HIDDEN_ORDINARY);
filteredOrdinary = new IndividualFiltering(indOrdinary,
new IndividualBasedFilter());
List<ObjectPropertyStatement> expected = opsList(filteredOrdinary,
ops(PROPERTY_OBJECT_VISIBLE, URI_VISIBLE_OBJECT_ORDINARY));
List<ObjectPropertyStatement> actual = filteredOrdinary
.getObjectPropertyStatements();
assertEquivalentOpsList("hidden faux is not visible", expected, actual);
}
@Test
public void visibleFauxWithHiddenBase() {
indOrdinary.addObjectPropertyStatement(
property(PROPERTY_OBJECT_HIDDEN, FAUX_DOMAIN_VISIBLE,
FAUX_RANGE_VISIBLE), URI_FAUX_VISIBLE_ORDINARY);
filteredOrdinary = new IndividualFiltering(indOrdinary,
new IndividualBasedFilter());
List<ObjectPropertyStatement> expected = opsList(filteredOrdinary,
ops(PROPERTY_OBJECT_VISIBLE, URI_VISIBLE_OBJECT_ORDINARY),
ops(PROPERTY_OBJECT_HIDDEN, URI_FAUX_VISIBLE_ORDINARY));
List<ObjectPropertyStatement> actual = filteredOrdinary
.getObjectPropertyStatements();
assertEquivalentOpsList("visible faux even if base is hidden",
expected, actual);
}
// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------
@ -726,14 +786,33 @@ public class IndividualFilteringByStatementTest extends AbstractTestClass {
@Override
public Boolean fn(ObjectPropertyStatement ops) {
if (PROPERTY_OBJECT_VISIBLE.equals(ops.getPropertyURI())) {
if (isFauxHidden(ops)) {
return false;
} else {
return true;
}
}
if (PROPERTY_OBJECT_MAYBE.equals(ops.getPropertyURI())
&& URI_INDIVIDUAL_SPECIAL.equals(ops.getSubjectURI())) {
return true;
}
if (isFauxVisible(ops)) {
return true;
}
return false;
}
private boolean isFauxHidden(ObjectPropertyStatement ops) {
ObjectProperty prop = ops.getProperty();
return FAUX_DOMAIN_HIDDEN.equals(prop.getDomainVClassURI())
&& FAUX_RANGE_HIDDEN.equals(prop.getRangeVClassURI());
}
private boolean isFauxVisible(ObjectPropertyStatement ops) {
ObjectProperty prop = ops.getProperty();
return FAUX_DOMAIN_VISIBLE.equals(prop.getDomainVClassURI())
&& FAUX_RANGE_VISIBLE.equals(prop.getRangeVClassURI());
}
}
// ----------------------------------------------------------------------

View file

@ -12,6 +12,9 @@ import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
@ -21,6 +24,7 @@ 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.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
/**
* Mock the basic functions of Individual for unit tests.
@ -31,6 +35,8 @@ public class IndividualStub implements Individual {
// ----------------------------------------------------------------------
private final String uri;
private final String namespace;
private final String localName;
private final Set<DataPropertyStatement> dpsSet = new HashSet<DataPropertyStatement>();
private final Set<ObjectPropertyStatement> opsSet = new HashSet<ObjectPropertyStatement>();
@ -40,27 +46,25 @@ public class IndividualStub implements Individual {
public IndividualStub(String uri) {
this.uri = uri;
Resource r = ResourceFactory.createResource(uri);
this.namespace = r.getNameSpace();
this.localName = r.getLocalName();
}
public void addDataPropertyStatement(String predicateUri, String object) {
dpsSet.add(new DataPropertyStatementImpl(this.uri, predicateUri, object));
}
public void addObjectPropertyStatement(String predicateUri, String objectUri) {
opsSet.add(new ObjectPropertyStatementImpl(this.uri, predicateUri,
objectUri));
public void addObjectPropertyStatement(ObjectProperty property, String objectUri) {
ObjectPropertyStatementImpl ops = new ObjectPropertyStatementImpl();
ops.setSubject(this);
ops.setProperty(property);
ops.setObjectURI(objectUri);
opsSet.add(ops);
}
public void addPopulatedObjectPropertyStatement(String predicateUri,
String objectUri, Individual object) {
ObjectPropertyStatementImpl stmt = new ObjectPropertyStatementImpl(
this.uri, predicateUri, objectUri);
stmt.setObject(object);
opsSet.add(stmt);
}
public void addVclass(String namespace, String localname, String vClassName) {
vClasses.add(new VClass(namespace, localname, vClassName));
public void addVclass(String ns, String localname, String vClassName) {
vClasses.add(new VClass(ns, localname, vClassName));
}
// ----------------------------------------------------------------------
@ -72,6 +76,22 @@ public class IndividualStub implements Individual {
return uri;
}
@Override
public boolean isAnonymous() {
return (this.uri == null || VitroVocabulary.PSEUDO_BNODE_NS.equals(this
.getNamespace()));
}
@Override
public String getLocalName() {
return this.localName;
}
@Override
public String getNamespace() {
return this.namespace;
}
@Override
public void setName(String name) {
this.name = name;
@ -166,12 +186,6 @@ public class IndividualStub implements Individual {
// does nothing.
}
@Override
public String getLocalName() {
// Useless for now.
return "BOGUS Local Name";
}
@Override
public VClass getVClass() {
for (VClass vc : vClasses) {
@ -197,69 +211,57 @@ public class IndividualStub implements Individual {
// Un-implemented methods
// ----------------------------------------------------------------------
@Override
public boolean isAnonymous() {
throw new RuntimeException(
"ResourceBean.isAnonymous() not implemented.");
}
@Override
public void setURI(String URI) {
throw new RuntimeException("ResourceBean.setURI() not implemented.");
}
@Override
public String getNamespace() {
throw new RuntimeException(
"ResourceBean.getNamespace() not implemented.");
throw new RuntimeException("IndividualStub.setURI() not implemented.");
}
@Override
public void setNamespace(String namespace) {
throw new RuntimeException(
"ResourceBean.setNamespace() not implemented.");
"IndividualStub.setNamespace() not implemented.");
}
@Override
public void setLocalName(String localName) {
throw new RuntimeException(
"ResourceBean.setLocalName() not implemented.");
"IndividualStub.setLocalName() not implemented.");
}
@Override
public RoleLevel getHiddenFromDisplayBelowRoleLevel() {
throw new RuntimeException(
"ResourceBean.getHiddenFromDisplayBelowRoleLevel() not implemented.");
"IndividualStub.getHiddenFromDisplayBelowRoleLevel() not implemented.");
}
@Override
public void setHiddenFromDisplayBelowRoleLevel(RoleLevel eR) {
throw new RuntimeException(
"ResourceBean.setHiddenFromDisplayBelowRoleLevel() not implemented.");
"IndividualStub.setHiddenFromDisplayBelowRoleLevel() not implemented.");
}
@Override
public void setHiddenFromDisplayBelowRoleLevelUsingRoleUri(String roleUri) {
throw new RuntimeException(
"ResourceBean.setHiddenFromDisplayBelowRoleLevelUsingRoleUri() not implemented.");
"IndividualStub.setHiddenFromDisplayBelowRoleLevelUsingRoleUri() not implemented.");
}
@Override
public RoleLevel getProhibitedFromUpdateBelowRoleLevel() {
throw new RuntimeException(
"ResourceBean.getProhibitedFromUpdateBelowRoleLevel() not implemented.");
"IndividualStub.getProhibitedFromUpdateBelowRoleLevel() not implemented.");
}
@Override
public void setProhibitedFromUpdateBelowRoleLevel(RoleLevel eR) {
throw new RuntimeException(
"ResourceBean.setProhibitedFromUpdateBelowRoleLevel() not implemented.");
"IndividualStub.setProhibitedFromUpdateBelowRoleLevel() not implemented.");
}
@Override
public void setProhibitedFromUpdateBelowRoleLevelUsingRoleUri(String roleUri) {
throw new RuntimeException(
"ResourceBean.setProhibitedFromUpdateBelowRoleLevelUsingRoleUri() not implemented.");
"IndividualStub.setProhibitedFromUpdateBelowRoleLevelUsingRoleUri() not implemented.");
}
@Override