@Override
  public Filter createFilter(FilterConfig filterConfig) {

    try {
      PluginServletFilter.removeFilter(filter);
      PluginServletFilter.addFilter(filter);

    } catch (ServletException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    return super.createFilter(filterConfig);
  }
  @DataBoundConstructor
  public WwpassSecurityRealm(String certFile, String keyFile, String name, boolean allowsSignup) {

    this.disableSignup = !allowsSignup;

    this.name = name;

    if (certFile != null && !certFile.isEmpty() && keyFile != null && !keyFile.isEmpty()) {
      this.certFile = certFile;
      this.keyFile = keyFile;
    } else {
      if (System.getProperty("os.name").startsWith("Windows")) {
        this.certFile = DEFAULT_CERT_FILE_WINDOWS;
        this.keyFile = DEFAULT_KEY_FILE_WINDOWS;
      } else if (System.getProperty("os.name").startsWith("Linux")) {
        this.certFile = DEFAULT_CERT_FILE_LINUX;
        this.keyFile = DEFAULT_KEY_FILE_LINUX;
      } else {
        LOGGER.severe(Messages.WwpassSession_UnsupportedOsError());
        throw new Failure(Messages.WwpassSession_AuthError());
      }
    }

    if (!hasSomeUser()) {
      // if Hudson is newly set up with the security realm and there's no user account created yet,
      // insert a filter that asks the user to create one
      try {
        PluginServletFilter.addFilter(CREATE_FIRST_USER_FILTER);
      } catch (ServletException e) {
        throw new AssertionError(e); // never happen because our Filter.init is no-op
      }
    }
  }
  @DataBoundConstructor
  public SSOKerberosSecurityRealm(
      String kdc, String realm, String krbConf, String user, String password, Boolean overwrite) {
    this.realm = realm;
    this.kdc = kdc;
    this.overwrite = overwrite;
    this.krbConf = krbConf;
    this.user = user;
    this.password = password;

    try {
      setUpKerberos();
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
    try {

      filter = new KerberosAuthenticationFilter(user, password, krbConf);
      PluginServletFilter.addFilter(filter);

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
          HttpServletRequest req = (HttpServletRequest) request;

          if (req.getRequestURI().equals(req.getContextPath() + "/")) {
            if (needsToCreateFirstUser()) {
              ((HttpServletResponse) response).sendRedirect("securityRealm/firstUser");
            } else { // the first user already created. the role of this filter is over.
              PluginServletFilter.removeFilter(this);
              chain.doFilter(request, response);
            }
          } else chain.doFilter(request, response);
        }
 @DataBoundConstructor
 public HudsonPrivateSecurityRealm(boolean allowsSignup, boolean enableCaptcha, CaptchaSupport captchaSupport) {
     this.disableSignup = !allowsSignup;
     this.enableCaptcha = enableCaptcha;
     setCaptchaSupport(captchaSupport);
     if(!allowsSignup && !hasSomeUser()) {
         // if Hudson is newly set up with the security realm and there's no user account created yet,
         // insert a filter that asks the user to create one
         try {
             PluginServletFilter.addFilter(CREATE_FIRST_USER_FILTER);
         } catch (ServletException e) {
             throw new AssertionError(e); // never happen because our Filter.init is no-op
         }
     }
 }