Search in sources :

Example 26 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class ApprovalWorkflowTest method testBuildApprovalWorkflow.

@Test
public void testBuildApprovalWorkflow() throws WikiException {
    Principal submitter = new WikiPrincipal("Submitter");
    String workflowApproverKey = "workflow.approvalWorkflow";
    Task prepTask = new TestPrepTask("task.preSaveWikiPage");
    String decisionKey = "decision.saveWikiPage";
    Fact[] facts = new Fact[3];
    facts[0] = new Fact("fact1", new Integer(1));
    facts[1] = new Fact("fact2", "A factual String");
    facts[2] = new Fact("fact3", Outcome.DECISION_ACKNOWLEDGE);
    Task completionTask = new TestPrepTask("task.saveWikiPage");
    String rejectedMessageKey = "notification.saveWikiPage.reject";
    Workflow w = m_builder.buildApprovalWorkflow(submitter, workflowApproverKey, prepTask, decisionKey, facts, completionTask, rejectedMessageKey);
    w.setWorkflowManager(m_engine.getWorkflowManager());
    // Check to see if the workflow built correctly
    Assert.assertFalse(w.isStarted() || w.isCompleted() || w.isAborted());
    Assert.assertNull(w.getCurrentStep());
    Assert.assertEquals("workflow.approvalWorkflow", w.getMessageKey());
    Assert.assertEquals(Workflow.CREATED, w.getCurrentState());
    Assert.assertEquals(new WikiPrincipal("Submitter"), w.getOwner());
    Assert.assertEquals(m_engine.getWorkflowManager(), w.getWorkflowManager());
    Assert.assertEquals(0, w.getHistory().size());
    // Our dummy "task complete" attributes should still be null
    Assert.assertNull(w.getAttribute("task.preSaveWikiPage"));
    Assert.assertNull(w.getAttribute("task.saveWikiPage"));
    // Start the workflow
    w.start();
    // Presave complete attribute should be set now, and current step should be Decision
    Step decision = w.getCurrentStep();
    Assert.assertTrue(decision instanceof Decision);
    Assert.assertEquals(2, w.getHistory().size());
    Assert.assertEquals(prepTask, w.getHistory().get(0));
    Assert.assertTrue(w.getHistory().get(1) instanceof Decision);
    Assert.assertNotNull(w.getAttribute("task.preSaveWikiPage"));
    Assert.assertEquals(new WikiPrincipal(Users.JANNE), decision.getActor());
    Assert.assertEquals(decisionKey, decision.getMessageKey());
    List decisionFacts = ((Decision) decision).getFacts();
    Assert.assertEquals(3, decisionFacts.size());
    Assert.assertEquals(facts[0], decisionFacts.get(0));
    Assert.assertEquals(facts[1], decisionFacts.get(1));
    Assert.assertEquals(facts[2], decisionFacts.get(2));
    // Check that our predecessor/successor relationships are ok
    Assert.assertEquals(decision, prepTask.getSuccessor(Outcome.STEP_COMPLETE));
    Assert.assertEquals(null, prepTask.getSuccessor(Outcome.STEP_ABORT));
    Assert.assertEquals(null, prepTask.getSuccessor(Outcome.STEP_CONTINUE));
    Assert.assertEquals(null, decision.getSuccessor(Outcome.DECISION_ACKNOWLEDGE));
    Assert.assertEquals(null, decision.getSuccessor(Outcome.DECISION_HOLD));
    Assert.assertEquals(null, decision.getSuccessor(Outcome.DECISION_REASSIGN));
    Assert.assertEquals(completionTask, decision.getSuccessor(Outcome.DECISION_APPROVE));
    // The "deny" notification should use the right key
    Step notification = decision.getSuccessor(Outcome.DECISION_DENY);
    Assert.assertNotNull(notification);
    Assert.assertEquals(rejectedMessageKey, notification.getMessageKey());
    Assert.assertTrue(notification instanceof SimpleNotification);
    // Now, approve the Decision and everything should complete
    ((Decision) decision).decide(Outcome.DECISION_APPROVE);
    Assert.assertTrue(w.isCompleted());
    Assert.assertNull(w.getCurrentStep());
    Assert.assertEquals(3, w.getHistory().size());
    Assert.assertEquals(completionTask, w.getHistory().get(2));
    Assert.assertTrue(completionTask.isCompleted());
    Assert.assertEquals(Outcome.STEP_COMPLETE, completionTask.getOutcome());
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) List(java.util.List) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 27 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class DecisionQueueTest method testDecisionWorkflow.

@Test
public void testDecisionWorkflow() throws WikiException {
    Principal janne = janneSession.getUserPrincipal();
    // Clean out the queue first
    m_queue.remove(d1);
    m_queue.remove(d2);
    m_queue.remove(d3);
    // Create a workflow with 3 steps, with a Decision for Janne in the middle
    w = new Workflow("workflow.key", new WikiPrincipal("Owner1"));
    w.setWorkflowManager(m_engine.getWorkflowManager());
    Step startTask = new TaskTest.NormalTask(w);
    Step endTask = new TaskTest.NormalTask(w);
    Decision decision = new SimpleDecision(w, "decision.Actor1Decision", janne);
    startTask.addSuccessor(Outcome.STEP_COMPLETE, decision);
    decision.addSuccessor(Outcome.DECISION_APPROVE, endTask);
    w.setFirstStep(startTask);
    // Start the workflow, and verify that the Decision is the current Step
    w.start();
    Assert.assertEquals(decision, w.getCurrentStep());
    // Verify that it's also in Janne's DecisionQueue
    Collection decisions = m_queue.getActorDecisions(janneSession);
    Assert.assertEquals(1, decisions.size());
    Decision d = (Decision) decisions.iterator().next();
    Assert.assertEquals(decision, d);
    // Make Decision, and verify that it's gone from the queue
    m_queue.decide(decision, Outcome.DECISION_APPROVE);
    decisions = m_queue.getActorDecisions(janneSession);
    Assert.assertEquals(0, decisions.size());
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Collection(java.util.Collection) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) Test(org.junit.Test)

Example 28 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class SimpleDecisionTest method testReassign.

@Test
public void testReassign() {
    m_decision.reassign(new WikiPrincipal("Actor2"));
    Assert.assertEquals(new WikiPrincipal("Actor2"), m_decision.getActor());
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Test(org.junit.Test)

Example 29 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class SimpleDecisionTest method testSuccessors.

@Test
public void testSuccessors() {
    // If the decision is approved, branch to another decision (d2)
    Step d2 = new SimpleDecision(m_workflow, "decision2.key", new WikiPrincipal("Actor1"));
    m_decision.addSuccessor(Outcome.DECISION_APPROVE, d2);
    // If the decision is denied, branch to another decision (d3)
    Step d3 = new SimpleDecision(m_workflow, "decision3.key", new WikiPrincipal("Actor1"));
    m_decision.addSuccessor(Outcome.DECISION_DENY, d3);
    Assert.assertEquals(d2, m_decision.getSuccessor(Outcome.DECISION_APPROVE));
    Assert.assertEquals(d3, m_decision.getSuccessor(Outcome.DECISION_DENY));
    // The other Outcomes should return null when looked up
    Assert.assertNull(m_decision.getSuccessor(Outcome.DECISION_HOLD));
    Assert.assertNull(m_decision.getSuccessor(Outcome.DECISION_REASSIGN));
    Assert.assertNull(m_decision.getSuccessor(Outcome.STEP_ABORT));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Test(org.junit.Test)

Example 30 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class WorkflowTest method testWorkflow.

@Test
public void testWorkflow() {
    // Make sure everything is set to their proper default values
    Assert.assertNull(w.getCurrentStep());
    Assert.assertNull(w.getCurrentActor());
    Assert.assertEquals(0, w.getHistory().size());
    Assert.assertEquals(Workflow.ID_NOT_SET, w.getId());
    Assert.assertNull(w.getWorkflowManager());
    Assert.assertEquals(new WikiPrincipal("Owner1"), w.getOwner());
    Assert.assertEquals(Workflow.CREATED, w.getCurrentState());
    Assert.assertEquals(Workflow.TIME_NOT_SET, w.getStartTime());
    Assert.assertEquals(Workflow.TIME_NOT_SET, w.getEndTime());
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Test(org.junit.Test)

Aggregations

WikiPrincipal (org.apache.wiki.auth.WikiPrincipal)60 Principal (java.security.Principal)41 Test (org.junit.Test)32 LoginException (javax.security.auth.login.LoginException)13 GroupPrincipal (org.apache.wiki.auth.GroupPrincipal)13 CallbackHandler (javax.security.auth.callback.CallbackHandler)8 LoginModule (javax.security.auth.spi.LoginModule)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)6 IOException (java.io.IOException)5 Callback (javax.security.auth.callback.Callback)5 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)5 WikiSessionTest (org.apache.wiki.WikiSessionTest)5 NoSuchPrincipalException (org.apache.wiki.auth.NoSuchPrincipalException)5 WikiSecurityException (org.apache.wiki.auth.WikiSecurityException)4 UserProfile (org.apache.wiki.auth.user.UserProfile)4 Before (org.junit.Before)4 Properties (java.util.Properties)3 Subject (javax.security.auth.Subject)3 FailedLoginException (javax.security.auth.login.FailedLoginException)3