use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthorizationManagerTest method testAdminView2.
@Test
public void testAdminView2() throws Exception {
m_engine.saveText("TestDefaultPage", "Foo [{ALLOW view FooBar}]");
final Session session = WikiSessionTest.adminSession(m_engine);
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 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
*/
@BeforeEach
public void setUp() throws Exception {
final Session m_session = WikiSessionTest.adminSession(engine);
m_acl = Wiki.acls().acl();
m_aclGroup = Wiki.acls().acl();
m_groups = new HashMap<>();
final Principal uAlice = new WikiPrincipal("Alice");
final Principal uBob = new WikiPrincipal("Bob");
final Principal uCharlie = new WikiPrincipal("Charlie");
final Principal uDave = new WikiPrincipal("Dave");
// Alice can view
final AclEntry ae = Wiki.acls().entry();
ae.addPermission(PagePermission.VIEW);
ae.setPrincipal(uAlice);
// Charlie can view
final AclEntry ae2 = Wiki.acls().entry();
ae2.addPermission(PagePermission.VIEW);
ae2.setPrincipal(uCharlie);
// Bob can view and edit (and by implication, comment)
final AclEntry ae3 = Wiki.acls().entry();
ae3.addPermission(PagePermission.VIEW);
ae3.addPermission(PagePermission.EDIT);
ae3.setPrincipal(uBob);
// Dave can view and comment
final AclEntry ae4 = Wiki.acls().entry();
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
final Group foo = m_groupMgr.parseGroup("FooGroup", "", true);
m_groupMgr.setGroup(m_session, foo);
foo.add(uAlice);
foo.add(uBob);
final AclEntry ag1 = Wiki.acls().entry();
ag1.setPrincipal(foo.getPrincipal());
ag1.addPermission(PagePermission.EDIT);
m_aclGroup.addEntry(ag1);
m_groups.put("FooGroup", foo);
// Bar group includes Bob and Charlie
final Group bar = m_groupMgr.parseGroup("BarGroup", "", true);
m_groupMgr.setGroup(m_session, bar);
bar.add(uBob);
bar.add(uCharlie);
final AclEntry ag2 = Wiki.acls().entry();
ag2.setPrincipal(bar.getPrincipal());
ag2.addPermission(PagePermission.VIEW);
m_aclGroup.addEntry(ag2);
m_groups.put("BarGroup", bar);
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class TestEngine method saveText.
/**
* Convenience method that saves a wiki page by constructing a fake WikiContext and HttpServletRequest. We always want to do this
* using a WikiContext whose subject contains Role.ADMIN. Note: the WikiPage author will have the default value of "Guest".
*
* @param pageName page name
* @param content page content
* @throws WikiException associated login operation or page save had some trouble
*/
public void saveText(final String pageName, final String content) throws WikiException {
// Build new request and associate our admin session
final MockHttpServletRequest request = newHttpRequest();
final Session wikiSession = SessionMonitor.getInstance(this).find(request.getSession());
this.getManager(AuthenticationManager.class).login(wikiSession, request, Users.ADMIN, Users.ADMIN_PASS);
// Create page and wiki context
final Page page = Wiki.contents().page(this, pageName);
final Context context = Wiki.context().create(this, request, page);
getManager(PageManager.class).saveText(context, content);
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class AuthenticationManagerTest method testCustomAuthorizer.
/**
* Tests a dummy WebAuthorizer that is guaranteed to return true for one role for each of the two <code>isInRole</code> methods.
*
* @throws Exception
*/
@Test
public void testCustomAuthorizer() throws Exception {
final Properties props = TestEngine.getTestProperties();
props.put(AuthorizationManager.PROP_AUTHORIZER, "org.apache.wiki.auth.AuthenticationManagerTest$DummyAuthorizer");
m_engine = new TestEngine(props);
// Start a session without any container roles: DummyAuthorizer should ALWAYS allow AuthorizerRole
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)));
Assertions.assertTrue(session.hasPrincipal(new Role("AuthorizerRole")));
Assertions.assertFalse(session.hasPrincipal(new Role("ContainerRole")));
Assertions.assertFalse(session.hasPrincipal(new Role("DummyRole")));
// Try again with a container-authenticated session: DummyAuthorizer should ALSO allow ContainerRole
session = WikiSessionTest.containerAuthenticatedSession(m_engine, Users.JANNE, new Principal[0]);
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)));
Assertions.assertTrue(session.hasPrincipal(new Role("AuthorizerRole")));
Assertions.assertTrue(session.hasPrincipal(new Role("ContainerRole")));
Assertions.assertFalse(session.hasPrincipal(new Role("DummyRole")));
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class WikiSessionTest method testRoles.
@Test
public void testRoles() throws Exception {
Session session;
Principal[] principals;
// Test roles for guest session
session = Wiki.session().guest(m_engine);
principals = session.getRoles();
Assertions.assertTrue(session.isAnonymous());
Assertions.assertFalse(session.isAuthenticated());
Assertions.assertTrue(ArrayUtils.contains(principals, Role.ALL));
Assertions.assertTrue(ArrayUtils.contains(principals, Role.ANONYMOUS));
Assertions.assertFalse(ArrayUtils.contains(principals, Role.ASSERTED));
Assertions.assertFalse(ArrayUtils.contains(principals, Role.AUTHENTICATED));
// Test roles for anonymous session
session = anonymousSession(m_engine);
principals = session.getRoles();
Assertions.assertTrue(session.isAnonymous());
Assertions.assertFalse(session.isAuthenticated());
Assertions.assertTrue(ArrayUtils.contains(principals, Role.ALL));
Assertions.assertTrue(ArrayUtils.contains(principals, Role.ANONYMOUS));
Assertions.assertFalse(ArrayUtils.contains(principals, Role.ASSERTED));
Assertions.assertFalse(ArrayUtils.contains(principals, Role.AUTHENTICATED));
// Test roles for authenticated session
session = authenticatedSession(m_engine, Users.JANNE, Users.JANNE_PASS);
principals = session.getRoles();
Assertions.assertFalse(session.isAnonymous());
Assertions.assertTrue(session.isAuthenticated());
Assertions.assertTrue(ArrayUtils.contains(principals, Role.ALL));
Assertions.assertFalse(ArrayUtils.contains(principals, Role.ANONYMOUS));
Assertions.assertFalse(ArrayUtils.contains(principals, Role.ASSERTED));
Assertions.assertTrue(ArrayUtils.contains(principals, Role.AUTHENTICATED));
// Test roles for admin session
session = adminSession(m_engine);
principals = session.getRoles();
Assertions.assertFalse(session.isAnonymous());
Assertions.assertTrue(session.isAuthenticated());
Assertions.assertTrue(ArrayUtils.contains(principals, Role.ALL));
Assertions.assertFalse(ArrayUtils.contains(principals, Role.ANONYMOUS));
Assertions.assertFalse(ArrayUtils.contains(principals, Role.ASSERTED));
Assertions.assertTrue(ArrayUtils.contains(principals, Role.AUTHENTICATED));
}
Aggregations