use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class WikiSessionTest method testAssertionCookie.
@Test
public void testAssertionCookie() throws ServletException, IOException {
final MockHttpServletRequest request;
final Session wikiSession;
// Adding the magic "assertion cookie" should set asserted status.
request = m_engine.newHttpRequest();
request.setUserPrincipal(null);
final String cookieName = CookieAssertionLoginModule.PREFS_COOKIE_NAME;
request.setCookies(new Cookie[] { new Cookie(cookieName, "FredFlintstone") });
runSecurityFilter(m_engine, request);
wikiSession = Wiki.session().find(m_engine, request);
Assertions.assertTrue(wikiSession.isAsserted());
Assertions.assertEquals("FredFlintstone", wikiSession.getUserPrincipal().getName());
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class WikiSessionTest method containerAuthenticatedSession.
public static Session containerAuthenticatedSession(final TestEngine engine, final String id, final Principal[] roles) throws Exception {
// Build container session
final MockHttpServletRequest request = engine.newHttpRequest();
final Set<String> r = new HashSet<>();
for (final Principal role : roles) {
r.add(role.getName());
}
request.setRoles(r);
request.setUserPrincipal(new WikiPrincipal(id));
// Log in
runSecurityFilter(engine, request);
// Make sure the user is actually authenticated
final Session session = Wiki.session().find(engine, request);
if (!session.isAuthenticated()) {
throw new IllegalStateException("Could not log in authenticated user '" + id + "'");
}
return session;
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class WikiSessionTest method anonymousSession.
/**
* Creates an anonymous user session.
* @param engine the wiki engine
* @return the new session
* @throws Exception session not anonymous.
*/
public static Session anonymousSession(final TestEngine engine) throws Exception {
// Build anon session
final MockHttpServletRequest request = engine.newHttpRequest();
// Log in
runSecurityFilter(engine, request);
// Make sure the user is actually anonymous
final Session session = Wiki.session().find(engine, request);
if (!session.isAnonymous()) {
throw new IllegalStateException("Session is not anonymous.");
}
return session;
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class IfPluginTest method getJanneBasedWikiContextFor.
/**
* Returns a {@link WikiContext} for the given page, with user {@link Users#JANNE} logged in.
*
* @param page given {@link Page}.
* @return {@link WikiContext} associated to given {@link Page}.
* @throws WikiException problems while logging in.
*/
Context getJanneBasedWikiContextFor(final Page page) throws WikiException {
final MockHttpServletRequest request = testEngine.newHttpRequest();
final Session session = WikiSession.getWikiSession(testEngine, request);
testEngine.getManager(AuthenticationManager.class).login(session, request, Users.JANNE, Users.JANNE_PASS);
return Wiki.context().create(testEngine, request, page);
}
use of org.apache.wiki.api.core.Session in project jspwiki by apache.
the class DefaultRSSGenerator method generateFullWikiRSS.
/**
* {@inheritDoc}
*/
@Override
public String generateFullWikiRSS(final Context wikiContext, final Feed feed) {
feed.setChannelTitle(m_engine.getApplicationName());
feed.setFeedURL(m_engine.getBaseURL());
feed.setChannelLanguage(m_channelLanguage);
feed.setChannelDescription(m_channelDescription);
final Set<Page> changed = m_engine.getManager(PageManager.class).getRecentChanges();
final Session session = Wiki.session().guest(m_engine);
int items = 0;
for (final Iterator<Page> i = changed.iterator(); i.hasNext() && items < 15; items++) {
final Page page = i.next();
// Check if the anonymous user has view access to this page.
if (!m_engine.getManager(AuthorizationManager.class).checkPermission(session, new PagePermission(page, PagePermission.VIEW_ACTION))) {
// No permission, skip to the next one.
continue;
}
final String url;
if (page instanceof Attachment) {
url = m_engine.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), page.getName(), null);
} else {
url = m_engine.getURL(ContextEnum.PAGE_VIEW.getRequestContext(), page.getName(), null);
}
final Entry e = new Entry();
e.setPage(page);
e.setURL(url);
e.setTitle(page.getName());
e.setContent(getEntryDescription(page));
e.setAuthor(getAuthor(page));
feed.addEntry(e);
}
return feed.getString();
}
Aggregations