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);
}
Aggregations