Search in sources :

Example 21 with WikiPrincipal

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

the class GroupTest method testEquals4.

@Test
public void testEquals4() {
    Group group1 = new Group("BlibBlab", m_wiki);
    Principal u1 = new WikiPrincipal("Alice");
    Principal u2 = new WikiPrincipal("Bob");
    group1.add(u1);
    group1.add(u2);
    Group group2 = new Group("Blib", m_wiki);
    Principal u3 = new WikiPrincipal("Alice");
    Principal u4 = new WikiPrincipal("Bob");
    group2.add(u3);
    group2.add(u4);
    Assert.assertFalse(m_group.equals(group2));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 22 with WikiPrincipal

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

the class CookieAssertionLoginModuleTest method testLogout.

public final void testLogout() {
    MockHttpServletRequest request = m_engine.newHttpRequest();
    Cookie cookie = new Cookie(CookieAssertionLoginModule.PREFS_COOKIE_NAME, "Bullwinkle");
    request.setCookies(new Cookie[] { cookie });
    try {
        CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
        LoginModule module = new CookieAssertionLoginModule();
        module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
        module.login();
        module.commit();
        Set<Principal> principals = m_subject.getPrincipals();
        Assert.assertEquals(1, principals.size());
        Assert.assertTrue(principals.contains(new WikiPrincipal("Bullwinkle")));
        Assert.assertFalse(principals.contains(Role.ANONYMOUS));
        Assert.assertFalse(principals.contains(Role.ALL));
        module.logout();
        Assert.assertEquals(0, principals.size());
    } catch (LoginException e) {
        System.err.println(e.getMessage());
        Assert.assertTrue(false);
    }
}
Also used : Cookie(javax.servlet.http.Cookie) CallbackHandler(javax.security.auth.callback.CallbackHandler) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 23 with WikiPrincipal

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

the class UserDatabaseLoginModuleTest method testLogout.

public final void testLogout() {
    try {
        CallbackHandler handler = new WikiCallbackHandler(m_engine, null, "user", "password");
        LoginModule module = new UserDatabaseLoginModule();
        module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
        module.login();
        module.commit();
        Set<Principal> principals = m_subject.getPrincipals();
        Assert.assertEquals(1, principals.size());
        Assert.assertTrue(principals.contains(new WikiPrincipal("user", WikiPrincipal.LOGIN_NAME)));
        Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
        Assert.assertFalse(principals.contains(Role.ALL));
        module.logout();
        Assert.assertEquals(0, principals.size());
    } catch (LoginException e) {
        System.err.println(e.getMessage());
        Assert.assertTrue(false);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 24 with WikiPrincipal

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

the class UserDatabaseLoginModuleTest method testLogin.

public final void testLogin() {
    try {
        // Log in with a user that isn't in the database
        CallbackHandler handler = new WikiCallbackHandler(m_engine, null, "user", "password");
        LoginModule module = new UserDatabaseLoginModule();
        module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
        module.login();
        module.commit();
        Set<Principal> principals = m_subject.getPrincipals();
        Assert.assertEquals(1, principals.size());
        Assert.assertTrue(principals.contains(new WikiPrincipal("user", WikiPrincipal.LOGIN_NAME)));
        Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
        Assert.assertFalse(principals.contains(Role.ALL));
        // Login with a user that IS in the database
        m_subject = new Subject();
        handler = new WikiCallbackHandler(m_engine, null, "janne", "myP@5sw0rd");
        module = new UserDatabaseLoginModule();
        module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
        module.login();
        module.commit();
        principals = m_subject.getPrincipals();
        Assert.assertEquals(1, principals.size());
        Assert.assertTrue(principals.contains(new WikiPrincipal("janne", WikiPrincipal.LOGIN_NAME)));
        Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
        Assert.assertFalse(principals.contains(Role.ALL));
    } catch (LoginException e) {
        System.err.println(e.getMessage());
        Assert.assertTrue(false);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Subject(javax.security.auth.Subject)

Example 25 with WikiPrincipal

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

the class ApprovalWorkflowTest method testBuildApprovalWorkflowDeny.

@Test
public void testBuildApprovalWorkflowDeny() 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());
    // Start the workflow
    w.start();
    // Now, deny the Decision and the submitter should see a notification
    Step step = w.getCurrentStep();
    Assert.assertTrue(step instanceof Decision);
    Decision decision = (Decision) step;
    decision.decide(Outcome.DECISION_DENY);
    Assert.assertFalse(w.isCompleted());
    // Check that the notification is ok, then acknowledge it
    step = w.getCurrentStep();
    Assert.assertTrue(step instanceof SimpleNotification);
    Assert.assertEquals(rejectedMessageKey, step.getMessageKey());
    SimpleNotification notification = (SimpleNotification) step;
    notification.acknowledge();
    // Workflow should be complete now
    Assert.assertTrue(w.isCompleted());
    Assert.assertNull(w.getCurrentStep());
    Assert.assertEquals(3, w.getHistory().size());
    Assert.assertEquals(notification, w.getHistory().get(2));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) 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