Search in sources :

Example 1 with WikiPrincipal

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

the class DecisionQueueTest method setUp.

@Before
public void setUp() throws Exception {
    Properties props = TestEngine.getTestProperties();
    m_engine = new TestEngine(props);
    m_queue = m_engine.getWorkflowManager().getDecisionQueue();
    adminSession = m_engine.adminSession();
    janneSession = m_engine.janneSession();
    w = new Workflow("workflow.key", new WikiPrincipal("Owner1"));
    w.setWorkflowManager(m_engine.getWorkflowManager());
    d1 = new SimpleDecision(w, "decision1.key", new GroupPrincipal("Admin"));
    d2 = new SimpleDecision(w, "decision2.key", new WikiPrincipal("Owner2"));
    d3 = new SimpleDecision(w, "decision3.key", janneSession.getUserPrincipal());
    m_queue.add(d1);
    m_queue.add(d2);
    m_queue.add(d3);
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) Before(org.junit.Before)

Example 2 with WikiPrincipal

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

the class DecisionQueueTest method testReassign.

@Test
public void testReassign() throws WikiException {
    // Janne owns 1 decision (d3)
    Assert.assertEquals(janneSession.getUserPrincipal(), d3.getActor());
    Assert.assertEquals(1, m_queue.getActorDecisions(janneSession).size());
    // Reassign the decision
    m_queue.reassign(d3, new WikiPrincipal("NewOwner"));
    // d3 should have a different owner now, and it won't show up in
    // Janne's decision list
    Assert.assertEquals(new WikiPrincipal("NewOwner"), d3.getActor());
    Assert.assertEquals(0, m_queue.getActorDecisions(janneSession).size());
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Test(org.junit.Test)

Example 3 with WikiPrincipal

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

the class TaskTest method testGetActor.

@Test
public void testGetActor() {
    Assert.assertNotSame(new WikiPrincipal("Actor1"), m_task.getActor());
    Assert.assertEquals(SystemPrincipal.SYSTEM_USER, m_task.getActor());
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Test(org.junit.Test)

Example 4 with WikiPrincipal

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

the class TaskTest method testSuccessors.

@Test
public void testSuccessors() {
    // If task finishes normally, branch to a decision (d1)
    Step d1 = new SimpleDecision(m_workflow, "decision1.key", new WikiPrincipal("Actor1"));
    m_task.addSuccessor(Outcome.STEP_COMPLETE, d1);
    // If the task aborts, branch to an alternate decision (d2)
    Step d2 = new SimpleDecision(m_workflow, "decision2.key", new WikiPrincipal("Actor2"));
    m_task.addSuccessor(Outcome.STEP_ABORT, d2);
    Assert.assertEquals(d1, m_task.getSuccessor(Outcome.STEP_COMPLETE));
    Assert.assertEquals(d2, m_task.getSuccessor(Outcome.STEP_ABORT));
    // The other Outcomes should return null when looked up
    Assert.assertNull(m_task.getSuccessor(Outcome.DECISION_APPROVE));
    Assert.assertNull(m_task.getSuccessor(Outcome.DECISION_DENY));
    Assert.assertNull(m_task.getSuccessor(Outcome.DECISION_HOLD));
    Assert.assertNull(m_task.getSuccessor(Outcome.DECISION_REASSIGN));
    Assert.assertNull(m_task.getSuccessor(Outcome.STEP_CONTINUE));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Test(org.junit.Test)

Example 5 with WikiPrincipal

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

the class WorkflowManagerTest method testGetApprover.

@Test
public void testGetApprover() throws WikiException {
    // Test properties says workflow.saveWikiPage approver is GP Admin; workflow.foo is 'janne'
    Assert.assertEquals(new WikiPrincipal("janne", WikiPrincipal.LOGIN_NAME), wm.getApprover("workflow.foo"));
    Assert.assertEquals(new GroupPrincipal("Admin"), wm.getApprover("workflow.bar"));
    // 'saveWikiPage' workflow doesn't require approval, so we will need to catch an Exception
    try {
        Assert.assertEquals(new GroupPrincipal("Admin"), wm.getApprover("workflow.saveWikiPage"));
    } catch (WikiException e) {
        // Swallow
        return;
    }
    // We should never get here
    Assert.fail("Workflow.bar doesn't need approval!");
}
Also used : WikiException(org.apache.wiki.api.exceptions.WikiException) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) 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