Example usage for javax.servlet FilterConfig getServletContext

List of usage examples for javax.servlet FilterConfig getServletContext

Introduction

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

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns a reference to the ServletContext in which the caller is executing.

Usage

From source file:cc.kune.core.server.rack.filters.gwts.GWTServiceFilter.java

@Override
public void init(final FilterConfig filterConfig) throws ServletException {
    super.init(filterConfig);
    final RemoteService service = getInstance(serviceClass);
    this.servlet = new DelegatedRemoteServlet(service);
    servlet.setService(service, serviceClass.getSimpleName());
    servlet.setServletContext(filterConfig.getServletContext());
}

From source file:jp.co.opentone.bsol.framework.web.filter.FeedAuthenticationFilter.java

private void setupAuthenticator(String name, FilterConfig filterConfig) throws ServletException {
    try {//from  www .j a va2s  . c o m
        factory = (FeedAuthenticatorFactory) Class.forName(name).newInstance();
        factory.setContext(
                WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()));
    } catch (Exception e) {
        log.error(String.format("Authenticator factory not instanciated. %s", name), e);
        throw new ServletException(e);
    }
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.MultiPartFilter.java

/**
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 *///  w ww  .  j  a v a 2  s.c  om
public void init(FilterConfig filterConfig) throws ServletException {
    tempdir = (File) filterConfig.getServletContext().getAttribute("javax.servlet.context.tempdir");
}

From source file:org.alfresco.web.site.servlet.SecurityHeadersFilter.java

/**
 * Parses the headers config.//from  www  . ja  va 2  s  . c om
 *
 * @param config The filter config
 * @throws javax.servlet.ServletException if the headers filter config is invalid
 */
@Override
public void init(FilterConfig config) throws ServletException {
    servletContext = config.getServletContext();

    ApplicationContext context = getApplicationContext();

    ConfigService configService = (ConfigService) context.getBean("web.config");

    // Retrieve the remote configuration
    Config securityHeadersConfig = (Config) configService.getConfig("SecurityHeadersPolicy");
    if (securityHeadersConfig == null) {
        enabled = false;
        if (logger.isDebugEnabled())
            logger.debug("There is no 'SecurityHeadersPolicy' config, no headers will be added.");
    } else {
        ConfigElement headersConfig = securityHeadersConfig.getConfigElement("headers");
        if (headersConfig == null) {
            enabled = false;
            if (logger.isDebugEnabled())
                logger.debug("The 'SecurityHeadersPolicy' config had no headers, no headers will be added.");
        } else {
            List<ConfigElement> headersConfigList = headersConfig.getChildren("header");
            if (headersConfigList == null || headersConfigList.size() == 0) {
                enabled = false;
                if (logger.isDebugEnabled())
                    logger.debug(
                            "The 'SecurityHeadersPolicy' headers config was empty, no headers will be added.");
            } else {
                // Get and merge all configs
                Map<String, Header> allHeaders = new HashMap<String, Header>();
                for (ConfigElement headerConfig : headersConfigList) {
                    // Name
                    String name = headerConfig.getChildValue("name");
                    Header header;
                    if (allHeaders.containsKey(name)) {
                        header = allHeaders.get(name);
                    } else {
                        header = new Header();
                        header.setName(name);
                        allHeaders.put(name, header);
                    }

                    // Vaule
                    ConfigElement valueConfig = headerConfig.getChild("value");
                    if (valueConfig != null) {
                        header.setValue(valueConfig.getValue());
                    }

                    // Enabled
                    ConfigElement enabledConfig = headerConfig.getChild("enabled");
                    if (enabledConfig != null) {
                        String enabled = enabledConfig.getValue();
                        header.setEnabled(enabled == null || enabled.equalsIgnoreCase("true"));
                    }
                }

                // Filter out all enabled configs
                for (Header header : allHeaders.values()) {
                    if (header.getEnabled()) {
                        headers.add(header);
                    }
                }
            }
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.filters.CachingResponseFilter.java

@Override
public void init(FilterConfig fc) throws ServletException {
    ctx = fc.getServletContext();
    ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
    defaultNamespace = props.getProperty(PROPERTY_DEFAULT_NAMESPACE);
    enabled = Boolean.valueOf(props.getProperty(PROPERTY_ENABLE_CACHING));
}

From source file:com.zaizi.alfresco.crowd.authentication.filter.CrowdSSOFilter.java

/**
 * <p>//from  w  w w  .  j  av  a2 s .c  om
 * Filter initialization
 * </p>
 * 
 * @param filterConfig
 *            The filter configuration
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.servletContext = filterConfig.getServletContext();

    ApplicationContext context = getApplicationContext();

    /*
     * retrieve the framework utils bean used to deal with connectors (connector.service) and connector
     * sessions
     */
    this.frameworkUtils = (FrameworkBean) context.getBean("framework.utils");
}

From source file:org.alfresco.module.vti.web.VtiFilter.java

/**
 * <p>//  w  ww.  j  a  va  2 s  .  c  o m
 * Filter initialization.
 * </p>
 * 
 * @param filterConfig filter configuration
 */
public void init(FilterConfig filterConfig) throws ServletException {
    this.context = filterConfig.getServletContext();
}

From source file:org.xwiki.resource.servlet.RoutingFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    // Get the Component Manager which has been initialized first in a Servlet Context Listener.
    this.rootComponentManager = (ComponentManager) filterConfig.getServletContext()
            .getAttribute(ComponentManager.class.getName());
    // Save the Servlet Context to be able to do forwards later on
    this.servletContext = filterConfig.getServletContext();
}

From source file:com.googlecode.jtiger.modules.ecside.filter.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 a  2  s.  co  m
    initProperties();

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

}

From source file:dk.itst.oiosaml.sp.service.SPFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    String homeParam = filterConfig.getServletContext().getInitParameter(Constants.INIT_OIOSAML_HOME);
    log.info(Constants.INIT_OIOSAML_HOME + " set to " + homeParam + " in web.xml");
    if (homeParam == null) {
        homeParam = System.getProperty(SAMLUtil.OIOSAML_HOME);
    }/*  w  ww  .j  a v  a2  s.  c  om*/
    if (homeParam == null) {
        String name = filterConfig.getServletContext().getInitParameter(Constants.INIT_OIOSAML_NAME);
        if (name != null) {
            log.info("Configuring OIOSAML with application name " + name);
            homeParam = System.getProperty("user.home") + "/.oiosaml-" + name;
        }
    }
    log.info("Trying to retrieve configuration from " + homeParam);
    SAMLConfiguration.setHomeProperty(homeParam);

    if (SAMLConfiguration.isConfigured()) {
        try {
            Configuration conf = SAMLConfiguration.getSystemConfiguration();
            if (conf.getBoolean(Constants.PROP_DEVEL_MODE, false)) {
                develMode = new DevelModeImpl();
                setConfiguration(conf);
                setFilterInitialized(true);
                return;
            }
            setRuntimeConfiguration(conf);
            setFilterInitialized(true);
            return;
        } catch (IllegalStateException e) {
            log.error("Unable to configure", e);
        }
    }
    log.info("The parameter " + Constants.INIT_OIOSAML_HOME + " which is set in web.xml to: " + homeParam
            + " is not set to an (existing) directory, or the directory is empty - OIOSAML-J is not configured.");
    setFilterInitialized(false);

}