public void init(FilterConfig filterConfig) throws ServletException {
   super.init(filterConfig);
   resourceSearchPackage =
       filterConfig.getInitParameter(KatharsisProperties.RESOURCE_SEARCH_PACKAGE);
   resourceDefaultDomain =
       filterConfig.getInitParameter(KatharsisProperties.RESOURCE_DEFAULT_DOMAIN);
 }
  /**
   * Place this filter into service.
   *
   * @param filterConfig The filter configuration object
   */
  public void init(FilterConfig filterConfig) {

    config = filterConfig;
    if (filterConfig != null) {
      String value = filterConfig.getInitParameter("debug");
      if (value != null) {
        debug = Integer.parseInt(value);
      } else {
        debug = 0;
      }
      String str = filterConfig.getInitParameter("compressionThreshold");
      if (str != null) {
        compressionThreshold = Integer.parseInt(str);
        if (compressionThreshold != 0 && compressionThreshold < minThreshold) {
          if (debug > 0) {
            System.out.println(
                "compressionThreshold should be either 0 - no compression or >= " + minThreshold);
            System.out.println("compressionThreshold set to " + minThreshold);
          }
          compressionThreshold = minThreshold;
        }
      } else {
        compressionThreshold = 0;
      }

    } else {
      compressionThreshold = 0;
    }
  }
  /**
   * Initialize this filter.
   *
   * @param config <code>FilterConfig</code>
   */
  public void init(final FilterConfig config) {
    this.context = config.getServletContext();
    this.requireAttribute =
        Boolean.valueOf(config.getInitParameter(REQUIRE_ATTRIBUTE)).booleanValue();
    if (LOG.isDebugEnabled()) {
      LOG.debug("requireAttribute = " + this.requireAttribute);
    }

    final Enumeration<?> e = config.getInitParameterNames();
    while (e.hasMoreElements()) {
      final String name = (String) e.nextElement();
      if (!name.equals(REQUIRE_ATTRIBUTE)) {
        final String value = config.getInitParameter(name);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Loaded attribute name:value " + name + ":" + value);
        }

        final StringTokenizer st = new StringTokenizer(name);
        final String attrName = st.nextToken();
        final String attrValue = st.nextToken();

        this.attributes.put(attrName, Pattern.compile(attrValue));
        this.redirects.put(attrName, value);
        if (LOG.isDebugEnabled()) {
          LOG.debug(
              "Stored attribute "
                  + attrName
                  + " for pattern "
                  + attrValue
                  + " with redirect of "
                  + value);
        }
      }
    }
  }
Esempio n. 4
0
 /* (non-Javadoc)
  * @see esg.orp.app.PolicyServiceFilterCollaborator#init(javax.servlet.FilterConfig)
  */
 public void init(FilterConfig filterConfig) {
   String authRequiredPatternStr =
       filterConfig.getInitParameter(Parameters.AUTHENTICATION_REQUIRED_PATTERNS);
   String authNotRequiredPatternStr =
       filterConfig.getInitParameter(Parameters.AUTHENTICATION_NOT_REQUIRED_PATTERNS);
   if ((authRequiredPatternStr != null) && (authNotRequiredPatternStr != null)) {
     LOG.error(
         String.format(
             "Only one of the initialisation parameters %s and %s should be specified.",
             Parameters.AUTHENTICATION_REQUIRED_PATTERNS,
             Parameters.AUTHENTICATION_NOT_REQUIRED_PATTERNS));
   }
   String patternStr = null;
   // Find the pattern parameter - if both are specified, only act on the access denied patterns.
   if (authNotRequiredPatternStr != null) {
     patternStr = authNotRequiredPatternStr;
     matchResult = false;
   } else if (authRequiredPatternStr != null) {
     patternStr = authRequiredPatternStr;
     matchResult = true;
   }
   if (patternStr == null) {
     LOG.error(
         String.format(
             "One of the initialisation parameters %s and %s should be specified.",
             Parameters.AUTHENTICATION_REQUIRED_PATTERNS,
             Parameters.AUTHENTICATION_NOT_REQUIRED_PATTERNS));
     // Default to requiring authorization for all URLs.
     patternStr = "";
     matchResult = false;
   }
   patterns = parsePatternString(patternStr);
 }
Esempio n. 5
0
 public void init(FilterConfig filterConfig) throws ServletException {
   this.filterChar = filterConfig.getInitParameter("FilterChar");
   this.replaceChar = filterConfig.getInitParameter("ReplaceChar");
   this.splitChar = filterConfig.getInitParameter("SplitChar");
   this.excludeUrls = filterConfig.getInitParameter("excludeUrls");
   this.filterConfig = filterConfig;
 }
 public void init(FilterConfig filterConfig) throws ServletException {
   this.encoding = filterConfig.getInitParameter("encoding");
   String fe = filterConfig.getInitParameter("forceEncoding");
   if (StringUtils.isNotBlank(fe)) {
     this.forceEncoding = Boolean.parseBoolean(fe);
   }
 }
Esempio n. 7
0
  public void init(FilterConfig config) throws ServletException {
    this.config = config;

    String value = null;
    try {
      value = config.getInitParameter("debug");
      this.debug = Integer.parseInt(value);
    } catch (Throwable localThrowable) {
    }

    try {
      value = config.getInitParameter("expires");
      if (StringUtil.isEmpty(value)) {
        value = "0";
      }
      this.expires = Long.valueOf(value);
    } catch (NumberFormatException e) {
      this.expires = null;
      config
          .getServletContext()
          .log("Invalid format for expires initParam; expected integer (seconds)");
    } catch (Throwable localThrowable1) {
    }
    if (this.debug > 0)
      config
          .getServletContext()
          .log("SSIFilter.init() SSI invoker started with 'debug'=" + this.debug);
  }
  public void init(FilterConfig filterConfig) throws ServletException {
    boolean jetty_7_or_greater =
        "org.eclipse.jetty.servlet".equals(filterConfig.getClass().getPackage().getName());
    _context = filterConfig.getServletContext();

    String param = filterConfig.getInitParameter("debug");
    _debug = param != null && Boolean.parseBoolean(param);
    if (_debug) __debug = true;

    param = filterConfig.getInitParameter("jetty6");
    if (param == null) param = filterConfig.getInitParameter("partial");
    if (param != null) _jetty6 = Boolean.parseBoolean(param);
    else _jetty6 = ContinuationSupport.__jetty6 && !jetty_7_or_greater;

    param = filterConfig.getInitParameter("faux");
    if (param != null) _faux = Boolean.parseBoolean(param);
    else _faux = !(jetty_7_or_greater || _jetty6 || _context.getMajorVersion() >= 3);

    _filtered = _faux || _jetty6;
    if (_debug)
      _context.log(
          "ContinuationFilter "
              + " jetty="
              + jetty_7_or_greater
              + " jetty6="
              + _jetty6
              + " faux="
              + _faux
              + " filtered="
              + _filtered
              + " servlet3="
              + ContinuationSupport.__servlet3);
    _initialized = true;
  }
  @Override
  public void init(final FilterConfig filterConfig) {
    ikey = filterConfig.getInitParameter("ikey");
    skey = filterConfig.getInitParameter("skey");
    akey = filterConfig.getInitParameter("akey");
    host = filterConfig.getInitParameter("host");

    if (filterConfig.getInitParameter("login.url") != null) {
      loginUrl = filterConfig.getInitParameter("login.url");
    }
    // Init our unprotected endpoints
    unprotectedDirs = new ArrayList<String>(Arrays.asList(defaultUnprotectedDirs));

    if (filterConfig.getInitParameter("unprotected.dirs") != null) {
      String[] userSpecifiedUnprotectedDirs =
          filterConfig.getInitParameter("unprotected.dirs").split(" ");
      unprotectedDirs.addAll(Arrays.asList(userSpecifiedUnprotectedDirs));
    }

    if (filterConfig.getInitParameter("bypass.APIs") != null) {
      apiBypassEnabled = Boolean.parseBoolean(filterConfig.getInitParameter("bypass.APIs"));
    }

    if (filterConfig.getInitParameter("fail.Open") != null) {
      failOpen = Boolean.parseBoolean(filterConfig.getInitParameter("fail.Open"));
    }
  }
  /**
   * Place this filter into service.
   *
   * @param filterConfig The filter configuration object
   */
  public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    this.errorPage = filterConfig.getInitParameter("errorPage");

    String webFilter = filterConfig.getInitParameter("webfilter");
    if ((webFilter == null)
        || webFilter.equalsIgnoreCase("true")
        || webFilter.equalsIgnoreCase("yes")) {
      this.webfilter = true;
    } else {
      this.webfilter = false;
    }

    String sqlFilter = filterConfig.getInitParameter("sqlfilter");
    if ((sqlFilter == null)
        || sqlFilter.equalsIgnoreCase("true")
        || sqlFilter.equalsIgnoreCase("yes")) {
      this.sqlfilter = true;
    } else {
      this.sqlfilter = false;
    }

    String specialfilter = filterConfig.getInitParameter("specialfilter");
    if ((specialfilter == null)
        || specialfilter.equalsIgnoreCase("true")
        || specialfilter.equalsIgnoreCase("yes")) {
      this.specialfilter = true;
    } else {
      this.specialfilter = false;
    }
  }
Esempio n. 11
0
 /** @see javax.servlet.Filter#init(javax.servlet.FilterConfig) */
 public void init(FilterConfig filterConfig) throws ServletException {
   tempdir = (File) filterConfig.getServletContext().getAttribute("javax.servlet.context.tempdir");
   _deleteFiles = "true".equals(filterConfig.getInitParameter("deleteFiles"));
   String fileOutputBuffer = filterConfig.getInitParameter("fileOutputBuffer");
   if (fileOutputBuffer != null) _fileOutputBuffer = Integer.parseInt(fileOutputBuffer);
   _context = filterConfig.getServletContext();
 }
  public void testGetToken() throws Exception {
    AuthenticationFilter filter = new AuthenticationFilter();
    try {
      FilterConfig config = Mockito.mock(FilterConfig.class);
      Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TYPE))
          .thenReturn(DummyAuthenticationHandler.class.getName());
      Mockito.when(config.getInitParameter(AuthenticationFilter.SIGNATURE_SECRET))
          .thenReturn("secret");
      Mockito.when(config.getInitParameterNames())
          .thenReturn(
              new Vector(
                      Arrays.asList(
                          AuthenticationFilter.AUTH_TYPE, AuthenticationFilter.SIGNATURE_SECRET))
                  .elements());
      filter.init(config);

      AuthenticationToken token =
          new AuthenticationToken("u", "p", DummyAuthenticationHandler.TYPE);
      token.setExpires(System.currentTimeMillis() + 1000);
      Signer signer = new Signer("secret".getBytes());
      String tokenSigned = signer.sign(token.toString());

      Cookie cookie = new Cookie(AuthenticatedURL.AUTH_COOKIE, tokenSigned);
      HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
      Mockito.when(request.getCookies()).thenReturn(new Cookie[] {cookie});

      AuthenticationToken newToken = filter.getToken(request);

      assertEquals(token.toString(), newToken.toString());
    } finally {
      filter.destroy();
    }
  }
Esempio n. 13
0
 @Override
 public void init(FilterConfig filterConfig) throws ServletException {
   proxy = filterConfig.getInitParameter("proxy");
   String value = filterConfig.getInitParameter("redirects");
   if (StringUtils.isNotBlank(value)) {
     redirects = Boolean.parseBoolean(value);
   }
 }
Esempio n. 14
0
 /**
  * Set filter init params with proper values and check they are the same in {@link
  * WroConfiguration} object.
  */
 @Test(expected = WroRuntimeException.class)
 public void testFilterInitParamsAreWrong() throws Exception {
   Mockito.when(config.getInitParameter(ConfigConstants.cacheUpdatePeriod.name()))
       .thenReturn("InvalidNumber");
   Mockito.when(config.getInitParameter(ConfigConstants.modelUpdatePeriod.name()))
       .thenReturn("100");
   filter.init(config);
 }
Esempio n. 15
0
 @Test
 public void testDisableCacheInitParamInDeploymentMode() throws Exception {
   Mockito.when(config.getInitParameter(FilterConfigWroConfigurationFactory.PARAM_CONFIGURATION))
       .thenReturn(FilterConfigWroConfigurationFactory.PARAM_VALUE_DEPLOYMENT);
   Mockito.when(config.getInitParameter(ConfigConstants.disableCache.name())).thenReturn("true");
   filter.init(config);
   Assert.assertEquals(false, filter.getWroConfiguration().isDebug());
   Assert.assertEquals(false, filter.getWroConfiguration().isDisableCache());
 }
 public void init(FilterConfig filterConfig) throws ServletException {
   this.filterConfig = filterConfig;
   this.encoding = filterConfig.getInitParameter("encoding");
   String value = filterConfig.getInitParameter("ignore");
   if (value == null) this.ignore = false;
   else if (value.equalsIgnoreCase("false")) this.ignore = true;
   else if (value.equalsIgnoreCase("no")) this.ignore = true;
   else this.ignore = false;
 }
Esempio n. 17
0
 public void init(FilterConfig filterConfig) {
   String fromEncodingParameter = filterConfig.getInitParameter(FROM_ENCODING_PARAMETER_NAME);
   String toEncodingParameter = filterConfig.getInitParameter(TO_ENCODING_PARAMETER_NAME);
   if (fromEncodingParameter != null) {
     fromEncoding = fromEncodingParameter;
   }
   if (toEncodingParameter != null) {
     toEncoding = toEncodingParameter;
   }
 }
Esempio n. 18
0
 public void init(FilterConfig filterConfig) throws ServletException {
   if (StringUtils.isNotBlank(filterConfig.getInitParameter("exclude"))) {
     String ex[] = filterConfig.getInitParameter("exclude").trim().split(",");
     exclude = new String[ex.length];
     for (int i = 0; i < ex.length; i++) {
       exclude[i] = ex[i].trim();
     }
   }
   this.filterConfig = filterConfig;
 }
  /**
   * {@inheritDoc}
   *
   * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
   */
  @Override
  public void init(FilterConfig config) {
    if (config.getInitParameter("header_name") != null) {
      headerName = config.getInitParameter("header_name");
    }

    if (config.getInitParameter("mdc_key") != null) {
      mdcKey = config.getInitParameter("mdc_key");
    }
  }
 @Override
 public void init(FilterConfig arg0) throws ServletException {
   try {
     exceptionClass = Class.forName(arg0.getInitParameter("exceptionClassname"));
   } catch (ClassNotFoundException e) {
     throw new ServletException(e);
   }
   forwardPath = arg0.getInitParameter("forwardPath");
   ExceptionHandlerFilter.register(this);
 }
Esempio n. 21
0
  public void init(FilterConfig filterConfig) {
    int max_priority = __DEFAULT_MAX_PRIORITY;
    if (filterConfig.getInitParameter(MAX_PRIORITY_INIT_PARAM) != null)
      max_priority = Integer.parseInt(filterConfig.getInitParameter(MAX_PRIORITY_INIT_PARAM));
    _queues = new Queue[max_priority + 1];
    _listeners = new AsyncListener[_queues.length];
    for (int p = 0; p < _queues.length; ++p) {
      _queues[p] = new ConcurrentLinkedQueue<>();
      _listeners[p] = new QoSAsyncListener(p);
    }

    int maxRequests = __DEFAULT_PASSES;
    if (filterConfig.getInitParameter(MAX_REQUESTS_INIT_PARAM) != null)
      maxRequests = Integer.parseInt(filterConfig.getInitParameter(MAX_REQUESTS_INIT_PARAM));
    _passes = new Semaphore(maxRequests, true);
    _maxRequests = maxRequests;

    long wait = __DEFAULT_WAIT_MS;
    if (filterConfig.getInitParameter(MAX_WAIT_INIT_PARAM) != null)
      wait = Integer.parseInt(filterConfig.getInitParameter(MAX_WAIT_INIT_PARAM));
    _waitMs = wait;

    long suspend = __DEFAULT_TIMEOUT_MS;
    if (filterConfig.getInitParameter(SUSPEND_INIT_PARAM) != null)
      suspend = Integer.parseInt(filterConfig.getInitParameter(SUSPEND_INIT_PARAM));
    _suspendMs = suspend;

    ServletContext context = filterConfig.getServletContext();
    if (context != null
        && Boolean.parseBoolean(filterConfig.getInitParameter(MANAGED_ATTR_INIT_PARAM)))
      context.setAttribute(filterConfig.getFilterName(), this);
  }
Esempio n. 22
0
  public final void init(FilterConfig arg0) throws ServletException {
    filterConfig = arg0;
    encoding = filterConfig.getInitParameter("encoding");

    String value = filterConfig.getInitParameter("ignore");

    if (value == null) ignore = true;
    else if (value.equalsIgnoreCase("true")) ignore = true;
    else if (value.equalsIgnoreCase("yes")) ignore = true;
    else ignore = false;
  }
 @Override
 public void init(FilterConfig filterConfig) throws ServletException {
   String v = filterConfig.getInitParameter("securityDomain");
   if (v != null) {
     domain = v;
   }
   v = filterConfig.getInitParameter("realmName");
   if (v != null) {
     realmName = v;
   }
 }
Esempio n. 24
0
  public void init(FilterConfig config) throws ServletException {

    final String adminPages = config.getInitParameter(P_ADMIN);
    setAccessLevel(adminPages, acl, User.ADMIN_USER);

    final String userPages = config.getInitParameter(P_NORMAL);
    setAccessLevel(userPages, acl, User.NORMAL_USER);

    final String allAccessPages = config.getInitParameter(P_ALL);
    setAccessLevel(allAccessPages, acl, User.INACTIVE_USER);
  }
Esempio n. 25
0
  @Override
  public void init(FilterConfig config) throws ServletException {
    super.init(config);
    initializeFromConfig(); // configure init parameters the "old" way

    // filter init params are preffered and override context params :
    String value = config.getInitParameter("addsHtmlToPathInfo");
    if (value != null) setAddsHtmlToPathInfo(Boolean.parseBoolean(value));
    value = config.getInitParameter("verifiesHtmlResource");
    if (value != null) setVerifiesHtmlResource(Boolean.parseBoolean(value));
  }
  public void init(FilterConfig filterConfig) throws ServletException {
    Utils.logDebug("Initializing the filter..", LOG);

    passiveRequestorEndPoint = filterConfig.getInitParameter(PASSIVE_REQUESTOR_ENDPOINT);
    Utils.logInfo("Passive Requestor Endpoint is:" + passiveRequestorEndPoint, LOG);
    if (passiveRequestorEndPoint == null) {
      throw new ServletException(
          PASSIVE_REQUESTOR_ENDPOINT + " init parameter not proivded in the filter configuration.");
    }
    // Remove query parameters if any
    passiveRequestorEndPoint =
        (passiveRequestorEndPoint != null && passiveRequestorEndPoint.indexOf('?') > 0)
            ? passiveRequestorEndPoint.substring(0, passiveRequestorEndPoint.indexOf('?'))
            : passiveRequestorEndPoint;

    relyingPartyRealm = filterConfig.getInitParameter(RELYING_PARTY_REALM);
    Utils.logInfo("Relying Party Realm is:" + relyingPartyRealm, LOG);
    if (relyingPartyRealm == null) {
      throw new ServletException(
          RELYING_PARTY_REALM + " init parameter not proivded in the filter configuration.");
    }

    certificatePath = filterConfig.getInitParameter(CERTIFICATE_PATH);
    Utils.logInfo("Certificate path:" + certificatePath, LOG);
    if (certificatePath == null) {
      // 1. check for embedded cert and if exists set certPath to cert/acs_signing.cer
      if (filterConfig.getServletContext().getResourceAsStream(EMBEDDED_CERT_LOC) != null)
        certificatePath = EMBEDDED_CERT_LOC;
      else
        throw new ServletException(
            CERTIFICATE_PATH
                + " init parameter not proivded in the filter configuration"
                + " or Embeddded Cert is not found at /WEB-INF/cert/_acs_signing.cer");
    }

    secretKey = filterConfig.getInitParameter(SECRET_KEY);
    if (secretKey == null) {
      throw new ServletException(
          SECRET_KEY + " init parameter not proivded in the filter configuration.");
    }

    allowHttp = Boolean.parseBoolean(filterConfig.getInitParameter(ALLOW_HTTP));

    // create keystore
    Key publicKey = getPublicKey(certificatePath, filterConfig);
    trustParams =
        new TrustParameters(publicKey, Utils.getSecretKey(secretKey), allowHttp, relyingPartyRealm);

    // Create the command which performs actual filtering
    Utils.logDebug("Creating stateless filter...", LOG);
    filterCommand = new StatelessFilterCommand(this);
  }
Esempio n. 27
0
  public void init(FilterConfig config) throws ServletException {
    this.context = config.getServletContext();

    // get input and output dirs
    this.inDirName = config.getInitParameter(P_INPUT_DIRNAME);
    if (this.inDirName == null) this.inDirName = DEFAULT_INPUT_DIRNAME;
    this.outDirName = config.getInitParameter(P_OUTPUT_DIRNAME);
    if (this.outDirName == null) this.outDirName = DEFAULT_OUTPUT_DIRNAME;
    if (ZimbraLog.webclient.isDebugEnabled()) {
      ZimbraLog.webclient.debug("### indir:  " + this.inDirName);
      ZimbraLog.webclient.debug("### outdir: " + this.outDirName);
    }
  }
Esempio n. 28
0
  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
    this.sessionId = filterConfig.getInitParameter("sessionId");
    this.cookieDomain = filterConfig.getInitParameter("cookieDomain");
    if (this.cookieDomain == null) {
      this.cookieDomain = "";
    }

    this.cookiePath = filterConfig.getInitParameter("cookiePath");
    if (this.cookiePath == null || this.cookiePath.length() == 0) {
      this.cookiePath = "/";
    }
  }
  public void init(FilterConfig filterConfig) throws ServletException {
    final String expiresOffsetString =
        filterConfig.getInitParameter(EXPIRES_OFFSET_YEARS_PARAMETER_NAME);
    if (expiresOffsetString != null) {
      expiresOffsetYears = Integer.parseInt(expiresOffsetString);
    }

    final String userAgentExcludeRegexpString =
        filterConfig.getInitParameter(USER_AGENT_EXCLUDE_REGEXP_PARAMETER_NAME);
    if (userAgentExcludeRegexpString != null) {
      userAgentExclude = Pattern.compile(userAgentExcludeRegexpString);
    }
  }
Esempio n. 30
0
  @Test(expectedExceptions = ServletException.class)
  public void shouldThrowExceptionWhenMaxAgeIsNaN() throws ServletException {
    // given
    FilterConfig config = mock(FilterConfig.class);
    given(config.getInitParameter(CORSConstants.ORIGINS_KEY)).willReturn("www.google.com");
    given(config.getInitParameter(CORSConstants.METHODS_KEY)).willReturn("GET,POST");
    given(config.getInitParameter(CORSConstants.MAX_AGE_KEY)).willReturn("words");

    // when
    testFilter.init(config);

    // then
  }