Merging with issue-vivo-101-sparqlupdate. Using develop licenser files that were in conflict. VIVO-255 VIVO-101
This commit is contained in:
commit
4c42128993
41 changed files with 1606 additions and 414 deletions
|
@ -0,0 +1,154 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AllRequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AnyRequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.UnauthorizedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
|
||||
public class PolicyListTest {
|
||||
|
||||
@Test
|
||||
public void basicPolicyListTest() {
|
||||
|
||||
List<PolicyIface> polis = new ArrayList<PolicyIface>();
|
||||
polis.add( new SimplePolicy() );
|
||||
PolicyIface policy = new PolicyList( polis );
|
||||
PolicyDecision decision = policy.isAuthorized(null, new UnauthorizedAction());
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
decision = policy.isAuthorized(null, new AuthorizedAction());
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the handling of the AnyRequestedAction by the PolicyList.
|
||||
*/
|
||||
@Test
|
||||
public void anyActionTest(){
|
||||
List<PolicyIface> polis = new ArrayList<PolicyIface>();
|
||||
polis.add( new SimplePolicy() );
|
||||
PolicyIface policy = new PolicyList( polis );
|
||||
|
||||
AnyRequestedAction act = new AnyRequestedAction( new UnauthorizedAction() );
|
||||
PolicyDecision decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction() , new UnauthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction(),new UnauthorizedAction(),new UnauthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new AuthorizedAction(),new UnauthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction(),new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction(),new UnauthorizedAction(),new AuthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction(),new AuthorizedAction(),new AuthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new AuthorizedAction(),new AuthorizedAction(),new AuthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the handling of the AllRequestedAction by the PolicyList.
|
||||
*/
|
||||
@Test
|
||||
public void andActionTest(){
|
||||
List<PolicyIface> polis = new ArrayList<PolicyIface>();
|
||||
polis.add( new SimplePolicy() );
|
||||
PolicyIface policy = new PolicyList( polis );
|
||||
|
||||
AllRequestedAction act = new AllRequestedAction( new UnauthorizedAction(), new UnauthorizedAction(), new UnauthorizedAction());
|
||||
PolicyDecision decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new UnauthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new UnauthorizedAction() , new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new AuthorizedAction() , new UnauthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new AuthorizedAction() , new AuthorizedAction() ,new UnauthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new AuthorizedAction() , new AuthorizedAction(), new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* policy that only responds to Unauthorized and Authorized actions.
|
||||
*/
|
||||
public class SimplePolicy implements PolicyIface {
|
||||
|
||||
@Override
|
||||
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth,
|
||||
RequestedAction whatToAuth) {
|
||||
if( whatToAuth instanceof UnauthorizedAction )
|
||||
return new BasicPolicyDecision( Authorization.UNAUTHORIZED, "SimplePolicy unauthorized");
|
||||
if( whatToAuth instanceof AuthorizedAction )
|
||||
return new BasicPolicyDecision( Authorization.AUTHORIZED, "SimplePolicy authorized");
|
||||
else
|
||||
return new BasicPolicyDecision(Authorization.INCONCLUSIVE, "SimplePolicy INCONCLUSIVE");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.github.jsonldjava.core.JSONLD;
|
||||
import com.github.jsonldjava.core.JSONLDProcessingError;
|
||||
import com.github.jsonldjava.impl.JenaRDFParser;
|
||||
import com.github.jsonldjava.utils.JSONUtils;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
public class SparqlQueryServletTest {
|
||||
|
||||
@Test
|
||||
public void testJSONLD() throws JSONLDProcessingError {
|
||||
//just check if we can use JSONLD-JAVA
|
||||
|
||||
final String turtle = "@prefix const: <http://foo.com/> .\n"
|
||||
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n"
|
||||
+ "<http://localhost:8080/foo1> const:code \"123\" .\n"
|
||||
+ "<http://localhost:8080/foo2> const:code \"ABC\"^^xsd:string .\n";
|
||||
|
||||
final List<Map<String, Object>> expected = new ArrayList<Map<String, Object>>() {
|
||||
{
|
||||
add(new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("@id", "http://localhost:8080/foo1");
|
||||
put("http://foo.com/code", new ArrayList<Object>() {
|
||||
{
|
||||
add(new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("@value", "123");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
add(new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("@id", "http://localhost:8080/foo2");
|
||||
put("http://foo.com/code", new ArrayList<Object>() {
|
||||
{
|
||||
add(new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("@value", "ABC");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
final Model modelResult = ModelFactory.createDefaultModel().read(
|
||||
new ByteArrayInputStream(turtle.getBytes()), "", "TURTLE");
|
||||
final JenaRDFParser parser = new JenaRDFParser();
|
||||
final Object json = JSONLD.fromRDF(modelResult, parser);
|
||||
|
||||
assertTrue(JSONUtils.equals(json, expected));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue