Java Code Examples for javax.servlet.FilterConfig#getInitParameterNames()
The following examples show how to use
javax.servlet.FilterConfig#getInitParameterNames() .
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: GenericFilterBean.java From spring-analysis-note with MIT License | 6 votes |
/** * Create new FilterConfigPropertyValues. * @param config the FilterConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public FilterConfigPropertyValues(FilterConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from FilterConfig for filter '" + config.getFilterName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } }
Example 2
Source File: GenericFilterBean.java From java-technology-stack with MIT License | 6 votes |
/** * Create new FilterConfigPropertyValues. * @param config the FilterConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public FilterConfigPropertyValues(FilterConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from FilterConfig for filter '" + config.getFilterName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } }
Example 3
Source File: LogsearchKrbFilter.java From ambari-logsearch with Apache License 2.0 | 6 votes |
/** * 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}. * <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; }
Example 4
Source File: FilterBase.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void init(FilterConfig filterConfig) throws ServletException { Enumeration<String> paramNames = filterConfig.getInitParameterNames(); while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); if (!IntrospectionUtils.setProperty(this, paramName, filterConfig.getInitParameter(paramName))) { String msg = sm.getString("filterbase.noSuchProperty", paramName, this.getClass().getName()); if (isConfigProblemFatal()) { throw new ServletException(msg); } else { getLogger().warn(msg); } } } }
Example 5
Source File: TestRMWebServicesAppsModification.java From hadoop with Apache License 2.0 | 6 votes |
@Override protected Properties getConfiguration(String configPrefix, FilterConfig filterConfig) throws ServletException { Properties props = new Properties(); Enumeration<?> names = filterConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.startsWith(configPrefix)) { String value = filterConfig.getInitParameter(name); props.put(name.substring(configPrefix.length()), value); } } props.put(AuthenticationFilter.AUTH_TYPE, "simple"); props.put(PseudoAuthenticationHandler.ANONYMOUS_ALLOWED, "false"); return props; }
Example 6
Source File: SentryAuthFilter.java From incubator-sentry with Apache License 2.0 | 6 votes |
/** * Override <code>getConfiguration<code> to get <code>ALLOW_WEB_CONNECT_USERS<code>. */ @Override protected Properties getConfiguration(String configPrefix, FilterConfig filterConfig) throws ServletException { Properties props = new Properties(); Enumeration<?> names = filterConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.startsWith(configPrefix)) { String value = filterConfig.getInitParameter(name); if (ALLOW_WEB_CONNECT_USERS.equals(name)) { allowUsers = parseConnectUsersFromConf(value); } else { props.put(name.substring(configPrefix.length()), value); } } } return props; }
Example 7
Source File: DelegationTokenKerberosFilter.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Return the ProxyUser Configuration. FilterConfig properties beginning with * "solr.impersonator.user.name" will be added to the configuration. */ @Override protected Configuration getProxyuserConfiguration(FilterConfig filterConf) throws ServletException { Configuration conf = new Configuration(false); Enumeration<?> names = filterConf.getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.startsWith(KerberosPlugin.IMPERSONATOR_PREFIX)) { String value = filterConf.getInitParameter(name); conf.set(PROXYUSER_PREFIX + "." + name.substring(KerberosPlugin.IMPERSONATOR_PREFIX.length()), value); conf.set(name, value); } } return conf; }
Example 8
Source File: StreamlineResponseHeaderFilter.java From streamline with Apache License 2.0 | 5 votes |
@Override public void init(FilterConfig filterConfig) throws ServletException { Enumeration<String> names = filterConfig.getInitParameterNames(); while (names.hasMoreElements()) { String key = names.nextElement(); headers.put(key, filterConfig.getInitParameter(key)); } }
Example 9
Source File: CheCacheForcingFilter.java From che with Eclipse Public License 2.0 | 5 votes |
@Override public void init(FilterConfig filterConfig) { Enumeration<String> names = filterConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = names.nextElement(); if (name.startsWith("pattern")) { actionPatterns.add(Pattern.compile(filterConfig.getInitParameter(name))); } } }
Example 10
Source File: ServletUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Gets map of init-params from filter config. * Fill-in for missing java servlet API method. */ public static Map<String, String> getInitParams(FilterConfig filterConfig) { Map<String, String> initParams = new HashMap<>(); Enumeration<String> names = filterConfig.getInitParameterNames(); while(names.hasMoreElements()) { String name = names.nextElement(); initParams.put(name, filterConfig.getInitParameter(name)); } return initParams; }
Example 11
Source File: HttpParamDelegationTokenPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void init(Map<String, Object> pluginConfig) { try { final FilterConfig initConf = getInitFilterConfig(pluginConfig, true); FilterConfig conf = new FilterConfig() { @Override public ServletContext getServletContext() { return initConf.getServletContext(); } @Override public Enumeration<String> getInitParameterNames() { return initConf.getInitParameterNames(); } @Override public String getInitParameter(String param) { if (AuthenticationFilter.AUTH_TYPE.equals(param)) { return HttpParamDelegationTokenAuthenticationHandler.class.getName(); } return initConf.getInitParameter(param); } @Override public String getFilterName() { return "HttpParamFilter"; } }; Filter kerberosFilter = new HttpParamToRequestFilter(); kerberosFilter.init(conf); setKerberosFilter(kerberosFilter); } catch (ServletException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error initializing kerberos authentication plugin: "+e); } }
Example 12
Source File: HadoopAuthFilter.java From knox with Apache License 2.0 | 5 votes |
Properties getConfiguration(AliasService aliasService, String configPrefix, FilterConfig filterConfig) throws ServletException { String clusterName = filterConfig.getInitParameter("clusterName"); Properties props = new Properties(); Enumeration<String> names = filterConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = names.nextElement(); if (name.startsWith(configPrefix)) { String value = filterConfig.getInitParameter(name); // Handle the case value is an alias if (value.startsWith("${ALIAS=") && value.endsWith("}")) { String alias = value.substring("${ALIAS=".length(), value.length() - 1); try { value = String.valueOf( aliasService.getPasswordFromAliasForCluster(clusterName, alias)); } catch (AliasServiceException e) { throw new ServletException("Unable to retrieve alias for config: " + name, e); } } props.put(name.substring(configPrefix.length()), value); } } return props; }
Example 13
Source File: OneConfig.java From hasor with Apache License 2.0 | 5 votes |
public void putConfig(FilterConfig config, boolean overwrite) { Enumeration<?> names = config.getInitParameterNames(); if (names != null) { while (names.hasMoreElements()) { String name = names.nextElement().toString(); this.computeIfAbsent(name, s -> overwrite ? config.getInitParameter(name) : s); } } }
Example 14
Source File: ResponseHeaderFilter.java From sakai with Educational Community License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public void init(FilterConfig filterConfig) throws ServletException { String webappName = filterConfig.getServletContext().getServletContextName(); // storing the header information in a local map for (Enumeration<String> paramNames = filterConfig.getInitParameterNames(); paramNames.hasMoreElements(); ) { String paramName = paramNames.nextElement(); String paramValue = filterConfig.getInitParameter(paramName); if (paramName != null && paramValue != null) { this.headerMap.put(paramName, paramValue); } } // adding the configured ones from sakai config ServerConfigurationService serverConfigurationService = org.sakaiproject.component.cover.ServerConfigurationService.getInstance(); if (serverConfigurationService != null) { String[] headerStrings = serverConfigurationService.getStrings("response.headers"); if (headerStrings != null) { for (String headerString : headerStrings) { if (headerString != null && ! "".equals(headerString)) { int loc = headerString.indexOf("::"); if (loc <= 0) { log.warn("Invalid header string in sakai config (must contain '::', e.g. key::value): " + headerString); continue; } String name = headerString.substring(0, loc); if (name == null || "".equals(name)) { log.warn("Invalid header string in sakai config (name must not be empty): " + headerString); continue; } String value = null; if (headerString.length() > loc+2) { value = headerString.substring(loc+2); } addHeader(name, value); if (value == null) { log.info("Removing header ("+name+") from all responses for current webapp: " + webappName); } else { log.info("Adding header ("+name+" -> "+value+") to all responses for current webapp: " + webappName); } } } } } log.info("INIT: for webapp " + webappName); }
Example 15
Source File: FilterDefinitionTest.java From dagger-servlet with Apache License 2.0 | 4 votes |
@Test public final void testFilterInitFilterInstance() throws ServletException { ObjectGraph objectGraph = createStrictMock(ObjectGraph.class); final MockFilter mockFilter = new MockFilter(); replay(objectGraph); //some init params //noinspection SSBasedInspection final Map<String, String> initParams = new HashMap<String, String>() {{ put("ahsd", "asdas24dok"); put("ahssd", "asdasd124ok"); put("ahfsasd", "asda124sdok"); put("ahsasgd", "a124sdasdok"); put("ahsd124124", "as124124124dasdok"); }}; ServletContext servletContext = createMock(ServletContext.class); final String contextName = "thing__!@@44"; expect(servletContext.getServletContextName()).andReturn(contextName); replay(servletContext); String pattern = "/*"; final FilterDefinition filterDef = new FilterDefinition(pattern, Filter.class, UriPatternType.get(UriPatternType.SERVLET, pattern), initParams, mockFilter); filterDef.init(servletContext, objectGraph, Sets.newSetFromMap(Maps.<Filter, Boolean>newIdentityHashMap())); assertTrue(filterDef.getFilter() instanceof MockFilter); assertEquals(filterDef.getFilter(), mockFilter); final FilterConfig filterConfig = mockFilter.getConfig(); assertNotNull(filterConfig); assertEquals(filterConfig.getServletContext().getServletContextName(), contextName); assertEquals(filterConfig.getFilterName(), Filter.class.getCanonicalName()); final Enumeration names = filterConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); assertTrue(initParams.containsKey(name)); assertTrue(initParams.get(name).equals(filterConfig.getInitParameter(name))); } verify(objectGraph, servletContext); }
Example 16
Source File: ResponseHeaderFilter.java From sakai with Educational Community License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public void init(FilterConfig filterConfig) throws ServletException { String webappName = filterConfig.getServletContext().getServletContextName(); // storing the header information in a local map for (Enumeration<String> paramNames = filterConfig.getInitParameterNames(); paramNames.hasMoreElements(); ) { String paramName = paramNames.nextElement(); String paramValue = filterConfig.getInitParameter(paramName); if (paramName != null && paramValue != null) { this.headerMap.put(paramName, paramValue); } } // adding the configured ones from sakai config ServerConfigurationService serverConfigurationService = org.sakaiproject.component.cover.ServerConfigurationService.getInstance(); if (serverConfigurationService != null) { String[] headerStrings = serverConfigurationService.getStrings("response.headers"); if (headerStrings != null) { for (String headerString : headerStrings) { if (headerString != null && ! "".equals(headerString)) { int loc = headerString.indexOf("::"); if (loc <= 0) { log.warn("Invalid header string in sakai config (must contain '::', e.g. key::value): " + headerString); continue; } String name = headerString.substring(0, loc); if (name == null || "".equals(name)) { log.warn("Invalid header string in sakai config (name must not be empty): " + headerString); continue; } String value = null; if (headerString.length() > loc+2) { value = headerString.substring(loc+2); } addHeader(name, value); if (value == null) { log.info("Removing header ("+name+") from all responses for current webapp: " + webappName); } else { log.info("Adding header ("+name+" -> "+value+") to all responses for current webapp: " + webappName); } } } } } log.info("INIT: for webapp " + webappName); }
Example 17
Source File: NtlmHttpFilter.java From jcifs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void init ( FilterConfig filterConfig ) throws ServletException { String name; Properties p = new Properties(); /* * Set jcifs properties we know we want; soTimeout and cachePolicy to 30min. */ p.setProperty("jcifs.smb.client.soTimeout", "1800000"); p.setProperty("jcifs.netbios.cachePolicy", "1200"); /* * The Filter can only work with NTLMv1 as it uses a man-in-the-middle * technique that NTLMv2 specifically thwarts. A real NTLM Filter would * need to do a NETLOGON RPC that JCIFS will likely never implement * because it requires a lot of extra crypto not used by CIFS. */ p.setProperty("jcifs.smb.lmCompatibility", "0"); p.setProperty("jcifs.smb.client.useExtendedSecurity", "false"); Enumeration<String> e = filterConfig.getInitParameterNames(); while ( e.hasMoreElements() ) { name = e.nextElement(); if ( name.startsWith("jcifs.") ) { p.setProperty(name, filterConfig.getInitParameter(name)); } } try { this.defaultDomain = p.getProperty("jcifs.smb.client.domain"); this.domainController = p.getProperty("jcifs.http.domainController"); if ( this.domainController == null ) { this.domainController = this.defaultDomain; this.loadBalance = Config.getBoolean(p, "jcifs.http.loadBalance", true); } this.enableBasic = Boolean.valueOf(p.getProperty("jcifs.http.enableBasic")).booleanValue(); this.insecureBasic = Boolean.valueOf(p.getProperty("jcifs.http.insecureBasic")).booleanValue(); this.realm = p.getProperty("jcifs.http.basicRealm"); this.netbiosLookupRespLimit = Config.getInt(p, "jcifs.netbios.lookupRespLimit", 3); this.netbiosCacheTimeout = Config.getInt(p, "jcifs.netbios.cachePolicy", 60 * 10) * 60; /* 10 hours */ if ( this.realm == null ) this.realm = "jCIFS"; this.transportContext = new BaseContext(new PropertyConfiguration(p)); } catch ( CIFSException ex ) { throw new ServletException("Failed to initialize CIFS context"); } }
Example 18
Source File: HadoopGroupProviderFilter.java From knox with Apache License 2.0 | 4 votes |
@Override public void init(final FilterConfig filterConfig) throws ServletException { super.init(filterConfig); try { hadoopConfig = new Configuration(false); if (filterConfig.getInitParameterNames() != null) { for (final Enumeration<String> keys = filterConfig .getInitParameterNames(); keys.hasMoreElements();) { final String key = keys.nextElement(); hadoopConfig.set(key, filterConfig.getInitParameter(key)); } } hadoopGroups = new Groups(hadoopConfig); } catch (final Exception e) { throw new ServletException(e); } }
Example 19
Source File: AuthenticationFilter.java From big-c with Apache License 2.0 | 3 votes |
/** * 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}. * <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(); Enumeration<?> names = filterConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.startsWith(configPrefix)) { String value = filterConfig.getInitParameter(name); props.put(name.substring(configPrefix.length()), value); } } return props; }
Example 20
Source File: AuthenticationFilter.java From hadoop with Apache License 2.0 | 3 votes |
/** * 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}. * <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(); Enumeration<?> names = filterConfig.getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.startsWith(configPrefix)) { String value = filterConfig.getInitParameter(name); props.put(name.substring(configPrefix.length()), value); } } return props; }