Search in sources :

Example 1 with FusekiFilter

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;
        }
    }
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FusekiFilter(org.apache.jena.fuseki.servlets.FusekiFilter) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 2 with FusekiFilter

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FusekiFilter(org.apache.jena.fuseki.servlets.FusekiFilter) FusekiFilter(org.apache.jena.fuseki.servlets.FusekiFilter) Principal(java.security.Principal)

Aggregations

FusekiFilter (org.apache.jena.fuseki.servlets.FusekiFilter)2 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)2 Principal (java.security.Principal)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)1 Handler (org.eclipse.jetty.server.Handler)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)1