Java Code Examples for javax.servlet.FilterConfig#getServletContext()

The following examples show how to use javax.servlet.FilterConfig#getServletContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenUtils.java    From knox with Apache License 2.0 6 votes vote down vote up
/**
 * Determine if server-managed token state is enabled for a provider, based on configuration.
 * The analysis includes checking the provider params and the gateway configuration.
 *
 * @param filterConfig A FilterConfig object.
 *
 * @return true, if server-managed state is enabled; Otherwise, false.
 */
public static boolean isServerManagedTokenStateEnabled(FilterConfig filterConfig) {
  boolean isServerManaged = false;

  // First, check for explicit provider-level configuration
  String providerParamValue = filterConfig.getInitParameter(TokenStateService.CONFIG_SERVER_MANAGED);

  // If there is no provider-level configuration
  if (providerParamValue == null || providerParamValue.isEmpty()) {
    // Fall back to the gateway-level default
    ServletContext context = filterConfig.getServletContext();
    if (context != null) {
      GatewayConfig config = (GatewayConfig) context.getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
      isServerManaged = (config != null) && config.isServerManagedTokenStateEnabled();
    }
  } else {
    // Otherwise, apply the provider-level configuration
    isServerManaged = Boolean.valueOf(providerParamValue);
  }

  return isServerManaged;
}
 
Example 2
Source File: EncodingFilter.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public void init(final FilterConfig config) throws ServletException {
    servletContext = config.getServletContext();

    encoding = config.getInitParameter(LastaPrepareFilter.ENCODING_KEY);
    if (encoding == null) {
        encoding = LastaPrepareFilter.DEFAULT_ENCODING;
    }

    // ex. sjis:Shift_JIS,eucjp:EUC-JP
    final String value = config.getInitParameter(ENCODING_MAP);
    if (StringUtil.isNotBlank(value)) {
        final String[] encodingPairs = value.split(",");
        for (final String pair : encodingPairs) {
            final String[] encInfos = pair.trim().split(":");
            if (encInfos.length == 2) {
                encodingMap.put("/" + encInfos[0] + "/", encInfos[1]);
            }
        }
    }
}
 
Example 3
Source File: MultiAppGuiceFilter.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void init( FilterConfig filterConfig ) throws ServletException {
    synchronized ( lock ) {
        //define the localPipeline with the injected pipeline.
        localPipeline = pipeline;
        // Store servlet context in a weakreference, for injection
        servletContext = new WeakReference<ServletContext>( filterConfig.getServletContext() );
        localPipeline.initPipeline( filterConfig.getServletContext() );
        //reset the static pipeline
        pipeline = new DefaultFilterPipeline();
    }
}
 
Example 4
Source File: GenericFilterBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Standard way of initializing this filter.
 * Map config parameters onto bean properties of this filter, and
 * invoke subclass initialization.
 * @param filterConfig the configuration for this filter
 * @throws ServletException if bean properties are invalid (or required
 * properties are missing), or if subclass initialization fails.
 * @see #initFilterBean
 */
@Override
public final void init(FilterConfig filterConfig) throws ServletException {
	Assert.notNull(filterConfig, "FilterConfig must not be null");
	if (logger.isDebugEnabled()) {
		logger.debug("Initializing filter '" + filterConfig.getFilterName() + "'");
	}

	this.filterConfig = filterConfig;

	// Set bean properties from init parameters.
	try {
		PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties);
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
		ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext());
		bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.environment));
		initBeanWrapper(bw);
		bw.setPropertyValues(pvs, true);
	}
	catch (BeansException ex) {
		String msg = "Failed to set bean properties on filter '" +
			filterConfig.getFilterName() + "': " + ex.getMessage();
		logger.error(msg, ex);
		throw new NestedServletException(msg, ex);
	}

	// Let subclasses do whatever initialization they like.
	initFilterBean();

	if (logger.isDebugEnabled()) {
		logger.debug("Filter '" + filterConfig.getFilterName() + "' configured successfully");
	}
}
 
Example 5
Source File: AuthenticationCheckFilter.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final FilterConfig filterConfig) throws ServletException
{
    String allowed = filterConfig.getInitParameter(INIT_PARAM_ALLOWED);
    if (allowed != null && !"".equals(allowed))
    {
        _allowed = allowed;
    }
    ServletContext servletContext = filterConfig.getServletContext();
    _broker = HttpManagementUtil.getBroker(servletContext);
    _managementConfiguration = HttpManagementUtil.getManagementConfiguration(servletContext);
}
 
Example 6
Source File: DaggerFilter.java    From dagger-servlet with Apache License 2.0 5 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    ServletContext servletContext = filterConfig.getServletContext();

    // Store servlet context in a weakreference, for injection
    DaggerFilter.servletContext = new WeakReference<ServletContext>(servletContext);

    // In the default pipeline, this is a noop. However, if replaced
    // by a managed pipeline, a lazy init will be triggered the first time
    // dispatch occurs.
    FilterPipeline filterPipeline = getPipeline();
    filterPipeline.initPipeline(servletContext);
}
 
Example 7
Source File: ProxyFilter.java    From esigate with Apache License 2.0 5 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) {
    requestFactory = new RequestFactory(filterConfig.getServletContext());
    // Force esigate configuration parsing to trigger errors right away (if
    // any) and prevent delay on first call.
    DriverFactory.ensureConfigured();
}
 
Example 8
Source File: ProxyFilter.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void init(FilterConfig config) throws ServletException {
    if (enable) {
        ProxyFilterConfig proxyFilterConfig = new ProxyFilterConfig(
                config.getServletContext());
        proxyFilterConfig.setFilterName(name);
        proxyFilterConfig.setMap(map);
        filter.init(proxyFilterConfig);
    }
}
 
Example 9
Source File: PippoFilter.java    From pippo with Apache License 2.0 4 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    if (System.getProperty("pippo.hideLogo") == null) {
        log.info(PippoUtils.getPippoLogo());
    }

    // check for runtime mode in filter init parameter
    String mode = filterConfig.getInitParameter(MODE_PARAM);
    if (!StringUtils.isNullOrEmpty(mode)) {
        System.setProperty(PippoConstants.SYSTEM_PROPERTY_PIPPO_MODE, mode);
    }

    if (application == null) {
        createApplication(filterConfig);
        log.debug("Created application '{}'", application);
    }

    ServletContext servletContext = filterConfig.getServletContext();

    // save the servlet context object in application
    application.setServletContext(servletContext);

    // set the application as an attribute of the servlet container
    if (servletContext.getAttribute(WebServer.PIPPO_APPLICATION) == null) {
        servletContext.setAttribute(WebServer.PIPPO_APPLICATION, application);
    }

    try {
        String contextPath = StringUtils.addStart(servletContext.getContextPath(), "/");
        application.getRouter().setContextPath(contextPath);

        if (filterPath == null) {
            initFilterPath(filterConfig);
        }
        String applicationPath = StringUtils.addEnd(contextPath, "/") + StringUtils.removeStart(filterPath, "/");
        application.getRouter().setApplicationPath(applicationPath);

        if (!contextPath.equals(applicationPath)) {
            log.debug("Context path is '{}'", contextPath);
        }
        log.debug("Serving application on path '{}'", applicationPath);

        log.debug("Initializing Route Dispatcher");
        routeDispatcher = new RouteDispatcher(application);
        routeDispatcher.init();

        String runtimeMode = application.getRuntimeMode().toString().toUpperCase();
        log.info("Pippo started ({})", runtimeMode);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        destroy();
        throw new ServletException(e);
    }
}
 
Example 10
Source File: ValidateLoginFilter.java    From weiyunpan with Apache License 2.0 4 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
	servletContext = filterConfig.getServletContext();
}
 
Example 11
Source File: ScriptFilter.java    From engine with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.servletContext = filterConfig.getServletContext();
}
 
Example 12
Source File: AuthenticationEndpointFilter.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    context = filterConfig.getServletContext();
}
 
Example 13
Source File: AuthenticationEndpointFilter.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    context = filterConfig.getServletContext();
}
 
Example 14
Source File: IsLoginFilter.java    From ALLGO with Apache License 2.0 4 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
	servletContext = filterConfig.getServletContext();
	
}
 
Example 15
Source File: Oauth2Filter.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void init(final FilterConfig config) throws ServletException {
  this.context = config.getServletContext();
}
 
Example 16
Source File: Config.java    From monasca-common with Apache License 2.0 4 votes vote down vote up
public synchronized void initialize(FilterConfig config, ServletRequest req) throws ServletException {
  this.context = config.getServletContext();
  this.filterConfig = config;

  try {

    // Initialize auth server connection parameters...

    String host = filterConfig.getInitParameter(SERVER_VIP);

    int port = Integer.parseInt(filterConfig.getInitParameter(SERVER_PORT));

    // Initialize Certificates

    String keyStore = filterConfig.getInitParameter(KEYSTORE);
    String keyPass = filterConfig.getInitParameter(KEYSTORE_PASS);
    String trustStore = filterConfig.getInitParameter(TRUSTSTORE);
    String trustPass = filterConfig.getInitParameter(TRUSTSTORE_PASS);

    String adminToken = getValue(ADMIN_TOKEN, "");
    final boolean useHttps = getValue(USE_HTTPS, false);
    int timeout = getValue(CONN_TIMEOUT, 0);
    boolean clientAuth = getValue(CONN_SSL_CLIENT_AUTH, true);
    int maxActive = getValue(CONN_POOL_MAX_ACTIVE, 3);
    int maxIdle = getValue(CONN_POOL_MAX_IDLE, 3);
    long evictPeriod = getValue(CONN_POOL_EVICT_PERIOD, 60000L);
    long minIdleTime = getValue(CONN_POOL_MIN_IDLE_TIME, 90000L);
    retries = getValue(CONN_TIMEOUT_RETRIES, 3);
    pauseTime = getValue(PAUSE_BETWEEN_RETRIES, 100);
    delayAuthDecision = getValue(DELAY_AUTH_DECISION, false);
    includeCatalog = getValue(INCLUDE_SERVICE_CATALOG, true);
    adminAuthMethod = getValue(ADMIN_AUTH_METHOD, "");
    adminProjectId = getValue(ADMIN_PROJECT_ID, "");
    adminProjectName = getValue(ADMIN_PROJECT_NAME, "");
    adminUserDomainId = getValue(ADMIN_USER_DOMAIN_ID, "");
    adminUserDomainName = getValue(ADMIN_USER_DOMAIN_NAME, "");
    adminProjectDomainId = getValue(ADMIN_PROJECT_DOMAIN_ID, "");
    adminProjectDomainName = getValue(ADMIN_PROJECT_DOMAIN_NAME, "");
    timeToCacheToken = getValue(TIME_TO_CACHE_TOKEN, 600);
    long maxTokenCacheSize = getValue(MAX_TOKEN_CACHE_SIZE, 1048576);

    this.factory = AuthClientFactory.build(host, port, useHttps, timeout,
      clientAuth, keyStore, keyPass, trustStore, trustPass,
      maxActive, maxIdle, evictPeriod, minIdleTime, adminToken);

    verifyRequiredParamsForAuthMethod();
    this.client = new TokenCache(maxTokenCacheSize, timeToCacheToken);
    logger.info("Using https {}", useHttps);
    if (useHttps) {
      logger.info("Auth host (2-way SSL: " + clientAuth + "): " + host);
    }
    logger.info("Read Servlet Initialization Parameters ");
    initialized = true;
  } catch (Throwable t) {
    logger.error("Failure initializing connection to authentication endpoint : {}",
      t.getMessage());
    throw new ServletException(
      "Failure initializing connection to authentication endpoint  :: "
        + t.getMessage(), t);
  }
}
 
Example 17
Source File: AbstractKatharsisFilter.java    From katharsis-framework with Apache License 2.0 4 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
       servletContext = filterConfig.getServletContext();
       filterBasePath = filterConfig.getInitParameter(KatharsisProperties.WEB_PATH_PREFIX);
   }
 
Example 18
Source File: KatharsisFilter.java    From katharsis-framework with Apache License 2.0 4 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
	this.filterConfig = filterConfig;
	servletContext = filterConfig.getServletContext();
	filterBasePath = filterConfig.getInitParameter(KatharsisProperties.WEB_PATH_PREFIX);
}
 
Example 19
Source File: CacheFilter.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void init(FilterConfig config) throws ServletException {
	ServletContext context = config.getServletContext();
	String param;

	param = context.getInitParameter(CACHE_IDENTIFIERS);
	if (null != param) {
		cacheIdentifiers = param.split(PARAMETER_SPLIT_REGEX);
	}

	param = context.getInitParameter(CACHE_SUFFIXES);
	if (null != param) {
		cacheSuffixes = param.split(PARAMETER_SPLIT_REGEX);
	}

	param = context.getInitParameter(NO_CACHE_IDENTIFIERS);
	if (null != param) {
		noCacheIdentifiers = param.split(PARAMETER_SPLIT_REGEX);
	}

	param = context.getInitParameter(NO_CACHE_SUFFIXES);
	if (null != param) {
		noCacheSuffixes = param.split(PARAMETER_SPLIT_REGEX);
	}

	param = context.getInitParameter(ZIP_SUFFIXES);
	if (null != param) {
		zipSuffixes = param.split(PARAMETER_SPLIT_REGEX);
	}

	param = context.getInitParameter(SKIP_PREFIXES);
	if (null != param) {
		skipPrefixes = param.split(PARAMETER_SPLIT_REGEX);
	}

	param = context.getInitParameter(CACHE_DURATION_IN_SECONDS);
	if (null != param) {
		try {
			cacheDurationInSeconds = Integer.parseInt(param);
			cacheDurationInMilliSeconds = cacheDurationInSeconds * MS_IN_S;
		} catch (NumberFormatException nfe) {
			throw new ServletException("Cannot parse " + CACHE_DURATION_IN_SECONDS + " value " + param +
					", should be parable to integer", nfe);
		}

	}
}
 
Example 20
Source File: PortalDriverFilter.java    From portals-pluto with Apache License 2.0 2 votes vote down vote up
/**
 * Initialize the Portal Driver.
 * This method retrieves the portlet container instance
 * from the servlet context scope.
 *
 * @see org.apache.pluto.container.PortletContainer
 */
public void init(FilterConfig filterConfig) throws ServletException {
    servletContext = filterConfig.getServletContext();
    container = (PortletContainer) servletContext.getAttribute(
        AttributeKeys.PORTLET_CONTAINER);
}