use of org.apache.jena.fuseki.servlets.FusekiFilter in project jena by apache.
the class ExFusekiMain_1_Servlet_AddFilter method addExtraFilter.
// Find the FusekiFilter and replace it with an indirection filter.
private static void addExtraFilter(FusekiServer server) {
Handler handler = server.getJettyServer().getHandler();
ServletContextHandler sch = (ServletContextHandler) handler;
ServletHandler servletHander = sch.getServletHandler();
FilterHolder[] fHolders = servletHander.getFilters();
for (int i = 0; i < fHolders.length; i++) {
FilterHolder fh = fHolders[i];
if (fh.getClassName().equals(FusekiFilter.class.getName())) {
FilterHolder fh2 = replacement(fh);
// ** Replacement.
fHolders[i] = fh2;
}
}
}
use of org.apache.jena.fuseki.servlets.FusekiFilter in project jena by apache.
the class ExFusekiMain_1_Servlet_AddFilter method replacement.
/**
* Build a replacement Filter
*/
private static FilterHolder replacement(FilterHolder fh) {
final Filter fx = (fh.getFilter() == null) ? new FusekiFilter() : fh.getFilter();
Filter filter2 = new Filter() {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Example: print the Principal
Principal user = ((HttpServletRequest) request).getUserPrincipal();
System.out.println("Request User: " + user);
fx.doFilter(request, response, chain);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
fx.init(filterConfig);
}
@Override
public void destroy() {
fx.destroy();
}
};
FilterHolder fh2 = new FilterHolder(filter2);
fh2.setClassName(filter2.getClass().getName());
fh2.setName(fh.getName());
// fh2.initialize();
return fh2;
}
Aggregations