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:info.magnolia.cms.filters.ServletDispatchingFilter.java

/**
 * Initializes the servlet and its mappings. ServletConfig is wrapped to take init parameters into account.
 *///from  w w  w.j  a v  a  2  s  . c  om
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
    super.init(filterConfig);

    if (servletClass != null) {
        try {
            servlet = Classes.newInstance(servletClass);
            servlet.init(new CustomServletConfig(servletName, filterConfig.getServletContext(), parameters));
        } catch (Throwable e) {
            log.error("Unable to load servlet " + servletClass + " : " + e.getMessage(), e);
        }
    }
}

From source file:org.commoncrawl.service.listcrawler.MultiPartFilter.java

/**
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 *//* w  w  w .ja v a2 s .  c  o m*/
public void init(FilterConfig filterConfig) throws ServletException {

    tempdir = (File) filterConfig.getServletContext().getAttribute("javax.servlet.context.tempdir");
    LOG.info("tempdir:" + tempdir);
    _deleteFiles = true;
    LOG.info("deleteFiles:" + _deleteFiles);
    _context = filterConfig.getServletContext();
}

From source file:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    InitOperations init = new InitOperations();
    try {/*  w w  w .  jav  a 2  s . co  m*/
        FilterHostConfig config = new FilterHostConfig(filterConfig);
        init.initLogging(config);
        Dispatcher dispatcher = init.initDispatcher(config);
        init.initStaticContentLoader(config, dispatcher);

        prepare = new PrepareOperations(filterConfig.getServletContext(), dispatcher);
        execute = new ExecuteOperations(filterConfig.getServletContext(), dispatcher);
        this.excludedPatterns = init.buildExcludedPatternsList(dispatcher);

        postInit(dispatcher, filterConfig);
    } finally {
        init.cleanup();
    }

}

From source file:com.netpace.cms.sso.filter.AlfrescoOpenSSOFilter.java

public void init(FilterConfig config) throws ServletException {
    props = ConfigEnvProperties.getInstance();
    openSSOServerURL = props.getProperty("opensso.url");
    vzdnSiteURL = props.getProperty("vzdnsite.url");
    servletContext = config.getServletContext();

    USERS.add("ricardo.clements@verizonwireless.com");
    USERS.add("michael.salmon@verizonwireless.com");
    USERS.add("lawrence.rau@verizonwireless.com");
    USERS.add("larry.voss@verizonwireless.com");
    USERS.add("jonathan.firestone@verizonwireless.com");
    USERS.add("diana.lewis@verizonwireless.com");
    USERS.add("dan@qual-smart.com");
    USERS.add("dalena.good@verizonwireless.com");
    USERS.add("brian.higgins@verizonwireless.com");

}

From source file:ch.gadp.alfresco.OAuthSSOAuthenticationFilter.java

/**
 * Called by the web container to indicate to a filter that it is being placed into
 * service. The servlet container calls the init method exactly once after instantiating the
 * filter. The init method must complete successfully before the filter is asked to do any
 * filtering work. <br><br>/*from w w  w .  j av  a2s .c o m*/
 * <p/>
 * The web container cannot place the filter into service if the init method either<br>
 * 1.Throws a ServletException <br>
 * 2.Does not return within a time period defined by the web container
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.servletContext = filterConfig.getServletContext();
}

From source file:org.artifactory.webapp.servlet.AccessFilter.java

@Override
public void initLater(FilterConfig filterConfig) throws ServletException {
    ServletContext servletContext = filterConfig.getServletContext();
    this.context = RequestUtils.getArtifactoryContext(servletContext);
    ArtifactoryAuthenticationFilterChain filterChain = new ArtifactoryAuthenticationFilterChain();
    //Add all the authentication filters
    //TODO: [by yl] Support ordering...
    filterChain.addFilters(context.beansForType(ArtifactoryAuthenticationFilter.class).values());
    authFilter = filterChain;//from   www . j  ava 2  s.  c  om
    initCaches(filterConfig);
    authFilter.init(filterConfig);
    authInterceptors = new AnonymousAuthenticationInterceptors();
    authInterceptors.addInterceptors(context.beansForType(AnonymousAuthenticationInterceptor.class).values());
}

From source file:org.alfresco.web.scripts.servlet.X509ServletFilterBase.java

public void init(FilterConfig config) throws ServletException {
    try {/*from  w w w.  ja  va2 s  .c  o m*/
        /*
        *  Find out if we are enforcing.
        */

        if (logger.isDebugEnabled()) {
            logger.debug("Initializing X509ServletFilter");
        }

        this.enforce = checkEnforce(config.getServletContext());

        if (logger.isDebugEnabled()) {
            logger.debug("Enforcing X509 Authentication:" + this.enforce);
        }

        if (this.enforce) {
            /*
            * We are enforcing so get the cert-contains string.
            */

            this.certContains = config.getInitParameter("cert-contains");

            if (logger.isDebugEnabled()) {
                if (certContains == null) {
                    logger.debug("Not enforcing cert-contains");
                } else {
                    logger.debug("Enforcing cert-contains:" + this.certContains);
                }
            }
        }
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:org.artifactory.webapp.servlet.AccessFilter.java

private void initCaches(FilterConfig filterConfig) {
    ArtifactorySystemProperties properties = ((ArtifactoryHome) filterConfig.getServletContext()
            .getAttribute(ArtifactoryHome.SERVLET_CTX_ATTR)).getArtifactoryProperties();
    ConstantValues idleTimeSecsProp = ConstantValues.securityAuthenticationCacheIdleTimeSecs;
    long cacheIdleSecs = properties.getLongProperty(idleTimeSecsProp);
    ConstantValues initSizeProp = ConstantValues.securityAuthenticationCacheInitSize;
    long initSize = properties.getLongProperty(initSizeProp);
    nonUiAuthCache = CacheBuilder.newBuilder().softValues().initialCapacity((int) initSize)
            .expireAfterWrite(cacheIdleSecs, TimeUnit.SECONDS).<AuthCacheKey, Authentication>build().asMap();
    userChangedCache = CacheBuilder.newBuilder().softValues().initialCapacity((int) initSize)
            .expireAfterWrite(cacheIdleSecs, TimeUnit.SECONDS).<String, AuthenticationCache>build().asMap();
    SecurityService securityService = context.beanForType(SecurityService.class);
    securityService.addListener(this);
}

From source file:org.toobsframework.servlet.filters.compression.CompressionFilter.java

/**
 * Initializes the filter's configuratuon
 *
 * @param config the FilterConfig object
 *
 * @throws ServletException//from  w w w.java  2 s  .c om
 */
public void init(FilterConfig config) throws ServletException {
    this.config = config;
    this.config.getServletContext().log("CompressionFilter - init()");
    URL resourcesURL = null;

    try {
        resourcesURL = config.getServletContext().getResource("/WEB-INF/classes/compression-filter-config.xml");

        if (resourcesURL != null) {
            if (log.isDebugEnabled()) {
                log.debug("Loading compression-filter-config");
            }
            CompressionFilterDAO dao = new CompressionFilterDAO(resourcesURL);

            filterCompress = dao.isCompressionEnabled();
            filterWhitespace = dao.isWhitespaceEnabled();

            filterEnabled = (filterCompress || filterWhitespace);
            if (log.isDebugEnabled()) {
                log.debug("filter enabled: " + filterEnabled);
            }
            compressionType = dao.getCompressionType();
            if (log.isDebugEnabled()) {
                log.debug("filter compression type: " + compressionType);
            }
            bufferSize = dao.getBufferSize();
            if (filterCompress) {
                smartCompress = dao.isSmartCompress();
                if (smartCompress) {
                    excludedHosts = dao.getHostAddress();
                    if (excludedHosts.size() < 1) {
                        smartCompress = false;
                    }
                }
            }
            if (log.isDebugEnabled()) {
                log.debug("smart compress: " + smartCompress);
                log.debug("host address  : " + excludedHosts);
            }
        }
    } catch (java.net.MalformedURLException ex) {
        this.config.getServletContext().log("CompressionFilter - Exception during init: " + ex.getMessage(),
                ex);
        throw new ServletException(ex);
    }
}

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();//  ww w. j  av a 2  s .  c  om
    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);
}