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:org.apache.ranger.security.web.filter.RangerKrbFilter.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}./*w ww . j a v a 2 s. 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(); if (filterConfig != null) { Enumeration<?> names = filterConfig.getInitParameterNames(); if (names != null) { while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name != null && configPrefix != null && name.startsWith(configPrefix)) { String value = filterConfig.getInitParameter(name); props.put(name.substring(configPrefix.length()), value); } } } } return props; }
From source file:org.apache.atlas.web.filters.AtlasAuthenticationFilter.java
@Override public void initializeSecretProvider(FilterConfig filterConfig) throws ServletException { LOG.debug("AtlasAuthenticationFilter :: initializeSecretProvider {}", filterConfig); secretProvider = (SignerSecretProvider) filterConfig.getServletContext() .getAttribute(AuthenticationFilter.SIGNER_SECRET_PROVIDER_ATTRIBUTE); if (secretProvider == null) { // As tomcat cannot specify the provider object in the configuration. // It'll go into this path String configPrefix = filterConfig.getInitParameter(CONFIG_PREFIX); configPrefix = (configPrefix != null) ? configPrefix + "." : ""; try {/* w w w .ja v a2s. c o m*/ secretProvider = AuthenticationFilter.constructSecretProvider(filterConfig.getServletContext(), super.getConfiguration(configPrefix, filterConfig), false); this.isInitializedByTomcat = true; } catch (Exception ex) { throw new ServletException(ex); } } signer = new Signer(secretProvider); }
From source file:org.ajax4jsf.webapp.BaseFilter.java
/** * Initialize the filter./*from w w w . j ava 2 s.c om*/ */ public void init(FilterConfig config) throws ServletException { if (log.isDebugEnabled()) { log.debug("Init ajax4jsf filter with nane: " + config.getFilterName()); Enumeration<String> parameterNames = config.getInitParameterNames(); StringBuffer parameters = new StringBuffer("Init parameters :\n"); while (parameterNames.hasMoreElements()) { String name = parameterNames.nextElement(); parameters.append(name).append(" : '").append(config.getInitParameter(name)).append('\n'); } log.debug(parameters); // log.debug("Stack Trace", new Exception()); } // Save config filterConfig = config; setFunction((String) nz(filterConfig.getInitParameter(FUNCTION_NAME_PARAMETER), getFunction())); setAttributesNames(filterConfig.getInitParameter(ABSOLUTE_TAGS_PARAMETER)); xmlFilter.init(config); if ("true".equalsIgnoreCase(filterConfig.getInitParameter(REWRITEID_PARAMETER))) { this.setRewriteid(true); } resourceService = new InternetResourceService(); // Caching initialization. resourceService.init(filterConfig); eventsManager = new PollEventsManager(); eventsManager.init(filterConfig.getServletContext()); String param = filterConfig.getInitParameter("createTempFiles"); if (param != null) { this.createTempFiles = Boolean.parseBoolean(param); } else { this.createTempFiles = true; } param = filterConfig.getInitParameter("maxRequestSize"); if (param != null) { this.maxRequestSize = Integer.parseInt(param); } }
From source file:fedora.server.security.servletfilters.FilterSetup.java
public void init(FilterConfig filterConfig) { String method = "init() "; if (log.isDebugEnabled()) { log.debug(enter(method));//w ww . j ava 2s .co m } inited = false; initErrors = false; if (filterConfig != null) { FILTER_NAME = filterConfig.getFilterName(); if (FILTER_NAME == null || "".equals(FILTER_NAME)) { if (log.isErrorEnabled()) { log.error(format(method, "FILTER_NAME not set")); } } else { if (log.isDebugEnabled()) { log.debug(format(method, null, "FILTER_NAME", FILTER_NAME)); } Enumeration enumer = filterConfig.getInitParameterNames(); while (enumer.hasMoreElements()) { String key = (String) enumer.nextElement(); String value = filterConfig.getInitParameter(key); initThisSubclass(key, value); } inited = true; } } if (log.isDebugEnabled()) { log.debug(exit(method)); } }
From source file:org.alfresco.repo.webdav.auth.HTTPRequestAuthenticationFilter.java
/** * Initialize the filter// w w w .j a va 2 s . com * * @param config * FitlerConfig * @exception ServletException */ public void init(FilterConfig config) throws ServletException { // Save the context m_context = config.getServletContext(); // Setup the authentication context WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(m_context); ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); setNodeService(serviceRegistry.getNodeService()); setAuthenticationService(serviceRegistry.getAuthenticationService()); setTransactionService(serviceRegistry.getTransactionService()); setPersonService((PersonService) ctx.getBean("PersonService")); // transactional and permission-checked m_authComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); httpServletRequestAuthHeaderName = config.getInitParameter("httpServletRequestAuthHeaderName"); if (httpServletRequestAuthHeaderName == null) { httpServletRequestAuthHeaderName = "x-user"; } this.m_authPatternString = config.getInitParameter("authPatternString"); if (this.m_authPatternString != null) { try { m_authPattern = Pattern.compile(this.m_authPatternString); } catch (PatternSyntaxException e) { logger.warn("Invalid pattern: " + this.m_authPatternString, e); m_authPattern = null; } } }
From source file:org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter.java
@Override public void init(FilterConfig config) throws ServletException { String val = config.getInitParameter("byPassAuthenticationLog"); if (val != null && Boolean.parseBoolean(val)) { byPassAuthenticationLog = true;/* ww w . j av a2 s. c o m*/ } val = config.getInitParameter("securityDomain"); if (val != null) { securityDomain = val; } }
From source file:wicket.protocol.http.WicketFilter.java
/** * /*w w w . j a v a2 s . c om*/ * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) */ public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; IWebApplicationFactory factory = getApplicationFactory(); // Construct WebApplication subclass this.webApplication = factory.createApplication(this); // Set this WicketServlet as the servlet for the web application this.webApplication.setWicketFilter(this); // Store instance of this application object in servlet context to make // integration with outside world easier String contextKey = "wicket:" + filterConfig.getFilterName(); filterConfig.getServletContext().setAttribute(contextKey, this.webApplication); filterPath = filterConfig.getInitParameter(FILTER_PATH_PARAM); try { Application.set(webApplication); // Call internal init method of web application for default // initialisation this.webApplication.internalInit(); // Call init method of web application this.webApplication.init(); // We initialize components here rather than in the constructor or // in the internal init, because in the init method class aliases // can be added, that would be used in installing resources in the // component. this.webApplication.initializeComponents(); // Finished log.info("Wicket application " + this.webApplication.getName() + " started [factory=" + factory.getClass().getName() + "]"); } finally { Application.unset(); } }
From source file:esg.node.filters.AccessLoggingFilter.java
public void init(FilterConfig filterConfig) throws ServletException { System.out.println("Initializing filter: " + this.getClass().getName()); this.filterConfig = filterConfig; ESGFProperties esgfProperties = null; try {//from w ww . java 2s . c o m esgfProperties = new ESGFProperties(); } catch (java.io.IOException e) { e.printStackTrace(); log.error(e); } String value = null; dbProperties = new Properties(); log.debug("FilterConfig is : [" + filterConfig + "]"); log.debug("db.protocol is : [" + filterConfig.getInitParameter("db.protocol") + "]"); dbProperties.put("db.protocol", ((null != (value = filterConfig.getInitParameter("db.protocol"))) ? value : esgfProperties.getProperty("db.protocol"))); value = null; dbProperties.put("db.host", ((null != (value = filterConfig.getInitParameter("db.host"))) ? value : esgfProperties.getProperty("db.host"))); value = null; dbProperties.put("db.port", ((null != (value = filterConfig.getInitParameter("db.port"))) ? value : esgfProperties.getProperty("db.port"))); value = null; dbProperties.put("db.database", ((null != (value = filterConfig.getInitParameter("db.database"))) ? value : esgfProperties.getProperty("db.database"))); value = null; dbProperties.put("db.user", ((null != (value = filterConfig.getInitParameter("db.user"))) ? value : esgfProperties.getProperty("db.user"))); value = null; dbProperties.put("db.password", ((null != (value = filterConfig.getInitParameter("db.password"))) ? value : esgfProperties.getDatabasePassword())); value = null; dbProperties.put("db.driver", ((null != (value = filterConfig.getInitParameter("db.driver"))) ? value : esgfProperties.getProperty("db.driver", "org.postgresql.Driver"))); value = null; serviceName = (null != (value = filterConfig.getInitParameter("service.name"))) ? value : "thredds"; value = null; log.debug("Database parameters: " + dbProperties); DatabaseResource.init(dbProperties.getProperty("db.driver", "org.postgresql.Driver")) .setupDataSource(dbProperties); DatabaseResource.getInstance().showDriverStats(); accessLoggingDAO = new AccessLoggingDAO(DatabaseResource.getInstance().getDataSource()); //------------------------------------------------------------------------ // Extensions that this filter will handle... //------------------------------------------------------------------------ String extensionsParam = filterConfig.getInitParameter("extensions"); if (extensionsParam == null) { extensionsParam = ""; } //defensive program against null for this param String[] extensions = (".nc," + extensionsParam.toString()).split(","); StringBuffer sb = new StringBuffer(); for (int i = 0; i < extensions.length; i++) { sb.append(extensions[i].trim()); if (i < extensions.length - 1) sb.append("|"); } System.out.println("Applying filter for files with extensions: " + sb.toString()); String regex = "http.*(?:" + sb.toString() + ")$"; System.out.println("Regex = " + regex); urlExtensionPattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Extensions that this filter will NOT handle... //------------------------------------------------------------------------ String exemptExtensionsParam = filterConfig.getInitParameter("exempt_extensions"); if (exemptExtensionsParam == null) { exemptExtensionsParam = ""; } //defensive program against null for this param String[] exemptExtensions = (".xml," + exemptExtensionsParam.toString()).split(","); sb = new StringBuffer(); for (int i = 0; i < exemptExtensions.length; i++) { sb.append(exemptExtensions[i].trim()); if (i < exemptExtensions.length - 1) sb.append("|"); } System.out.println("Exempt extensions: " + sb.toString()); regex = "http.*(?:" + sb.toString() + ")$"; System.out.println("Exempt Regex = " + regex); exemptUrlPattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Patterns that this filter will NOT handle: Because the output is not file based... //------------------------------------------------------------------------ String exemptServiceParam = filterConfig.getInitParameter("exempt_services"); if (exemptServiceParam == null) { exemptServiceParam = "x"; } //defensive program against null for this param String[] exemptServiceParams = (exemptServiceParam.toString()).split(","); sb = new StringBuffer(); for (int i = 0; i < exemptServiceParams.length; i++) { sb.append(exemptServiceParams[i].trim()); if (i < exemptServiceParams.length - 1) sb.append("|"); } System.out.println("Exempt services: " + exemptServiceParam); String exemptServiceRegex = "http[s]?://([^:/]*)(:(?:[0-9]*))?/(?:" + sb.toString() + ")/(.*$)"; exemptServicePattern = Pattern.compile(exemptServiceRegex, Pattern.CASE_INSENSITIVE); System.out.println("Exempt Service Regex = " + exemptServiceRegex); //------------------------------------------------------------------------ log.trace(accessLoggingDAO.toString()); String svc_prefix = esgfProperties.getProperty("node.download.svc.prefix", "thredds/fileServer"); String mountedPathRegex = "http[s]?://([^:/]*)(:(?:[0-9]*))?/" + svc_prefix + "(.*$)"; mountedPathPattern = Pattern.compile(mountedPathRegex, Pattern.CASE_INSENSITIVE); String urlRegex = "http[s]?://([^:/]*)(:(?:[0-9]*))?/(.*$)"; urlPattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE); mpResolver = new MountedPathResolver((new esg.common.util.ESGIni()).getMounts()); }
From source file:uk.ac.ox.webauth.FilterWorker.java
public FilterWorker(HttpServletRequest request, HttpServletResponse response, FilterChain chain, FilterConfig config, LogWrapper logger, PrivateKeyManager privateKeyManager, Map<Thread, Filter.JAASData> jaas, String serviceToken, SecretKey sessionKey) { this.request = request; this.response = response; this.chain = chain; this.config = config; this.logger = logger; this.privateKeyManager = privateKeyManager; this.jaas = jaas; this.serviceToken = serviceToken; this.sessionKey = sessionKey; webAuthLoginURL = config.getInitParameter("WebAuthLoginURL"); rip = request.getRemoteAddr();/* w w w. ja v a 2 s . c o m*/ if (request.getCookies() != null) { for (Cookie c : request.getCookies()) { cookies.put(c.getName(), c); } } }
From source file:org.apache.solr.servlet.SolrDispatchFilter.java
@Override public void init(FilterConfig config) throws ServletException { log.trace("SolrDispatchFilter.init(): {}", this.getClass().getClassLoader()); SolrRequestParsers.fileCleaningTracker = new SolrFileCleaningTracker(); StartupLoggingUtils.checkLogDir();/*from www . j av a2s. c o m*/ logWelcomeBanner(); String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE); if (muteConsole != null && !Arrays.asList("false", "0", "off", "no").contains(muteConsole.toLowerCase(Locale.ROOT))) { StartupLoggingUtils.muteConsole(); } String logLevel = System.getProperty(SOLR_LOG_LEVEL); if (logLevel != null) { StartupLoggingUtils.changeLogLevel(logLevel); } String exclude = config.getInitParameter("excludePatterns"); if (exclude != null) { String[] excludeArray = exclude.split(","); excludePatterns = new ArrayList<>(); for (String element : excludeArray) { excludePatterns.add(Pattern.compile(element)); } } try { Properties extraProperties = (Properties) config.getServletContext().getAttribute(PROPERTIES_ATTRIBUTE); if (extraProperties == null) extraProperties = new Properties(); String solrHome = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE); ExecutorUtil.addThreadLocalProvider(SolrRequestInfo.getInheritableThreadLocalProvider()); this.cores = createCoreContainer( solrHome == null ? SolrResourceLoader.locateSolrHome() : Paths.get(solrHome), extraProperties); this.httpClient = cores.getUpdateShardHandler().getHttpClient(); setupJvmMetrics(); log.debug("user.dir=" + System.getProperty("user.dir")); } catch (Throwable t) { // catch this so our filter still works log.error("Could not start Solr. Check solr/home property and the logs"); SolrCore.log(t); if (t instanceof Error) { throw (Error) t; } } log.trace("SolrDispatchFilter.init() done"); }