use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testInheritedPermissions.
@Test
public void testInheritedPermissions() throws Exception {
// Create test page & attachment
final String src = "[{ALLOW edit Alice}] ";
m_engine.saveText("Test", src);
final File f = m_engine.makeAttachmentFile();
final Attachment att = Wiki.contents().attachment(m_engine, "Test", "test1.txt");
att.setAuthor("FirstPost");
m_engine.getManager(AttachmentManager.class).storeAttachment(att, f);
final Attachment p = (Attachment) m_engine.getManager(PageManager.class).getPage("Test/test1.txt");
final Permission view = PermissionFactory.getPagePermission(p, "view");
final Permission edit = PermissionFactory.getPagePermission(p, "edit");
// Create authenticated session with user 'Alice', who can read & edit (in ACL)
Session session = WikiSessionTest.authenticatedSession(m_engine, Users.ALICE, Users.ALICE_PASS);
Assertions.assertTrue(m_auth.checkPermission(session, view), "Alice view Test/test1.txt");
Assertions.assertTrue(m_auth.checkPermission(session, edit), "Alice view Test/test1.txt");
// Create authenticated session with user 'Bob', who can't read or edit (not in ACL)
session = WikiSessionTest.authenticatedSession(m_engine, Users.BOB, Users.BOB_PASS);
Assertions.assertFalse(m_auth.checkPermission(session, view), "Bob !view Test/test1.txt");
Assertions.assertFalse(m_auth.checkPermission(session, edit), "Bob !view Test/test1.txt");
// Delete test page & attachment
m_engine.getManager(AttachmentManager.class).deleteAttachment(att);
m_engine.getManager(PageManager.class).deletePage("Test");
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testPrincipalAcl.
@Test
public void testPrincipalAcl() throws Exception {
// Create test page & attachment
final String src = "[{ALLOW edit Alice}] ";
m_engine.saveText("Test", src);
final Page p = m_engine.getManager(PageManager.class).getPage("Test");
final Permission view = PermissionFactory.getPagePermission(p, "view");
final Permission edit = PermissionFactory.getPagePermission(p, "edit");
// Create session with authenticated user 'Alice', who can read & edit (in ACL)
Session session = WikiSessionTest.authenticatedSession(m_engine, Users.ALICE, Users.ALICE_PASS);
Assertions.assertTrue(m_auth.checkPermission(session, view), "Alice view Test");
Assertions.assertTrue(m_auth.checkPermission(session, edit), "Alice edit Test");
// Create session with authenticated user 'Bob', who can't read or edit (not in ACL)
session = WikiSessionTest.authenticatedSession(m_engine, Users.BOB, Users.BOB_PASS);
Assertions.assertFalse(m_auth.checkPermission(session, view), "Bob !view Test");
Assertions.assertFalse(m_auth.checkPermission(session, edit), "Bob !edit Test");
// Cleanup
try {
m_engine.getManager(PageManager.class).deletePage("Test");
} catch (final ProviderException e) {
Assertions.fail("Could not delete page");
}
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testAuthenticatedSession.
@Test
public void testAuthenticatedSession() throws Exception {
// Create Alice and her roles
final Principal alice = new WikiPrincipal(Users.ALICE);
final Role it = new Role("IT");
final Role engineering = new Role("Engineering");
final Role finance = new Role("Finance");
final Principal admin = new GroupPrincipal("Admin");
final Session session = WikiSessionTest.containerAuthenticatedSession(m_engine, Users.ALICE, new Principal[] { it, engineering, admin });
// Create two groups: Alice should be part of group Bar, but not Foo
final Group fooGroup = m_groupMgr.parseGroup("Foo", "", true);
final Group barGroup = m_groupMgr.parseGroup("Bar", "", true);
barGroup.add(alice);
m_groupMgr.setGroup(m_session, fooGroup);
m_groupMgr.setGroup(m_session, barGroup);
// Test user principal posession: user principals of different
// types should still be "the same" if their names are equal
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, new WikiPrincipal(Users.ALICE)), "Alice has Alice");
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, new TestPrincipal(Users.ALICE)), "Alice has Alice");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, new WikiPrincipal(Users.BOB)), "Alice not has Bob");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, new TestPrincipal(Users.BOB)), "Alice not has Bob");
// Built-in role membership
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, Role.ALL), "Alice in ALL");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, Role.ANONYMOUS), "Alice not in ANONYMOUS");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, Role.ASSERTED), "Alice not in ASSERTED");
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, Role.AUTHENTICATED), "Alice in AUTHENTICATED");
// Custom roles
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, it), "Alice in IT");
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, engineering), "Alice in Engineering");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, finance), "Alice not in Finance");
// Group memberships
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, fooGroup.getPrincipal()), "Alice not in Foo");
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, barGroup.getPrincipal()), "Alice in Bar");
// Cleanup
m_groupMgr.removeGroup("Foo");
m_groupMgr.removeGroup("Bar");
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testAdminView.
@Test
public void testAdminView() throws Exception {
m_engine.saveText("TestDefaultPage", "Foo [{ALLOW view FooBar}]");
final Principal admin = new GroupPrincipal("Admin");
final Session session = WikiSessionTest.containerAuthenticatedSession(m_engine, Users.ALICE, new Principal[] { admin });
Assertions.assertTrue(m_auth.checkPermission(session, new AllPermission(m_engine.getApplicationName())), "Alice has AllPermission");
Assertions.assertTrue(m_auth.checkPermission(session, new PagePermission("TestDefaultPage", "view")), "Alice cannot read");
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testInheritedAclPermissions.
@Test
public void testInheritedAclPermissions() throws Exception {
// Create test page & attachment
final String src = "[{ALLOW view Alice}] ";
m_engine.saveText("Test", src);
final File f = m_engine.makeAttachmentFile();
final Attachment att = Wiki.contents().attachment(m_engine, "Test", "test1.txt");
att.setAuthor("FirstPost");
m_engine.getManager(AttachmentManager.class).storeAttachment(att, f);
final Attachment p = (Attachment) m_engine.getManager(PageManager.class).getPage("Test/test1.txt");
final Permission view = PermissionFactory.getPagePermission(p, "view");
final Permission edit = PermissionFactory.getPagePermission(p, "edit");
// Create session with user 'Alice', who can read (in ACL)
Session session = WikiSessionTest.authenticatedSession(m_engine, Users.ALICE, Users.ALICE_PASS);
Assertions.assertTrue(m_auth.checkPermission(session, view), "Foo view Test");
Assertions.assertFalse(m_auth.checkPermission(session, edit), "Foo !edit Test");
// Create session with user 'Bob', who can't read or edit (not in ACL)
session = WikiSessionTest.authenticatedSession(m_engine, Users.BOB, Users.BOB_PASS);
Assertions.assertFalse(m_auth.checkPermission(session, view), "Bar !view Test");
Assertions.assertFalse(m_auth.checkPermission(session, view), "Bar !edit Test");
// Delete test page & attachment
m_engine.getManager(AttachmentManager.class).deleteAttachment(att);
m_engine.getManager(PageManager.class).deletePage("Test");
}
Aggregations