Search in sources :

Example 31 with WikiPrincipal

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

the class WorkflowTest method setUp.

@Before
public void setUp() throws Exception {
    // Create workflow; owner is test user
    w = new Workflow("workflow.myworkflow", new WikiPrincipal("Owner1"));
    // Create custom initialization task
    initTask = new TaskTest.NormalTask(w);
    // Create finish task
    finishTask = new TaskTest.NormalTask(w);
    // Create an intermetidate decision step
    Principal actor = new GroupPrincipal("Admin");
    decision = new SimpleDecision(w, "decision.AdminDecision", actor);
    // Hook the steps together
    initTask.addSuccessor(Outcome.STEP_COMPLETE, decision);
    decision.addSuccessor(Outcome.DECISION_APPROVE, finishTask);
    // Stash page name as message attribute
    w.addMessageArgument("MyPage");
    // Set workflow's first step
    w.setFirstStep(initTask);
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) Before(org.junit.Before)

Example 32 with WikiPrincipal

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

the class WikiSessionTest method containerAuthenticatedSession.

public static WikiSession containerAuthenticatedSession(TestEngine engine, String id, Principal[] roles) throws Exception {
    // Build container session
    MockHttpServletRequest request = engine.newHttpRequest();
    Set<String> r = new HashSet<String>();
    for (int i = 0; i < roles.length; i++) {
        r.add(roles[i].getName());
    }
    request.setRoles(r);
    request.setUserPrincipal(new WikiPrincipal(id));
    // Log in
    runSecurityFilter(engine, request);
    // Make sure the user is actually authenticated
    WikiSession session = WikiSession.getWikiSession(engine, request);
    if (!session.isAuthenticated()) {
        throw new IllegalStateException("Could not log in authenticated user '" + id + "'");
    }
    return session;
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) HashSet(java.util.HashSet)

Example 33 with WikiPrincipal

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

the class AclImplTest method testCharlie.

@Test
public void testCharlie() {
    // Charlie should be able to view, but not edit, comment or delete
    Principal wup = new WikiPrincipal("Charlie");
    Assert.assertTrue("view", inArray(m_acl.findPrincipals(PagePermission.VIEW), wup));
    Assert.assertFalse("edit", inArray(m_acl.findPrincipals(PagePermission.EDIT), wup));
    Assert.assertFalse("comment", inArray(m_acl.findPrincipals(PagePermission.COMMENT), wup));
    Assert.assertFalse("delete", inArray(m_acl.findPrincipals(PagePermission.DELETE), wup));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.Test)

Example 34 with WikiPrincipal

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

the class AclImplTest method setUp.

/**
 * We setup the following rules: Alice = may view Bob = may view, may edit
 * Charlie = may view Dave = may view, may comment groupAcl: FooGroup =
 * Alice, Bob - may edit BarGroup = Bob, Charlie - may view
 */
@Before
public void setUp() throws Exception {
    Properties props = TestEngine.getTestProperties();
    TestEngine engine = new TestEngine(props);
    m_groupMgr = engine.getGroupManager();
    m_session = WikiSessionTest.adminSession(engine);
    m_acl = new AclImpl();
    m_aclGroup = new AclImpl();
    m_groups = new HashMap<String, Group>();
    Principal uAlice = new WikiPrincipal("Alice");
    Principal uBob = new WikiPrincipal("Bob");
    Principal uCharlie = new WikiPrincipal("Charlie");
    Principal uDave = new WikiPrincipal("Dave");
    // Alice can view
    AclEntry ae = new AclEntryImpl();
    ae.addPermission(PagePermission.VIEW);
    ae.setPrincipal(uAlice);
    // Charlie can view
    AclEntry ae2 = new AclEntryImpl();
    ae2.addPermission(PagePermission.VIEW);
    ae2.setPrincipal(uCharlie);
    // Bob can view and edit (and by implication, comment)
    AclEntry ae3 = new AclEntryImpl();
    ae3.addPermission(PagePermission.VIEW);
    ae3.addPermission(PagePermission.EDIT);
    ae3.setPrincipal(uBob);
    // Dave can view and comment
    AclEntry ae4 = new AclEntryImpl();
    ae4.addPermission(PagePermission.VIEW);
    ae4.addPermission(PagePermission.COMMENT);
    ae4.setPrincipal(uDave);
    // Create ACL with Alice, Bob, Charlie, Dave
    m_acl.addEntry(ae);
    m_acl.addEntry(ae2);
    m_acl.addEntry(ae3);
    m_acl.addEntry(ae4);
    // Foo group includes Alice and Bob
    Group foo = m_groupMgr.parseGroup("FooGroup", "", true);
    m_groupMgr.setGroup(m_session, foo);
    foo.add(uAlice);
    foo.add(uBob);
    AclEntry ag1 = new AclEntryImpl();
    ag1.setPrincipal(foo.getPrincipal());
    ag1.addPermission(PagePermission.EDIT);
    m_aclGroup.addEntry(ag1);
    m_groups.put("FooGroup", foo);
    // Bar group includes Bob and Charlie
    Group bar = m_groupMgr.parseGroup("BarGroup", "", true);
    m_groupMgr.setGroup(m_session, bar);
    bar.add(uBob);
    bar.add(uCharlie);
    AclEntry ag2 = new AclEntryImpl();
    ag2.setPrincipal(bar.getPrincipal());
    ag2.addPermission(PagePermission.VIEW);
    m_aclGroup.addEntry(ag2);
    m_groups.put("BarGroup", bar);
}
Also used : Group(org.apache.wiki.auth.authorize.Group) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) Before(org.junit.Before)

Example 35 with WikiPrincipal

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

the class DefaultAclManagerTest method testGetPermissions.

@Test
public void testGetPermissions() {
    WikiPage page = m_engine.getPage("TestDefaultPage");
    Acl acl = m_engine.getAclManager().getPermissions(page);
    Assert.assertNotNull(page.getAcl());
    Assert.assertTrue(page.getAcl().isEmpty());
    page = m_engine.getPage("TestAclPage");
    acl = m_engine.getAclManager().getPermissions(page);
    Assert.assertNotNull(page.getAcl());
    Assert.assertFalse(page.getAcl().isEmpty());
    Principal[] p;
    // Charlie is an editor; reading is therefore implied
    p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "view"));
    Assert.assertEquals(2, p.length);
    Assert.assertTrue(ArrayUtils.contains(p, new WikiPrincipal("Charlie")));
    // Charlie should be in the ACL as an editor
    p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "edit"));
    Assert.assertEquals(2, p.length);
    Assert.assertTrue(ArrayUtils.contains(p, new WikiPrincipal("Charlie")));
    // Charlie should not be able to delete this page
    p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "delete"));
    Assert.assertEquals(0, p.length);
    // Herman is an unregistered user and editor; reading is implied
    p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "view"));
    Assert.assertEquals(2, p.length);
    Assert.assertTrue(ArrayUtils.contains(p, new UnresolvedPrincipal("Herman")));
    // Herman should be in the ACL as an editor
    p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "edit"));
    Assert.assertEquals(2, p.length);
    Assert.assertTrue(ArrayUtils.contains(p, new UnresolvedPrincipal("Herman")));
    // Herman should not be able to delete this page
    p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "delete"));
    Assert.assertEquals(0, p.length);
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPage(org.apache.wiki.WikiPage) 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