Example usage for javax.servlet FilterConfig getInitParameterNames

List of usage examples for javax.servlet FilterConfig getInitParameterNames

Introduction

In this page you can find the example usage for javax.servlet FilterConfig getInitParameterNames.

Prototype

public Enumeration<String> getInitParameterNames();

Source Link

Document

Returns the names of the filter's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the filter has no initialization parameters.

Usage

From source file:edu.vt.middleware.servlet.filter.SessionAttributeFilter.java

/**
 * Initialize this filter./*from  w  w  w. j  a v a  2  s . c om*/
 *
 * @param  config  <code>FilterConfig</code>
 */
public void init(final FilterConfig config) {
    this.context = config.getServletContext();
    this.requireAttribute = Boolean.valueOf(config.getInitParameter(REQUIRE_ATTRIBUTE)).booleanValue();
    if (LOG.isDebugEnabled()) {
        LOG.debug("requireAttribute = " + this.requireAttribute);
    }

    final Enumeration<?> e = config.getInitParameterNames();
    while (e.hasMoreElements()) {
        final String name = (String) e.nextElement();
        if (!name.equals(REQUIRE_ATTRIBUTE)) {
            final String value = config.getInitParameter(name);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Loaded attribute name:value " + name + ":" + value);
            }

            final StringTokenizer st = new StringTokenizer(name);
            final String attrName = st.nextToken();
            final String attrValue = st.nextToken();

            this.attributes.put(attrName, Pattern.compile(attrValue));
            this.redirects.put(attrName, value);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Stored attribute " + attrName + " for pattern " + attrValue + " with redirect of "
                        + value);
            }
        }
    }
}

From source file:org.energyos.espi.thirdparty.web.filter.CORSFilter.java

public void init(FilterConfig cfg) throws ServletException {

    // Process origin parameters
    String regex = cfg.getInitParameter("allow.origin.regex");
    if (regex != null) {
        allowOriginRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    } else {/*w  w  w  .  j a v a2 s . c  om*/
        allowOrigin = cfg.getInitParameter("allow.origin");
        if (allowOrigin != null) {
            optionsHeaders.put("Access-Control-Allow-Origin", allowOrigin);
        }
    }

    // Process optional header parameters
    for (Enumeration<String> i = cfg.getInitParameterNames(); i.hasMoreElements();) {
        String name = i.nextElement();
        if (name.startsWith("header:")) {
            optionsHeaders.put(name.substring(7), cfg.getInitParameter(name));
        }
    }

    // Process Credential support parameter
    allowCredentials = cfg.getInitParameter("allow.credentials");

    // Process Expose header parameter
    exposeHeaders = cfg.getInitParameter("expose.headers");

    // Initialize default header values
    optionsHeaders.put("Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type");
    optionsHeaders.put("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    optionsHeaders.put("Access-Control-Max-Age", "1800");

}

From source file:org.energyos.espi.datacustodian.web.filter.CORSFilter.java

@SuppressWarnings("unchecked")
// TODO: fix the class problem
public void init(FilterConfig cfg) throws ServletException {

    // Process origin parameters
    String regex = cfg.getInitParameter("allow.origin.regex");
    if (regex != null) {
        allowOriginRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    } else {/*  ww  w.  j a va2s . com*/
        allowOrigin = cfg.getInitParameter("allow.origin");
        if (allowOrigin != null) {
            optionsHeaders.put("Access-Control-Allow-Origin", allowOrigin);
        }
    }

    // Process optional header parameters
    for (Enumeration<String> i = cfg.getInitParameterNames(); i.hasMoreElements();) {
        String name = i.nextElement();
        if (name.startsWith("header:")) {
            optionsHeaders.put(name.substring(7), cfg.getInitParameter(name));
        }
    }

    // Process Credential support parameter
    allowCredentials = cfg.getInitParameter("allow.credentials");

    // Process Expose header parameter
    exposeHeaders = cfg.getInitParameter("expose.headers");

    // Initialize default header values
    optionsHeaders.put("Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type");
    optionsHeaders.put("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    optionsHeaders.put("Access-Control-Max-Age", "1800");

}

From source file:org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter.java

/**
 * Returns the proxyuser configuration. All returned properties must start
 * with <code>proxyuser.</code>'
 * <p/>/*from   w w  w. j  a va 2 s.com*/
 * Subclasses may override this method if the proxyuser configuration is 
 * read from other place than the filter init parameters.
 *
 * @param filterConfig filter configuration object
 * @return the proxyuser configuration properties.
 * @throws ServletException thrown if the configuration could not be created.
 */
protected Configuration getProxyuserConfiguration(FilterConfig filterConfig) throws ServletException {
    // this filter class gets the configuration from the filter configs, we are
    // creating an empty configuration and injecting the proxyuser settings in
    // it. In the initialization of the filter, the returned configuration is
    // passed to the ProxyUsers which only looks for 'proxyusers.' properties.
    Configuration conf = new Configuration(false);
    Enumeration<?> names = filterConfig.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (name.startsWith(PROXYUSER_PREFIX + ".")) {
            String value = filterConfig.getInitParameter(name);
            conf.set(name, value);
        }
    }
    return conf;
}

From source file:fedora.server.security.servletfilters.FilterSetup.java

public void init(FilterConfig filterConfig) {
    String method = "init() ";
    if (log.isDebugEnabled()) {
        log.debug(enter(method));//www  . j  ava2s  .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.withinsea.izayoi.adapter.springmvc.SpringIzayoiDispatcherFilter.java

@Override
public void init(final FilterConfig filterConfig) throws ServletException {

    cloister = new Cloister();
    glowworm = new Glowworm();
    cortile = new Cortile();
    izayoiInterceptor = new SpringGlowwormInterceptor(glowworm);
    izayoiViewResolver = new SpringCloisterCortileViewResolver(cortile, cloister);

    super.init(new ServletConfig() {

        @Override/*  ww  w . j a va 2s.  com*/
        public String getInitParameter(String s) {
            return filterConfig.getInitParameter(s);
        }

        @Override
        public String getServletName() {
            return filterConfig.getFilterName();
        }

        @Override
        public ServletContext getServletContext() {
            return filterConfig.getServletContext();
        }

        @Override
        @SuppressWarnings("unchecked")
        public Enumeration<String> getInitParameterNames() {
            return filterConfig.getInitParameterNames();
        }
    });

    ApplicationContext appctx = getWebApplicationContext();
    ServletContext servletContext = filterConfig.getServletContext();
    Map<String, String> overriddenProperties = ServletFilterUtils.getParamsMap(filterConfig);

    IzayoiContainer container = new IzayoiContainerFactory().addBeanSource(new SpringBeanSource(appctx))
            .addModule("org.withinsea.izayoi.core").addModule("org.withinsea.izayoi.cloister")
            .addModule("org.withinsea.izayoi.glowworm").addModule("org.withinsea.izayoi.cortile")
            .addModule("org.withinsea.izayoi.adapter.springmvc").create(servletContext, overriddenProperties);

    cloister.init(container);
    glowworm.init(container);
    cortile.init(container);
}

From source file:coyote.commons.web.AuthFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    context = filterConfig.getServletContext();
    LOG.info("Servlet Context:" + context);

    applicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
    LOG.info("Spring Context:" + applicationContext);

    @SuppressWarnings("rawtypes")
    Enumeration initNames = context.getInitParameterNames();
    if (initNames != null) {
        while (initNames.hasMoreElements()) {
            String name = (String) initNames.nextElement();
            String value = filterConfig.getInitParameter(name);
            LOG.trace("Init:" + name + ":" + value);
        }//from  ww  w.jav  a 2 s.c  o  m
    }

    @SuppressWarnings("rawtypes")
    Enumeration attrNames = context.getAttributeNames();
    if (attrNames != null) {
        while (attrNames.hasMoreElements()) {
            String name = (String) attrNames.nextElement();
            String value = filterConfig.getInitParameter(name);
            LOG.trace("Attr:" + name + ":" + value);
        }
    }

    @SuppressWarnings("rawtypes")
    Enumeration initParams = filterConfig.getInitParameterNames();
    if (initParams != null) {
        while (initParams.hasMoreElements()) {
            String name = (String) initParams.nextElement();
            String value = filterConfig.getInitParameter(name);
            LOG.trace(name + ":" + value);
        }
    }

    if (applicationContext != null && applicationContext.containsBean("securityContext")) {
        securityContext = (SecurityContext) applicationContext.getBean("securityContext");
    }

    if (securityContext != null) {
        LOG.trace("Security Context Initialized");
    } else {
        LOG.fatal("Could not obtain a reference to the security context); application is unsecured!");
    }

    LOG.trace("Authentication Filter initialized");
}

From source file:com.paladin.mvc.URLMappingFilter.java

@Override
public void init(FilterConfig cfg) throws ServletException {
    this.context = cfg.getServletContext();

    // ?  // ww  w.  j  av a2 s  .  c  o m
    this.PATH_PREFIX = cfg.getInitParameter("template-path-prefix");
    if (this.PATH_PREFIX == null)
        this.PATH_PREFIX = "/WEB-INF/templates";
    else if (this.PATH_PREFIX.endsWith("/"))
        this.PATH_PREFIX = this.PATH_PREFIX.substring(0, this.PATH_PREFIX.length() - 1);

    // ? URL ??? /img/***
    String ignores = cfg.getInitParameter("ignore");
    if (ignores != null)
        for (String ig : StringUtils.split(ignores, ','))
            ignoreURIs.add(ig.trim());

    // ? URL ?? ? ? *.jpg
    ignores = cfg.getInitParameter("ignoreExts");
    if (ignores != null)
        for (String ig : StringUtils.split(ignores, ','))
            ignoreExts.add('.' + ig.trim());

    // ?? 
    String tmp = cfg.getInitParameter("domain");
    if (StringUtils.isNotBlank(tmp))
        rootDomain = tmp;

    //  ??   ? ? 
    @SuppressWarnings("unchecked")
    Enumeration<String> names = cfg.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        String v = cfg.getInitParameter(name);
        if (v.endsWith("/"))
            v = v.substring(0, v.length() - 1);
        if ("ignore".equalsIgnoreCase(name) || "ignoreExts".equalsIgnoreCase(name))
            continue;
        if ("default".equalsIgnoreCase(name))
            default_base = PATH_PREFIX + v;
        else
            other_base.put(name, PATH_PREFIX + v);
    }
}

From source file:com.iorga.webappwatcher.RequestLogFilter.java

@SuppressWarnings("unchecked")
@Override//w ww . j  av a  2s . c  o m
public void init(final FilterConfig filterConfig) throws ServletException {
    // Initializing context
    final CpuCriticalUsageWatcher cpuCriticalUsageWatcher = new CpuCriticalUsageWatcher();
    parametersContext.put(CpuCriticalUsageWatcher.class, cpuCriticalUsageWatcher);
    final WriteAllRequestsWatcher writeAllRequestsWatcher = new WriteAllRequestsWatcher();
    parametersContext.put(WriteAllRequestsWatcher.class, writeAllRequestsWatcher);
    final RequestDurationWatcher requestDurationWatcher = new RequestDurationWatcher();
    parametersContext.put(RequestDurationWatcher.class, requestDurationWatcher);
    final RetentionLogWritingWatcher retentionLogWritingWatcher = createRetentionLogWritingWatcher();
    parametersContext.put(RetentionLogWritingWatcher.class, retentionLogWritingWatcher);
    final EventLogManager eventLogManager = EventLogManager.getInstance();
    parametersContext.put(EventLogManager.class, eventLogManager);
    systemEventLogger = new SystemEventLogger();
    parametersContext.put(SystemEventLogger.class, systemEventLogger);
    parametersContext.put(RequestLogFilter.class, this);
    // by default, watch the CPU peaks, the request duration & write all requests to the log
    eventLogManager.setEventLogWatchers(Sets.newHashSet(cpuCriticalUsageWatcher, requestDurationWatcher,
            writeAllRequestsWatcher, retentionLogWritingWatcher));

    // Reading web.xml filterConfig init-params
    for (final String parameterName : (List<String>) Collections.list(filterConfig.getInitParameterNames())) {
        final String value = filterConfig.getInitParameter(parameterName);
        setParameter(parameterName, value);
    }
    // Reading "webappwatcher.properties" parameters
    try {
        final Properties properties = new Properties();
        final InputStream propertiesStream = getClass().getClassLoader()
                .getResourceAsStream("webappwatcher.properties");
        if (propertiesStream != null) {
            properties.load(propertiesStream);
            for (final Entry<Object, Object> property : properties.entrySet()) {
                setParameter((String) property.getKey(), (String) property.getValue());
            }
        }
    } catch (final IOException e) {
        throw new ServletException("Problem while reading webappwatcher.properties file", e);
    }

    startServices();
}