Search in sources :

Example 1 with WikiServletFilter

use of org.apache.wiki.ui.WikiServletFilter in project jspwiki by apache.

the class WikiSessionTest method runSecurityFilter.

/**
 * "Scaffolding" method that runs the session security filter on a mock request. We do this by creating a
 * complete mock servlet context and filter chain, and running the request through it.
 *
 * @param engine the wiki engine
 * @param request the mock request to pass itnto the
 * @throws ServletException error building servlet context or running the request through it
 * @throws IOException error building servlet context or running the request through it
 */
private static void runSecurityFilter(final WikiEngine engine, final HttpServletRequest request) throws ServletException, IOException {
    // Create a mock servlet context and stash the wiki engine in it
    final ServletContext servletCtx = new MockServletContext("JSPWiki");
    servletCtx.setAttribute("org.apache.wiki.WikiEngine", engine);
    // Create a mock filter configuration and add the servlet context we just created
    final MockFilterConfig filterConfig = new MockFilterConfig();
    filterConfig.setFilterName("WikiServletFilter");
    filterConfig.setServletContext(servletCtx);
    // Create the security filter and run the request  through it
    final Filter filter = new WikiServletFilter();
    final MockFilterChain chain = new MockFilterChain();
    chain.addFilter(filter);
    final Servlet servlet = new MockServlet();
    chain.setServlet(servlet);
    filter.init(filterConfig);
    filter.doFilter(request, null, chain);
}
Also used : Filter(javax.servlet.Filter) WikiServletFilter(org.apache.wiki.ui.WikiServletFilter) MockServletContext(net.sourceforge.stripes.mock.MockServletContext) ServletContext(javax.servlet.ServletContext) WikiServletFilter(org.apache.wiki.ui.WikiServletFilter) Servlet(javax.servlet.Servlet) MockFilterChain(net.sourceforge.stripes.mock.MockFilterChain) MockServletContext(net.sourceforge.stripes.mock.MockServletContext) MockFilterConfig(net.sourceforge.stripes.mock.MockFilterConfig)

Aggregations

Filter (javax.servlet.Filter)1 Servlet (javax.servlet.Servlet)1 ServletContext (javax.servlet.ServletContext)1 MockFilterChain (net.sourceforge.stripes.mock.MockFilterChain)1 MockFilterConfig (net.sourceforge.stripes.mock.MockFilterConfig)1 MockServletContext (net.sourceforge.stripes.mock.MockServletContext)1 WikiServletFilter (org.apache.wiki.ui.WikiServletFilter)1