Example usage for javax.servlet FilterConfig getInitParameter

List of usage examples for javax.servlet FilterConfig getInitParameter

Introduction

In this page you can find the example usage for javax.servlet FilterConfig getInitParameter.

Prototype

public String getInitParameter(String name);

Source Link

Document

Returns a String containing the value of the named initialization parameter, or null if the initialization parameter does not exist.

Usage

From source file:org.apache.ranger.security.web.filter.RangerKrbFilter.java

/**
 * <p>Initializes the authentication filter and signer secret provider.</p>
 * It instantiates and initializes the specified {@link
 * AuthenticationHandler}./*from w ww  .j ava  2 s.co m*/
 *
 * @param filterConfig filter configuration.
 *
 * @throws ServletException thrown if the filter or the authentication handler could not be initialized properly.
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    String configPrefix = filterConfig.getInitParameter(CONFIG_PREFIX);
    configPrefix = (configPrefix != null) ? configPrefix + "." : "";
    config = getConfiguration(configPrefix, filterConfig);
    String authHandlerName = config.getProperty(AUTH_TYPE, null);
    String authHandlerClassName;
    if (authHandlerName == null) {
        throw new ServletException("Authentication type must be specified: " + PseudoAuthenticationHandler.TYPE
                + "|" + KerberosAuthenticationHandler.TYPE + "|<class>");
    }
    if (StringUtils.equalsIgnoreCase(authHandlerName, PseudoAuthenticationHandler.TYPE)) {
        authHandlerClassName = PseudoAuthenticationHandler.class.getName();
    } else if (StringUtils.equalsIgnoreCase(authHandlerName, KerberosAuthenticationHandler.TYPE)) {
        authHandlerClassName = KerberosAuthenticationHandler.class.getName();
    } else {
        authHandlerClassName = authHandlerName;
    }

    validity = Long.parseLong(config.getProperty(AUTH_TOKEN_VALIDITY, "36000")) * 1000; //10 hours
    initializeSecretProvider(filterConfig);

    initializeAuthHandler(authHandlerClassName, filterConfig);

    cookieDomain = config.getProperty(COOKIE_DOMAIN, null);
    cookiePath = config.getProperty(COOKIE_PATH, null);
}

From source file:net.sf.j2ep.ProxyFilter.java

/**
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 * /*from   ww w. j a v a  2 s  .c o  m*/
 * Called upon initialization, Will create the ConfigParser and get the
 * RuleChain back. Will also configure the httpclient.
 */
public void init(FilterConfig filterConfig) throws ServletException {
    log = LogFactory.getLog(ProxyFilter.class);
    AllowedMethodHandler.setAllowedMethods("OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE");

    httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    httpClient.getParams().setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, false);
    httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);

    String data = filterConfig.getInitParameter("dataUrl");
    if (data == null) {
        serverChain = null;
    } else {
        try {
            File dataFile = new File(filterConfig.getServletContext().getRealPath(data));
            ConfigParser parser = new ConfigParser(dataFile);
            serverChain = parser.getServerChain();
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }
}

From source file:at.gv.egovernment.moa.id.configuration.filter.AuthenticationFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    log.debug("Starting init of " + this.getClass().getName() + ".");

    try {//from  w  w  w  .  j  a  v a2s . com
        config = ConfigurationProvider.getInstance();

    } catch (ConfigurationException e) {
        throw new ServletException(e.getMessage(), e);

    }

    // login page
    loginPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_LOGIN_PAGE));
    if (MiscUtil.isEmpty(loginPage)) {
        throw new ServletException(
                "ServletInitParameter \"" + WEB_XML_INIT_PARAM_LOGIN_PAGE + "\" must not be empty.");
    }
    loginPageForward = false; //!WebAppUtil.isFullQualifiedURL(loginPage);

    // error page
    errorPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ERROR_PAGE));
    if (MiscUtil.isEmpty(errorPage)) {
        throw new ServletException(
                "ServletInitParameter \"" + WEB_XML_INIT_PARAM_ERROR_PAGE + "\" must not be empty.");
    }

    // session lost page
    sessionLostPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_SESSION_LOST_PAGE));
    if (MiscUtil.isEmpty(sessionLostPage)) {
        log.warn("ServletInitParameter \"" + WEB_XML_INIT_PARAM_SESSION_LOST_PAGE
                + "\" is empty. This parameter defines a failsafe url the browser is redirected to if the original url has been lost due to session timeout.");
    }

    // authenticated page
    authenticatedPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE));
    if (MiscUtil.isEmpty(authenticatedPage)) {
        log.debug("ServletInitParameter \"" + WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE
                + "\" is empty. This parameter defines the url the user is redirected to (instead of the original url) on successful authentication.");
    }
    String excluded = filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ALLOWED_LIST);
    ArrayList<String> excludedList = new ArrayList<String>();
    if (MiscUtil.isNotEmpty(excluded)) {
        StringTokenizer tokenizer = new StringTokenizer(excluded, WEB_XML_INIT_PARAM_EXCLUDED_PAGES_DELIMITER);
        while (tokenizer.hasMoreTokens()) {
            String ex = StringUtils.trim(tokenizer.nextToken());
            if (MiscUtil.isNotEmpty(ex)) {
                excludedList.add(ex);
            }
        }
    }
    excludedList.add(loginPage);
    excludedList.add(errorPage);
    excludedPages = new String[excludedList.size()];
    excludedPages = excludedList.toArray(excludedPages);

    String excludedRegExString = StringUtils
            .trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ALLOWED_REGEX));
    if (MiscUtil.isNotEmpty(excludedRegExString)) {
        excludedRegEx = Pattern.compile(excludedRegExString);
    }

    log.debug(WEB_XML_INIT_PARAM_LOGIN_PAGE + " [" + (loginPageForward ? "forward" : "redirect") + "] = \""
            + loginPage + "\"");
    log.debug(WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE + " = \""
            + (MiscUtil.isNotEmpty(authenticatedPage) ? authenticatedPage : "<n/a>") + "\"");
    log.debug(WEB_XML_INIT_PARAM_ERROR_PAGE + " = \"" + errorPage + "\"");
    log.debug(WEB_XML_INIT_PARAM_SESSION_LOST_PAGE + " = \""
            + (MiscUtil.isNotEmpty(sessionLostPage) ? sessionLostPage : "<n/a>") + "\"");
    log.debug(WEB_XML_INIT_PARAM_ALLOWED_LIST + " = " + ToStringUtil.toString(excludedPages, ", ", "\""));
    log.debug(WEB_XML_INIT_PARAM_ALLOWED_REGEX + " = \""
            + (excludedRegEx != null ? excludedRegEx.pattern() : "<n/a>") + "\"");
}

From source file:com.cws.esolutions.security.filters.SSLEnforcementFilter.java

public void init(final FilterConfig filterConfig) throws ServletException {
    final String methodName = SSLEnforcementFilter.CNAME
            + "#init(FilterConfig filterConfig) throws ServletException";

    if (DEBUG) {/*ww w . j a  va 2  s .com*/
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("FilterConfig: {}", filterConfig);
    }

    ResourceBundle rBundle = null;

    try {
        if (filterConfig.getInitParameter(SSLEnforcementFilter.FILTER_CONFIG_PARAM_NAME) == null) {
            ERROR_RECORDER.error("Filter configuration not found. Using default !");

            rBundle = ResourceBundle.getBundle(SSLEnforcementFilter.FILTER_CONFIG_FILE_NAME);
        } else {
            rBundle = ResourceBundle
                    .getBundle(filterConfig.getInitParameter(SSLEnforcementFilter.FILTER_CONFIG_PARAM_NAME));
        }

        this.ignoreHosts = (StringUtils.isNotEmpty(rBundle.getString(SSLEnforcementFilter.IGNORE_HOST_LIST)))
                ? rBundle.getString(SSLEnforcementFilter.IGNORE_HOST_LIST).trim().split(",")
                : null;
        this.ignoreURIs = (StringUtils.isNotEmpty(rBundle.getString(SSLEnforcementFilter.IGNORE_URI_LIST)))
                ? rBundle.getString(SSLEnforcementFilter.IGNORE_HOST_LIST).trim().split(",")
                : null;

        if (DEBUG) {
            if (this.ignoreHosts != null) {
                for (String str : this.ignoreHosts) {
                    DEBUGGER.debug(str);
                }
            }

            if (this.ignoreURIs != null) {
                for (String str : this.ignoreURIs) {
                    DEBUGGER.debug(str);
                }
            }
        }
    } catch (MissingResourceException mre) {
        ERROR_RECORDER.error(mre.getMessage(), mre);

        throw new UnavailableException(mre.getMessage());
    }
}

From source file:org.commonfarm.web.ECSideFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    servletContext = filterConfig.getServletContext();
    servletRealPath = servletContext.getRealPath("/");

    initEncoding();//from  w w w .  j av  a2  s .  com
    initEasyList();

    String responseHeadersSetBeforeDoFilter = filterConfig.getInitParameter("responseHeadersSetBeforeDoFilter");
    if (StringUtils.isNotBlank(responseHeadersSetBeforeDoFilter)) {
        ECSideFilter.responseHeadersSetBeforeDoFilter = Boolean.valueOf(responseHeadersSetBeforeDoFilter)
                .booleanValue();
    }

}

From source file:edu.indiana.d2i.htrc.oauth2.filter.OAuth2Filter.java

/**
 * Setup servlet filter instance after reading filter configuration in web.xml. In a production scenario where
 * WSO2 IS is deployed with a valid certificate filter doesn't need trust store and trust store password
 * configuration values./*from w  ww. jav  a2s . c  o  m*/
 *
 * Also it's better have a web app specific user account to use with filter. This will make it easier to audit the
 * security logs.
 *
 * @param filterConfig  OAuth2 filter configuration
 * @throws ServletException
 */
public void init(FilterConfig filterConfig) throws ServletException {

    try {
        config = filterConfig;
        String log4jPath = config.getInitParameter(PN_LOG4J_PROPERTIES_PATH);
        AuditorFactory.init(config.getInitParameter(PN_AUDITOR_CLASS));
        auditorFactory = new AuditorFactory();

        if (log4jPath != null) {
            PropertyConfigurator.configure(log4jPath);
        }

        providerUrl = filterConfig.getInitParameter(OAUTH2_PROVIDER_URL);
        if (providerUrl == null || providerUrl.isEmpty()) {
            log.error("Cannot find OAuth2 provider URL in filter configuration!");
            throw new RuntimeException("Cannot find OAuth2 provider URL in filter configuration!");
        }
        userName = filterConfig.getInitParameter(OAUTH2_PROVIDER_USERS);
        if (userName == null || userName.isEmpty()) {
            log.error("Cannot find OAuth2 provider username in filter configuration!");
            throw new RuntimeException("Cannot find OAuth2 provider username in filter configuration!");
        }

        password = filterConfig.getInitParameter(OAUTH2_PROVIDER_PASSWORD);
        if (password == null || password.isEmpty()) {
            log.error("Cannot find OAuth2 provider password in filter configuration!");
            throw new RuntimeException("Cannot find OAuth2 provider password in filter configuration!");
        }
        // Trust store can be used when WSO2 IS is deployed with self-signed certificates
        trustStore = filterConfig.getInitParameter(TRUST_STORE);
        trustStorePassword = filterConfig.getInitParameter(TRUST_STORE_PASSWORD);

        if (trustStore != null && trustStorePassword != null) {
            System.setProperty(TRUST_STORE, trustStore);
            System.setProperty(TRUST_STORE_PASSWORD, trustStorePassword);
        }

        realm = filterConfig.getInitParameter(OAUTH2_RESOURCE_REALM);

    } catch (Exception e) {
        e.printStackTrace();
        throw new ServletException(e);
    }

}

From source file:org.apache.hadoop.security.authentication.server.AuthenticationFilter.java

/**
 * Returns the filtered configuration (only properties starting with the specified prefix). The property keys
 * are also trimmed from the prefix. The returned {@link Properties} object is used to initialized the
 * {@link AuthenticationHandler}./*from  w  ww . j  a  v a 2s . c  o  m*/
 * <p/>
 * This method can be overriden by subclasses to obtain the configuration from other configuration source than
 * the web.xml file.
 *
 * @param configPrefix configuration prefix to use for extracting configuration properties.
 * @param filterConfig filter configuration object
 *
 * @return the configuration to be used with the {@link AuthenticationHandler} instance.
 *
 * @throws ServletException thrown if the configuration could not be created.
 */
protected Properties getConfiguration(String configPrefix, FilterConfig filterConfig) throws ServletException {
    Properties props = new Properties();
    Enumeration<?> names = filterConfig.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (name.startsWith(configPrefix)) {
            String value = filterConfig.getInitParameter(name);
            props.put(name.substring(configPrefix.length()), value);
        }
    }
    return props;
}

From source file:org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponse.java

public UrlRewriteResponse(FilterConfig config, HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    super(response);
    this.rewriter = UrlRewriteServletContextListener.getUrlRewriter(config.getServletContext());
    this.config = config;
    this.request = request;
    this.response = response;
    this.output = null;
    getXForwardedHeaders();/*from  w w w. ja v  a  2s  .c  o  m*/
    this.bodyFilterName = config.getInitParameter(UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM);
    this.headersFilterName = config.getInitParameter(UrlRewriteServletFilter.RESPONSE_HEADERS_FILTER_PARAM);
    this.headersFilterConfig = getRewriteFilterConfig(rewriter.getConfig(), headersFilterName,
            UrlRewriteServletFilter.HEADERS_MIME_TYPE);
    this.cookiesFilterName = config.getInitParameter(UrlRewriteServletFilter.RESPONSE_COOKIES_FILTER_PARAM);
}

From source file:org.ajax4jsf.webapp.BaseXMLFilter.java

public void init(FilterConfig config) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("init XML filter service with class " + this.getClass().getName());
    }//from   ww  w. ja  v a  2  s.  c  o m
    String forceXmlParameter = config.getInitParameter(FORCEXML_PARAMETER);
    if (forceXmlParameter == null) {
        forceXmlParameter = config.getServletContext()
                .getInitParameter(INIT_PARAMETER_PREFIX + FORCEXML_PARAMETER);
    }
    setupForceXml(forceXmlParameter);

    String forceNotRfParameter = config.getInitParameter(FORCENOTRF_PARAMETER);
    if (forceNotRfParameter == null) {
        forceNotRfParameter = config.getServletContext()
                .getInitParameter(INIT_PARAMETER_PREFIX + FORCENOTRF_PARAMETER);
    }
    setupForcenotrf(forceNotRfParameter);

    setMimetype((String) nz(config.getInitParameter(MIME_TYPE_PARAMETER), "text/xml"));
    setPublicid((String) nz(config.getInitParameter(PUBLICID_PARAMETER), getPublicid()));
    setSystemid((String) nz(config.getInitParameter(SYSTEMID_PARAMETER), getSystemid()));
    setNamespace((String) nz(config.getInitParameter(NAMESPACE_PARAMETER), getNamespace()));
    handleViewExpiredOnClient = Boolean.parseBoolean(
            config.getServletContext().getInitParameter(ContextInitParameters.HANDLE_VIEW_EXPIRED_ON_CLIENT));

}

From source file:org.apache.struts2.dispatcher.FilterDispatcher.java

/**
 * Initializes the filter by creating a default dispatcher
 * and setting the default packages for static resources.
 *
 * @param filterConfig The filter configuration
 *//*from   ww  w.  j  a  v a2  s  .c o m*/
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;

    dispatcher = createDispatcher(filterConfig);
    dispatcher.init();

    String param = filterConfig.getInitParameter("packages");
    String packages = "org.apache.struts2.static template org.apache.struts2.interceptor.debugging";
    if (param != null) {
        packages = param + " " + packages;
    }
    this.pathPrefixes = parse(packages);
}