Search in sources :

Example 16 with WikiPrincipal

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

the class AclImplTest method testBob.

@Test
public void testBob() {
    // Bob should be able to view, edit, and comment but not delete
    Principal wup = new WikiPrincipal("Bob");
    Assert.assertTrue("view", inArray(m_acl.findPrincipals(PagePermission.VIEW), wup));
    Assert.assertTrue("edit", inArray(m_acl.findPrincipals(PagePermission.EDIT), wup));
    Assert.assertTrue("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 17 with WikiPrincipal

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

the class DefaultAclManagerTest method testPrintAcl.

@Test
public void testPrintAcl() {
    // Verify that the printed Acl for the test page is OK
    WikiPage page = m_engine.getPage("TestAclPage");
    Acl acl = m_engine.getAclManager().getPermissions(page);
    String aclString = DefaultAclManager.printAcl(acl);
    Assert.assertEquals("[{ALLOW edit Charlie,Herman}]\n", aclString);
    // Create an ACL from scratch
    acl = new AclImpl();
    AclEntry entry = new AclEntryImpl();
    entry.setPrincipal(new WikiPrincipal("Charlie"));
    entry.addPermission(PermissionFactory.getPagePermission("Main:Foo", "view"));
    entry.addPermission(PermissionFactory.getPagePermission("Main:Foo", "edit"));
    acl.addEntry(entry);
    entry = new AclEntryImpl();
    entry.setPrincipal(new WikiPrincipal("Devin"));
    entry.addPermission(PermissionFactory.getPagePermission("Main:Foo", "edit"));
    entry.addPermission(PermissionFactory.getPagePermission("Main:Foo", "delete"));
    acl.addEntry(entry);
    // Verify that the printed ACL is OK
    String expectedValue = "[{ALLOW delete Devin}]\n[{ALLOW edit Charlie,Devin}]\n[{ALLOW view Charlie}]\n";
    Assert.assertEquals(expectedValue, DefaultAclManager.printAcl(acl));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 18 with WikiPrincipal

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

the class GroupTest method testEquals2.

@Test
public void testEquals2() {
    Principal u1 = new WikiPrincipal("Alice");
    Principal u2 = new WikiPrincipal("Bob");
    m_group.add(u1);
    m_group.add(u2);
    Group group2 = new Group("Group2", m_wiki);
    Principal u3 = new WikiPrincipal("Alice");
    Principal u4 = new WikiPrincipal("Charlie");
    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 19 with WikiPrincipal

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

the class GroupTest method testEquals1.

@Test
public void testEquals1() {
    Principal u1 = new WikiPrincipal("Alice");
    Principal u2 = new WikiPrincipal("Bob");
    m_group.add(u1);
    m_group.add(u2);
    Group group2 = new Group("TestGroup", m_wiki);
    Principal u3 = new WikiPrincipal("Alice");
    Principal u4 = new WikiPrincipal("Bob");
    group2.add(u3);
    group2.add(u4);
    Assert.assertTrue(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 20 with WikiPrincipal

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

the class GroupTest method testEquals3.

@Test
public void testEquals3() {
    Group group1 = new Group("Blib", 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.assertTrue(group1.equals(group2));
}
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