NIHVIVO-2492 Modify authorizations based on action-classes to be based on actions instead.
This commit is contained in:
parent
87b87c8edf
commit
b82cf72807
4 changed files with 4 additions and 364 deletions
|
@ -17,14 +17,11 @@ import stubs.javax.servlet.http.HttpServletRequestStub;
|
|||
import stubs.javax.servlet.http.HttpSessionStub;
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper.RequiresAuthorizationFor;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper.RequiresAuthorizationFor.Or;
|
||||
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.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
|
||||
/**
|
||||
* Test the basic top-level function of PolicyHelper.
|
||||
|
@ -96,125 +93,6 @@ public class PolicyHelperTest extends AbstractTestClass {
|
|||
new Action1(), new Action2()).or(new Action3())));
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* actions is null,
|
||||
* actions is empty
|
||||
* actions has one clause with multiple actions
|
||||
* all pass
|
||||
* some pass
|
||||
* action has multiple clauses
|
||||
* one passes
|
||||
* none pass (but partial passes)
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------
|
||||
// Obsolete???
|
||||
// ----------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// @Test
|
||||
// public void noAnnotation() {
|
||||
// createPolicy();
|
||||
// assertExpectedAuthorization("no actions required",
|
||||
// NoAnnotationServlet.class, true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void noRequirements() {
|
||||
// createPolicy();
|
||||
// assertExpectedAuthorization("no actions required",
|
||||
// NoRequirementsServlet.class, true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneRequirementFail() {
|
||||
// createPolicy();
|
||||
// assertExpectedAuthorization("requires Action1", Action1Servlet.class,
|
||||
// false);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneRequirementSucceed() {
|
||||
// createPolicy(new Action1());
|
||||
// assertExpectedAuthorization("requires Action1", Action1Servlet.class,
|
||||
// true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void twoRequirementsFailOne() {
|
||||
// createPolicy(new Action1());
|
||||
// assertExpectedAuthorization("requires Actions 1 and 2",
|
||||
// Action1AndAction2Servlet.class, false);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void twoRequirementsFailTwo() {
|
||||
// createPolicy(new Action2());
|
||||
// assertExpectedAuthorization("requires Actions 1 and 2",
|
||||
// Action1AndAction2Servlet.class, false);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void twoRequirementsSucceed() {
|
||||
// createPolicy(new Action2(), new Action1());
|
||||
// assertExpectedAuthorization("requires Actions 1 and 2",
|
||||
// Action1AndAction2Servlet.class, true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneOrTwoFail() {
|
||||
// createPolicy();
|
||||
// assertExpectedAuthorization("requires Action 1 or 2",
|
||||
// Action1OrAction2Servlet.class, false);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneOrTwoSucceedOne() {
|
||||
// createPolicy(new Action1());
|
||||
// assertExpectedAuthorization("requires Action 1 or 2",
|
||||
// Action1OrAction2Servlet.class, true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneOrTwoSucceedTwo() {
|
||||
// createPolicy(new Action2());
|
||||
// assertExpectedAuthorization("requires Action 1 or 2",
|
||||
// Action1OrAction2Servlet.class, true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneOrTwoOrThreeFail() {
|
||||
// createPolicy();
|
||||
// assertExpectedAuthorization("requires Action 1 or 2 or 3",
|
||||
// Action1OrAction2OrAction3Servlet.class, false);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneOrTwoOrThreeSucceedOne() {
|
||||
// createPolicy(new Action1());
|
||||
// assertExpectedAuthorization("requires Action 1 or 2 or 3",
|
||||
// Action1OrAction2OrAction3Servlet.class, true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneOrTwoOrThreeSucceedTwo() {
|
||||
// createPolicy(new Action2());
|
||||
// assertExpectedAuthorization("requires Action 1 or 2 or 3",
|
||||
// Action1OrAction2OrAction3Servlet.class, true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void oneOrTwoOrThreeSucceedThree() {
|
||||
// createPolicy(new Action3());
|
||||
// assertExpectedAuthorization("requires Action 1 or 2 or 3",
|
||||
// Action1OrAction2OrAction3Servlet.class, true);
|
||||
// }
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -223,12 +101,6 @@ public class PolicyHelperTest extends AbstractTestClass {
|
|||
ServletPolicyList.addPolicy(ctx, new MySimplePolicy(authorizedActions));
|
||||
}
|
||||
|
||||
// private void assertExpectedAuthorization(String label,
|
||||
// Class<? extends VitroHttpServlet> servletClass, boolean expected) {
|
||||
// boolean actual = PolicyHelper.isAuthorizedForServlet(req, servletClass);
|
||||
// assertEquals(label, expected, actual);
|
||||
// }
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Helper Classes
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -245,38 +117,6 @@ public class PolicyHelperTest extends AbstractTestClass {
|
|||
// actions must be public, with public constructor
|
||||
}
|
||||
|
||||
// no annotation
|
||||
private static class NoAnnotationServlet extends VitroHttpServlet {
|
||||
/* no body */
|
||||
}
|
||||
|
||||
@RequiresAuthorizationFor
|
||||
private static class NoRequirementsServlet extends VitroHttpServlet {
|
||||
/* no body */
|
||||
}
|
||||
|
||||
@RequiresAuthorizationFor(Action1.class)
|
||||
private static class Action1Servlet extends VitroHttpServlet {
|
||||
/* no body */
|
||||
}
|
||||
|
||||
@RequiresAuthorizationFor({ Action1.class, Action2.class })
|
||||
private static class Action1AndAction2Servlet extends VitroHttpServlet {
|
||||
/* no body */
|
||||
}
|
||||
|
||||
@RequiresAuthorizationFor(value = Action1.class, or = @Or(Action2.class))
|
||||
private static class Action1OrAction2Servlet extends VitroHttpServlet {
|
||||
/* no body */
|
||||
}
|
||||
|
||||
@RequiresAuthorizationFor(value = Action1.class, or = { @Or(Action2.class),
|
||||
@Or(Action3.class) })
|
||||
private static class Action1OrAction2OrAction3Servlet extends
|
||||
VitroHttpServlet {
|
||||
/* no body */
|
||||
}
|
||||
|
||||
private static class MySimplePolicy implements PolicyIface {
|
||||
private final Set<RequestedAction> authorizedActions;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue