List of usage examples for javax.servlet FilterConfig getInitParameter
public String getInitParameter(String name);
String
containing the value of the named initialization parameter, or null
if the initialization parameter does not exist. From source file:com.github.safrain.remotegsh.server.RgshFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { if (filterConfig.getInitParameter("charset") != null) { charset = filterConfig.getInitParameter("charset"); } else {//from w w w . j av a 2s . com charset = DEFAULT_CHARSET; } if (filterConfig.getInitParameter("shellSessionTimeout") != null) { shellSessionTimeout = Long.valueOf(filterConfig.getInitParameter("shellSessionTimeout")); } else { shellSessionTimeout = SESSION_PURGE_INTERVAL; } String scriptExtensionCharset; if (filterConfig.getInitParameter("scriptExtensionCharset") != null) { scriptExtensionCharset = filterConfig.getInitParameter("scriptExtensionCharset"); } else { scriptExtensionCharset = DEFAULT_CHARSET; } //Compile script extensions List<String> scriptExtensionPaths = new ArrayList<String>(); if (filterConfig.getInitParameter("scriptExtensions") != null) { Collections.addAll(scriptExtensionPaths, filterConfig.getInitParameter("scriptExtensions").split(",")); } else { scriptExtensionPaths.add(RESOURCE_PATH + "extension/spring.groovy"); } scriptExtensions = new HashMap<String, CompiledScript>(); for (String path : scriptExtensionPaths) { String scriptContent; try { scriptContent = getResource(path, scriptExtensionCharset); } catch (IOException e) { throw new ServletException(e); } Compilable compilable = (Compilable) createGroovyEngine(); try { CompiledScript compiledScript = compilable.compile(scriptContent); scriptExtensions.put(path, compiledScript); } catch (ScriptException e) { //Ignore exceptions while compiling script extensions,there may be compilation errors due to missing dependency log.log(Level.WARNING, String.format("Error compiling script extension '%s'", path), e); } } // Setup a timer to purge timeout shell sessions Timer timer = new Timer("Remote Groovy Shell session purge daemon", true); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { purgeTimeOutSessions(); } }, 0, SESSION_PURGE_INTERVAL); }
From source file:com.qut.middleware.spep.filter.SPEPFilter.java
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; this.spepContextName = filterConfig.getInitParameter(SPEP_CONTEXT_PARAM_NAME); if (this.spepContextName == null) throw new ServletException(Messages.getString("SPEPFilter.8") + SPEP_CONTEXT_PARAM_NAME); //$NON-NLS-1$ }
From source file:org.ajax4jsf.resource.InternetResourceService.java
public void init(FilterConfig config) throws ServletException { filterConfig = config;//ww w . j a va2 s.c o m ServletContext servletContext = config.getServletContext(); if ("false".equalsIgnoreCase(config.getInitParameter(ENABLE_CACHING_PARAMETER))) { setCacheEnabled(false); // this.cacheEnabled = false; // this.cacheAdmin = null; } else { // this.cacheAdmin = ServletCacheAdministrator.getInstance( // servletContext, cacheProperties); try { CacheManager cacheManager = CacheManager.getInstance(); Map<String, String> env = new ServletContextInitMap(servletContext); CacheFactory cacheFactory = cacheManager.getCacheFactory(env); this.cache = cacheFactory.createCache(env, this, this); } catch (CacheException e) { throw new FacesException(e.getMessage(), e); } } // Create Resource-specific Faces Lifecycle instance. lifecycleClass = servletContext.getInitParameter(RESOURCE_LIFECYCLE_PARAMETER); if (lifecycleClass != null) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { Class<?> clazz = classLoader.loadClass(lifecycleClass); lifecycle = (ResourceLifecycle) clazz.newInstance(); } catch (Exception e) { throw new FacesException("Error create instance of resource Lifecycle " + lifecycleClass, e); } } else { lifecycle = new ResourceLifecycle(); } webXml = new WebXml(); webXml.init(servletContext, filterConfig.getFilterName()); if (log.isDebugEnabled()) { log.debug("Resources service initialized"); } }
From source file:org.sakaiproject.tool.gradebook.ui.RoleFilter.java
public void init(FilterConfig filterConfig) throws ServletException { if (logger.isInfoEnabled()) logger.info("Initializing gradebook role filter"); ac = (ApplicationContext) filterConfig.getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); authnServiceBeanName = filterConfig.getInitParameter("authnServiceBean"); authzServiceBeanName = filterConfig.getInitParameter("authzServiceBean"); contextManagementServiceBeanName = filterConfig.getInitParameter("contextManagementServiceBean"); authorizationFilterConfigurationBeanName = filterConfig .getInitParameter("authorizationFilterConfigurationBean"); selectGradebookRedirect = filterConfig.getInitParameter("selectGradebookRedirect"); }
From source file:org.ambraproject.cas.client.filter.CASFilterWrapper.java
/** * @see javax.servlet.Servlet/*from w w w .j a v a 2 s.co m*/ */ public void init(final FilterConfig filterConfig) throws ServletException { final Map<String, String> params = new HashMap<String, String>(6); final InitParamProvider initParamProvider = new InitParamProvider() { public Enumeration<?> getInitParameterNames() { return filterConfig.getInitParameterNames(); } public String getInitParameter(final String key) { return filterConfig.getInitParameter(key); } }; ConfigWrapperUtil.copyInitParams(initParamProvider, params); final Configuration configuration = ConfigurationStore.getInstance().getConfiguration(); final String ambraServerHost = configuration.getString("ambra.platform.host"); final String casProxyValidateUrl = configuration.getString("ambra.services.cas.url.proxy-validate"); final String casLoginUrl = configuration.getString("ambra.services.cas.url.login"); ConfigWrapperUtil.setInitParamValue(CASFilter.LOGIN_INIT_PARAM, casLoginUrl, initParamProvider, params); ConfigWrapperUtil.setInitParamValue(CASFilter.VALIDATE_INIT_PARAM, casProxyValidateUrl, initParamProvider, params); ConfigWrapperUtil.setInitParamValue(CASFilter.SERVERNAME_INIT_PARAM, ambraServerHost, initParamProvider, params); final FilterConfig customFilterConfig = new ConfigWrapper(filterConfig, params); super.init(customFilterConfig); }
From source file:org.apache.hadoop.security.authentication.server.AuthenticationFilter.java
/** * Initializes the authentication filter. * <p/>//from w w w.j a v a2s.c o m * It instantiates and initializes the specified {@link AuthenticationHandler}. * <p/> * * @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 + "." : ""; Properties config = getConfiguration(configPrefix, filterConfig); String authHandlerName = config.getProperty(AUTH_TYPE, null); String authHandlerClassName; if (authHandlerName == null) { throw new ServletException("Authentication type must be specified: simple|kerberos|<class>"); } if (authHandlerName.equals("simple")) { authHandlerClassName = PseudoAuthenticationHandler.class.getName(); } else if (authHandlerName.equals("kerberos")) { authHandlerClassName = KerberosAuthenticationHandler.class.getName(); } else { authHandlerClassName = authHandlerName; } try { Class<?> klass = Thread.currentThread().getContextClassLoader().loadClass(authHandlerClassName); authHandler = (AuthenticationHandler) klass.newInstance(); authHandler.init(config); } catch (ClassNotFoundException ex) { throw new ServletException(ex); } catch (InstantiationException ex) { throw new ServletException(ex); } catch (IllegalAccessException ex) { throw new ServletException(ex); } String signatureSecret = config.getProperty(configPrefix + SIGNATURE_SECRET); if (signatureSecret == null) { signatureSecret = Long.toString(RAN.nextLong()); randomSecret = true; LOG.warn("'signature.secret' configuration not set, using a random value as secret"); } signer = new Signer(signatureSecret.getBytes()); validity = Long.parseLong(config.getProperty(AUTH_TOKEN_VALIDITY, "36000")) * 1000; //10 hours cookieDomain = config.getProperty(COOKIE_DOMAIN, null); cookiePath = config.getProperty(COOKIE_PATH, null); }
From source file:org.echocat.jemoni.jmx.support.ServletHealth.java
protected void handleHostIncludeExcludesIfNeeded(@Nonnull FilterConfig filterConfig) { final String includeHosts = filterConfig.getInitParameter(INCLUDES_HOSTS); final String excludeHosts = filterConfig.getInitParameter(EXCLUDES_HOSTS); if (!isEmpty(includeHosts) || !isEmpty(excludeHosts)) { final ServletHealthInterceptor originalInterceptor = getInterceptor(); final AllowedHostsServletHealthInterceptor newInterceptor = new AllowedHostsServletHealthInterceptor(); newInterceptor.setIncludesPattern(includeHosts); newInterceptor.setExcludesPattern(excludeHosts); setInterceptor(originalInterceptor != null ? new CombinedServletHealthInterceptor(originalInterceptor, newInterceptor) : newInterceptor);/*from w w w.j a v a 2s.c o m*/ } }
From source file:com.yahoo.yos.YahooFilter.java
/** * Set the 'oauth' init parameter for this filter to change from the default * oauth.properties resource for configuration. The file should define: * <p/>/*from w w w .j a va2 s. c om*/ * yos.consumerKey=... * yos.consumerSecret=... * oauth.requesttoken.url=https://api.login.yahoo.com/oauth/v2/get_request_token * oauth.requestauth.url=https://api.login.yahoo.com/oauth/v2/request_auth * oauth.accesstoken.url=https://api.login.yahoo.com/oauth/v2/get_token * oauth.callback.url=http://myapplication:8080/ * <p/> * To access production OAuth services from Yahoo. This filter relies on session * information stored by cookies to operate. * * @param filterConfig see upstream docs * @throws ServletException */ public void init(FilterConfig filterConfig) throws ServletException { String filename = filterConfig.getInitParameter("oauth"); if (filename == null) { filename = "oauth.properties"; } logger.debug("oauth properties file: {}", filename); oauthConfig = new Properties(); try { oauthConfig.load(getClass().getResourceAsStream("/" + filename)); } catch (IOException e) { throw new ServletException("Could not load oauth properties from resource: " + filename, e); } String redirectString = filterConfig.getInitParameter("redirect"); // defaults to redirect if null, zero-length redirect = redirectString == null || redirectString.trim().length() <= 0 || "true".equalsIgnoreCase(redirectString.trim()); logger.debug("redirect if access token not found: {}", redirect); String oauthConnectionClass = filterConfig.getInitParameter("oauthConnectionClass"); if (oauthConnectionClass == null) { oauthConnectionClass = "net.oauth.client.URLConnectionClient"; } logger.debug("oauth client connection class: {}", oauthConnectionClass); try { client = new OAuthClient((HttpClient) Class.forName(oauthConnectionClass).newInstance()); } catch (Exception cce) { throw new ServletException("unable to create OAuthClient from: " + oauthConnectionClass, cce); } provider = new OAuthServiceProvider( oauthConfig.getProperty("oauth.requesttoken.url", "https://api.login.yahoo.com/oauth/v2/get_request_token"), oauthConfig.getProperty("oauth.requestauth.url", "https://api.login.yahoo.com/oauth/v2/request_auth"), oauthConfig.getProperty("oauth.accesstoken.url", "https://api.login.yahoo.com/oauth/v2/get_token")); consumer = new OAuthConsumer(oauthConfig.getProperty("oauth.callback.url"), oauthConfig.getProperty("yos.consumerKey"), oauthConfig.getProperty("yos.consumerSecret"), provider); consumer.setProperty("oauth_signature_method", oauthConfig.getProperty("yos.oauth_signature_method", "HMAC-SHA1")); callbackUrl = oauthConfig.getProperty("oauth.callback.url", ""); }
From source file:org.squale.jraf.provider.persistence.hibernate.HibernateFilter.java
public void init(FilterConfig filterConfig) throws ServletException { // providers// w w w.jav a 2s . c o m String providers = filterConfig.getInitParameter(PERSISTENCE_PROVIDER_INIT); if (providers != null) { // map de providers Map mProviders = getProviders(providers); // on fixe la map de providers setProvidersMap(mProviders); } else { log.debug("Aucun provider en parametre"); } }
From source file:com.mirantis.cachemod.filter.CacheConfiguration.java
public CacheConfiguration(FilterConfig config) { alreadyFilteredKey = ALREADY_FILTERED_KEY + config.getFilterName(); String fragmentParam = config.getInitParameter("fragment"); if (fragmentParam != null) { if ("no".equalsIgnoreCase(fragmentParam)) { fragment = FragmentType.NO;//w w w. ja v a 2s. c o m } else if ("yes".equalsIgnoreCase(fragmentParam)) { fragment = FragmentType.YES; } else if ("auto".equalsIgnoreCase(fragmentParam)) { fragment = FragmentType.AUTO; } else { log.error("CacheFilter: Wrong value '" + fragmentParam + "' for init parameter 'fragment', default is 'auto'."); } } String escapeSessionIdParam = config.getInitParameter("escapeSessionId"); if (escapeSessionIdParam != null) { if ("on".equalsIgnoreCase(escapeSessionIdParam)) { escapeSessionId = true; } else if ("off".equalsIgnoreCase(escapeSessionIdParam)) { escapeSessionId = false; } else { log.error("CacheFilter: Wrong value '" + escapeSessionIdParam + "' for init parameter 'escapeSessionId', default is 'no'."); } } String escapeMethodsParam = config.getInitParameter("escapeMethods"); if (escapeMethodsParam != null && escapeMethodsParam.length() > 0) { StringTokenizer tokenizer = new StringTokenizer(escapeMethodsParam); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken().trim(); if (token != null && token.length() > 0) { escapeMethods.add(token.toUpperCase()); } } } String timeParam = config.getInitParameter("time"); if (timeParam != null) { try { time = Integer.parseInt(timeParam); } catch (NumberFormatException nfe) { log.error("CacheFilter: Unexpected value for the init parameter 'time', default is '60'. Message=" + nfe.getMessage()); } } String lastModifiedParam = config.getInitParameter("lastModified"); if (lastModifiedParam != null) { if ("on".equalsIgnoreCase(lastModifiedParam)) { lastModified = LastModifiedType.ON; } else if ("off".equalsIgnoreCase(lastModifiedParam)) { lastModified = LastModifiedType.OFF; } else if ("initial".equalsIgnoreCase(lastModifiedParam)) { lastModified = LastModifiedType.INITIAL; } else { log.error( "CacheFilter: Invalid parameter 'lastModified'. Expected 'on', 'off' or 'initial'. Be default is 'initial'."); } } String expiresParam = config.getInitParameter("expires"); if (expiresParam != null) { if ("on".equalsIgnoreCase(expiresParam)) { expires = ExpiresType.ON; } else if ("off".equalsIgnoreCase(expiresParam)) { expires = ExpiresType.OFF; } else if ("time".equalsIgnoreCase(expiresParam)) { expires = ExpiresType.TIME; } else { log.error( "CacheFilter: Invalid parameter 'expires'. Expected 'on', 'off' or 'time'. Be default is 'on'."); } } String maxAgeParam = config.getInitParameter("max-age"); if (maxAgeParam != null) { if (maxAgeParam.equalsIgnoreCase("no init")) { maxAgeType = MaxAgeType.NO_INIT; } else if (maxAgeParam.equalsIgnoreCase("time")) { maxAgeType = MaxAgeType.TIME; } else { try { maxAgeType = MaxAgeType.NUMBER; maxAge = Long.parseLong(maxAgeParam); if (maxAge < 0) { log.error( "CacheFilter: 'max-age' parameter must be at least a positive integer, default is '60'."); maxAge = 60; } } catch (NumberFormatException nfe) { log.error( "CacheFilter: Unexpected value for the init parameter 'max-age', default is '60'. Message=" + nfe.getMessage()); } } } CacheProvider cacheProviderParam = (CacheProvider) initClass(config, "CacheProvider", CacheProvider.class); if (cacheProviderParam != null) { this.cacheProvider = cacheProviderParam; } else { this.cacheProvider = new LRUCacheProvider(); } KeyProvider cacheKeyProviderParam = (KeyProvider) initClass(config, "KeyProvider", KeyProvider.class); if (cacheKeyProviderParam != null) { this.cacheKeyProvider = cacheKeyProviderParam; } else { this.cacheKeyProvider = new HashedKeyProvider(); } UserDataProvider userDataProviderParam = (UserDataProvider) initClass(config, "UserDataProvider", UserDataProvider.class); if (userDataProviderParam != null) { this.userDataProvider = userDataProviderParam; } this.cacheName = config.getInitParameter("cacheName"); if (cacheName == null) { this.cacheName = DEF_CACHE_NAME; } }