use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthenticationManagerTest method testLoginCustomWithGroup.
@Test
public void testLoginCustomWithGroup() throws Exception {
// Flush any pre-existing groups (left over from previous Assertions.failures, perhaps)
try {
m_groupMgr.removeGroup("Test1");
m_groupMgr.removeGroup("Test2");
} catch (final NoSuchPrincipalException e) {
}
// Log in 'janne' and verify there are 5 principals in the subject
// (ALL, AUTHENTICATED, login, fullname, wikiname Principals)
final Session session = WikiSession.guestSession(m_engine);
m_auth.login(session, null, Users.JANNE, Users.JANNE_PASS);
Assertions.assertEquals(3, session.getPrincipals().length);
Assertions.assertEquals(2, session.getRoles().length);
Assertions.assertTrue(session.hasPrincipal(new WikiPrincipal("JanneJalkanen", WikiPrincipal.WIKI_NAME)));
// Listen for any manager group-add events
final GroupManager manager = m_engine.getManager(GroupManager.class);
final SecurityEventTrap trap = new SecurityEventTrap();
manager.addWikiEventListener(trap);
// Create two groups; one with Janne in it, and one without
Group groupTest1 = m_groupMgr.parseGroup("Test1", "JanneJalkanen \n Bob \n Charlie", true);
m_groupMgr.setGroup(m_session, groupTest1);
groupTest1 = m_groupMgr.getGroup("Test1");
final Principal principalTest1 = groupTest1.getPrincipal();
Group groupTest2 = m_groupMgr.parseGroup("Test2", "Alice \n Bob \n Charlie", true);
m_groupMgr.setGroup(m_session, groupTest2);
groupTest2 = m_groupMgr.getGroup("Test2");
final Principal principalTest2 = groupTest2.getPrincipal();
// We should see two security events (one for each group create)
// We should also see a GroupPrincipal for group Test1, but not Test2
Assertions.assertEquals(2, trap.events().length);
Assertions.assertTrue(session.hasPrincipal(principalTest1));
Assertions.assertFalse(session.hasPrincipal(principalTest2));
// If we remove Test1, the GroupPrincipal should disappear
m_groupMgr.removeGroup("Test1");
Assertions.assertFalse(session.hasPrincipal(principalTest1));
Assertions.assertFalse(session.hasPrincipal(principalTest2));
// Now, add 'JanneJalkanen' to Test2 group manually; we should see the
// GroupPrincipal
groupTest2.add(new WikiPrincipal("JanneJalkanen"));
m_groupMgr.setGroup(session, groupTest2);
Assertions.assertFalse(session.hasPrincipal(principalTest1));
Assertions.assertTrue(session.hasPrincipal(principalTest2));
// Remove 'JanneJalkenen' manually; the GroupPrincipal should disappear
groupTest2.remove(new WikiPrincipal("JanneJalkanen"));
m_groupMgr.setGroup(session, groupTest2);
Assertions.assertFalse(session.hasPrincipal(principalTest1));
Assertions.assertFalse(session.hasPrincipal(principalTest2));
// Clean up
m_groupMgr.removeGroup("Test2");
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthenticationManagerTest method testLoginCustom.
@Test
public void testLoginCustom() throws Exception {
final Session session = WikiSessionTest.authenticatedSession(m_engine, Users.JANNE, Users.JANNE_PASS);
Assertions.assertTrue(session.hasPrincipal(Role.ALL));
Assertions.assertTrue(session.hasPrincipal(Role.AUTHENTICATED));
Assertions.assertTrue(session.hasPrincipal(new WikiPrincipal(Users.JANNE, WikiPrincipal.LOGIN_NAME)));
Assertions.assertTrue(session.hasPrincipal(new WikiPrincipal("JanneJalkanen", WikiPrincipal.WIKI_NAME)));
Assertions.assertTrue(session.hasPrincipal(new WikiPrincipal("Janne Jalkanen", WikiPrincipal.FULL_NAME)));
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testUserPolicy.
@Test
public void testUserPolicy() throws Exception {
final Properties props = TestEngine.getTestProperties();
// Make sure we are using the default security policy file jspwiki.policy
props.put(AuthorizationManager.POLICY, "jspwiki-testUserPolicy.policy");
// Initialize the test engine
m_engine = new TestEngine(props);
m_auth = m_engine.getManager(AuthorizationManager.class);
m_groupMgr = m_engine.getManager(GroupManager.class);
m_session = WikiSessionTest.adminSession(m_engine);
Session s = WikiSessionTest.anonymousSession(m_engine);
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.VIEW), "Anonymous view");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.EDIT), "Anonymous edit");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.COMMENT), "Anonymous comment");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.MODIFY), "Anonymous modify");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.UPLOAD), "Anonymous upload");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.RENAME), "Anonymous rename");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.DELETE), "Anonymous delete");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PREFERENCES), "Anonymous prefs");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PROFILE), "Anonymous profile");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_PAGES), "Anonymous pages");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_GROUPS), "Anonymous groups");
s = WikiSessionTest.assertedSession(m_engine, "Jack Sparrow");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.VIEW), "Asserted view");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.EDIT), "Asserted edit");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.COMMENT), "Asserted comment");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.MODIFY), "Asserted modify");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.UPLOAD), "Asserted upload");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.RENAME), "Asserted rename");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.DELETE), "Asserted delete");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PREFERENCES), "Asserted prefs");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PROFILE), "Asserted profile");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_PAGES), "Asserted pages");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_GROUPS), "Asserted groups");
s = WikiSessionTest.authenticatedSession(m_engine, Users.BOB, Users.BOB_PASS);
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.VIEW), "Bob view");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.EDIT), "Bob edit");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.COMMENT), "Bob comment");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.MODIFY), "Bob modify");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.UPLOAD), "Bob upload");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.RENAME), "Bob rename");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.DELETE), "Bob delete");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PREFERENCES), "Bob prefs");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PROFILE), "Bob profile");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_PAGES), "Bob pages");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_GROUPS), "Bob groups");
s = WikiSessionTest.authenticatedSession(m_engine, Users.JANNE, Users.JANNE_PASS);
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.VIEW), "Janne view");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.EDIT), "Janne edit");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.COMMENT), "Janne comment");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.MODIFY), "Janne modify");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.UPLOAD), "Janne upload");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.RENAME), "Janne rename");
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.DELETE), "Janne delete");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PREFERENCES), "Janne prefs");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PROFILE), "Janne profile");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_PAGES), "Janne pages");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_GROUPS), "Janne groups");
s = WikiSessionTest.adminSession(m_engine);
Assertions.assertTrue(m_auth.checkStaticPermission(s, PagePermission.VIEW), "Admin view");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.EDIT), "Admin edit");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.COMMENT), "Admin comment");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.MODIFY), "Admin modify");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.UPLOAD), "Admin upload");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.RENAME), "Admin rename");
Assertions.assertFalse(m_auth.checkStaticPermission(s, PagePermission.DELETE), "Admin delete");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PREFERENCES), "Admin prefs");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.EDIT_PROFILE), "Admin profile");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_PAGES), "Admin pages");
Assertions.assertFalse(m_auth.checkStaticPermission(s, WikiPermission.CREATE_GROUPS), "Admin groups");
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testRoleAcl.
@Test
public void testRoleAcl() throws Exception {
// Create test page & attachment
final String src = "[{ALLOW edit Authenticated}] ";
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
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 asserted user 'Bob', who can't read or edit (not in ACL)
session = WikiSessionTest.assertedSession(m_engine, Users.BOB);
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(e.getMessage());
}
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testAssertedSession.
@Test
public void testAssertedSession() 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.assertedSession(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: Alice isn't considered to
// have the "Alice" principal because she's not authenticated
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, new WikiPrincipal(Users.ALICE)), "Alice has Alice");
Assertions.assertFalse(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 memberships
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, Role.ALL), "Alice in ALL");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, Role.ANONYMOUS), "Alice not in ANONYMOUS");
Assertions.assertTrue(m_auth.hasRoleOrPrincipal(session, Role.ASSERTED), "Alice in ASSERTED");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, Role.AUTHENTICATED), "Alice not in AUTHENTICATED");
// Custom roles should be FALSE because Alice is asserted
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, it), "Alice not in IT");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, engineering), "Alice not in Engineering");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, finance), "Alice not in Finance");
// Group memberships should be FALSE because Alice is asserted
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, fooGroup.getPrincipal()), "Alice not in Foo");
Assertions.assertFalse(m_auth.hasRoleOrPrincipal(session, barGroup.getPrincipal()), "Alice not in Bar");
// Clean up
m_groupMgr.removeGroup("Foo");
m_groupMgr.removeGroup("Bar");
}
Aggregations