/** @since servlet-api-3.0 */
    @Override
    public FilterRegistration.Dynamic addFilter(String filterName, String className) {
      if (isStarted()) throw new IllegalStateException();

      if (filterName == null || "".equals(filterName.trim()))
        throw new IllegalStateException("Missing filter name");

      if (!_enabled) throw new UnsupportedOperationException();

      final ServletHandler handler = ServletContextHandler.this.getServletHandler();
      FilterHolder holder = handler.getFilter(filterName);
      if (holder == null) {
        // new filter
        holder = handler.newFilterHolder(Source.JAVAX_API);
        holder.setName(filterName);
        holder.setClassName(className);
        handler.addFilter(holder);
        return holder.getRegistration();
      }
      if (holder.getClassName() == null && holder.getHeldClass() == null) {
        // preliminary filter registration completion
        holder.setClassName(className);
        return holder.getRegistration();
      } else return null; // existing filter
    }
Exemple #2
0
  /** Secure the web server with kerberos (AuthenticationFilter). */
  void setupSpnegoFilter(Builder b) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put("kerberos.principal", SecurityUtil.getServerPrincipal(b.spnegoPrincipal, b.host));
    params.put("kerberos.keytab", b.spnegoKeytab);
    params.put(AuthenticationFilter.AUTH_TYPE, "kerberos");
    FilterHolder holder = new FilterHolder();
    holder.setClassName(AuthenticationFilter.class.getName());
    holder.setInitParameters(params);

    ServletHandler handler = webAppContext.getServletHandler();
    handler.addFilterWithMapping(holder, "/*", FilterMapping.ALL);
  }