Example usage for javax.servlet FilterConfig getInitParameter

List of usage examples for javax.servlet FilterConfig getInitParameter

Introduction

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

Prototype

public String getInitParameter(String name);

Source Link

Document

Returns a String containing the value of the named initialization parameter, or null if the initialization parameter does not exist.

Usage

From source file:org.xmlactions.web.PagerFilter.java

@SuppressWarnings("unchecked")
public void init(FilterConfig filterConfig) throws ServletException {

    logger.debug("PagerFilter.init");
    this.filterConfig = filterConfig;
    try {//from w ww. j a  v  a 2  s  .  c o  m
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }

    Enumeration<String> enumeration = filterConfig.getInitParameterNames();
    while (enumeration.hasMoreElements()) {
        String key = enumeration.nextElement();
        String value = filterConfig.getInitParameter(key);
        mapRequestParams.put(key, value);
    }
}

From source file:org.infoscoop.web.SessionManagerFilter.java

public void init(FilterConfig config) throws ServletException {

    String excludePathStr = config.getInitParameter("excludePath");
    if (excludePathStr != null) {
        String[] pathArray = excludePathStr.split(",");
        for (int i = 0; i < pathArray.length; i++) {
            String path = pathArray[i].trim();
            if (path.endsWith("*")) {
                excludePathx.add(path.substring(0, path.length() - 1));
            } else {
                excludePaths.add(path);//w w w.  j  a v a  2 s  . co  m
            }
        }
    }

    String redirectPathStr = config.getInitParameter("redirectPath");
    if (redirectPathStr != null) {
        String[] pathArray = redirectPathStr.split(",");
        for (int i = 0; i < pathArray.length; i++) {
            redirectPaths.add(pathArray[i].trim());
        }
    }
}

From source file:org.wso2.carbon.identity.entitlement.filter.EntitlementFilter.java

/**
 * In this init method the required attributes are taken from web.xml, if there are not provided they will be set to default.
 * authRedirectURL attribute have to provided
 *///from w w  w  .  j av a 2  s.c om
@Override
public void init(FilterConfig filterConfig) throws EntitlementFilterException {

    //This Attributes are mandatory So have to be specified in the web.xml
    authRedirectURL = filterConfig.getInitParameter(EntitlementConstants.AUTH_REDIRECT_URL);
    remoteServiceUserName = filterConfig.getServletContext().getInitParameter(EntitlementConstants.USERNAME);
    remoteServicePassword = filterConfig.getServletContext().getInitParameter(EntitlementConstants.PASSWORD);
    remoteServiceUrl = filterConfig.getServletContext()
            .getInitParameter(EntitlementConstants.REMOTE_SERVICE_URL);

    //This Attributes are not mandatory
    client = filterConfig.getServletContext().getInitParameter(EntitlementConstants.CLIENT);
    if (client == null) {
        client = EntitlementConstants.defaultClient;
    }
    subjectScope = filterConfig.getServletContext().getInitParameter(EntitlementConstants.SUBJECT_SCOPE);
    if (subjectScope == null) {
        subjectScope = EntitlementConstants.defaultSubjectScope;
    }
    subjectAttributeName = filterConfig.getServletContext()
            .getInitParameter(EntitlementConstants.SUBJECT_ATTRIBUTE_NAME);
    if (subjectAttributeName == null) {
        subjectAttributeName = EntitlementConstants.defaultSubjectAttributeName;
    }
    cacheType = filterConfig.getInitParameter(EntitlementConstants.CACHE_TYPE);
    if (cacheType == null) {
        cacheType = EntitlementConstants.defaultCacheType;
    }
    if (filterConfig.getInitParameter(EntitlementConstants.MAX_CACHE_ENTRIES) != null) {
        maxCacheEntries = Integer
                .parseInt(filterConfig.getInitParameter(EntitlementConstants.MAX_CACHE_ENTRIES));
    } else {
        maxCacheEntries = 0;
    }
    if (filterConfig.getInitParameter(EntitlementConstants.INVALIDATION_INTERVAL) != null) {
        invalidationInterval = Integer
                .parseInt(filterConfig.getInitParameter(EntitlementConstants.INVALIDATION_INTERVAL));
    } else {
        invalidationInterval = 0;
    }

    if (filterConfig.getInitParameter(EntitlementConstants.THRIFT_HOST) != null) {
        thriftHost = filterConfig.getInitParameter(EntitlementConstants.THRIFT_HOST);
    } else {
        thriftHost = EntitlementConstants.defaultThriftHost;
    }

    if (filterConfig.getInitParameter(EntitlementConstants.THRIFT_PORT) != null) {
        thriftPort = filterConfig.getInitParameter(EntitlementConstants.THRIFT_PORT);
    } else {
        thriftPort = EntitlementConstants.defaultThriftPort;
    }

    Map<String, Map<String, String>> appToPDPClientConfigMap = new HashMap<String, Map<String, String>>();
    Map<String, String> clientConfigMap = new HashMap<String, String>();

    if (client != null) {
        if (client.equals(EntitlementConstants.SOAP)) {
            clientConfigMap.put(EntitlementConstants.CLIENT, client);
            clientConfigMap.put(EntitlementConstants.SERVER_URL, remoteServiceUrl);
            clientConfigMap.put(EntitlementConstants.USERNAME, remoteServiceUserName);
            clientConfigMap.put(EntitlementConstants.PASSWORD, remoteServicePassword);
            clientConfigMap.put(EntitlementConstants.REUSE_SESSION, reuseSession);
        } else if (client.equals(EntitlementConstants.BASIC_AUTH)) {
            clientConfigMap.put(EntitlementConstants.CLIENT, client);
            clientConfigMap.put(EntitlementConstants.SERVER_URL, remoteServiceUrl);
            clientConfigMap.put(EntitlementConstants.USERNAME, remoteServiceUserName);
            clientConfigMap.put(EntitlementConstants.PASSWORD, remoteServicePassword);
        } else if (client.equals(EntitlementConstants.THRIFT)) {
            clientConfigMap.put(EntitlementConstants.CLIENT, client);
            clientConfigMap.put(EntitlementConstants.SERVER_URL, remoteServiceUrl);
            clientConfigMap.put(EntitlementConstants.USERNAME, remoteServiceUserName);
            clientConfigMap.put(EntitlementConstants.PASSWORD, remoteServicePassword);
            clientConfigMap.put(EntitlementConstants.REUSE_SESSION, reuseSession);
            clientConfigMap.put(EntitlementConstants.THRIFT_HOST, thriftHost);
            clientConfigMap.put(EntitlementConstants.THRIFT_PORT, thriftPort);
        } else {
            throw new EntitlementFilterException(
                    "EntitlementMediator initialization error: Unsupported client");
        }

    } else {
        clientConfigMap.put(EntitlementConstants.SERVER_URL, remoteServiceUrl);
        clientConfigMap.put(EntitlementConstants.USERNAME, remoteServiceUserName);
        clientConfigMap.put(EntitlementConstants.PASSWORD, remoteServicePassword);
    }

    appToPDPClientConfigMap.put("EntitlementMediator", clientConfigMap);
    PEPProxyConfig config = new PEPProxyConfig(appToPDPClientConfigMap, "EntitlementMediator", cacheType,
            invalidationInterval, maxCacheEntries);

    try {
        pepProxy = new PEPProxy(config);
    } catch (EntitlementProxyException e) {
        throw new EntitlementFilterException("Error while initializing the Entitlement PEP Proxy", e);
    }
}

From source file:org.wso2.carbon.analytics.message.tracer.MessageTracerFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Initialize message tracer api client.");
    }//from   w  w  w  .  j  a  v a 2  s.  c o  m
    String url = filterConfig.getInitParameter("url");
    if ((url == null) || (url.isEmpty())) {
        log.error("BAM server URL is null or empty. Please add url as a MessageTracerFilter init parameter.");
        return;
    }
    String username = filterConfig.getInitParameter("username");
    if ((username == null) || (username.isEmpty())) {
        log.error(
                "BAM server username is null or empty. Please add username as a MessageTracerFilter init parameter.");
        return;
    }
    String password = filterConfig.getInitParameter("password");
    if ((password == null) || (password.isEmpty())) {
        log.error(
                "BAM server password is null or empty. Please add username as a MessageTracerFilter init parameter.");
        return;
    }
    String dumpMessageBody = filterConfig.getInitParameter("enableDumpMessageBody");
    if (dumpMessageBody != null) {
        isDumpMessageBody = Boolean.parseBoolean(dumpMessageBody);
        if (log.isDebugEnabled()) {
            log.debug(
                    "enableDumpMessageBody is " + isDumpMessageBody + ". Please use true/false to configure.");
        }
    }
    eventPublisher = new EventPublisher(new ServerConfig(url, username, password));
}

From source file:org.echocat.jemoni.jmx.support.ServletHealth.java

@Override
public void init(@Nonnull FilterConfig filterConfig) throws ServletException {
    final String mapping = filterConfig.getInitParameter(MAPPING_INIT_ATTRIBUTE);
    if (mapping != null) {
        setMapping(mapping);/*from w w  w .  ja  v a2 s . c o  m*/
    }
    final String registryRef = filterConfig.getInitParameter(REGISTRY_REF_INIT_ATTRIBUTE);
    if (!isEmpty(registryRef)) {
        setRegistry(getBeanFor(filterConfig.getServletContext(), registryRef, JmxRegistry.class));
    }
    final String interceptor = filterConfig.getInitParameter(INTERCEPTOR_INIT_ATTRIBUTE);
    if (!isEmpty(interceptor)) {
        setInterceptor(loadInterceptor(interceptor));
    }
    final String interceptorRef = filterConfig.getInitParameter(INTERCEPTOR_REF_INIT_ATTRIBUTE);
    if (!isEmpty(interceptorRef)) {
        setInterceptor(
                getBeanFor(filterConfig.getServletContext(), interceptorRef, ServletHealthInterceptor.class));
    }
    handleHostIncludeExcludesIfNeeded(filterConfig);
    init();
}

From source file:com.alfaariss.oa.util.web.RemoteAddrFilter.java

/**
 * Initializes the <code>RemoteAddrFilter</code>.
 * //from  ww  w.  j av  a  2s.c  o m
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */
public void init(FilterConfig oFilterConfig) throws ServletException {
    try {
        //Get filter name
        _sFilterName = oFilterConfig.getFilterName();
        if (_sFilterName == null)
            _sFilterName = RemoteAddrFilter.class.getSimpleName();

        //Read allowed IP from parameter
        _sIP = oFilterConfig.getInitParameter("allow");
        if (_sIP == null) {
            _logger.error("No 'allow' init parameter found in filter configuration");
            throw new OAException(SystemErrors.ERROR_INIT);
        }

        _sIP = _sIP.trim();

        StringTokenizer st = new StringTokenizer(_sIP, ",");
        if (st.countTokens() < 1) {
            _logger.error("Invalid 'allow' init parameter found in filter configuration");
            throw new OAException(SystemErrors.ERROR_INIT);
        }
        _logger.info("Only allowing requests from: " + _sIP);

        _logger.info(_sFilterName + " started");
    } catch (OAException e) {
        _logger.fatal(_sFilterName + " start failed", e);
        throw new ServletException();
    } catch (Exception e) {
        _logger.fatal(_sFilterName + " start failed due to internal error", e);
        throw new ServletException();
    }
}

From source file:org.hifivault.geo.location.filters.GeoLocationFilter.java

public void init(FilterConfig filterConfig) throws ServletException {

    BeanFactory beanFactory = WebApplicationContextUtils
            .getRequiredWebApplicationContext(filterConfig.getServletContext());
    manager = (GeoLocationManager) beanFactory.getBean("geoLocationManager");

    Enumeration<String> names = filterConfig.getInitParameterNames();
    while (names.hasMoreElements()) {
        String key = names.nextElement();
        String value = filterConfig.getInitParameter(key);
        if (value != null && value.length() > 0) {
            override.put(key.toUpperCase(), value.toUpperCase());
        }//from   ww  w .  j  a v  a  2  s  . c  om
    }
}

From source file:org.infoscoop.googleapps.GoogleAppsOpenIDFilter.java

private ConsumerHelper createConsumerHelper(FilterConfig config) {
    int socketTimeout = 30 * 1000;
    String socketTimeoutParam = config.getInitParameter("socketTimeout");
    if (socketTimeoutParam != null) {
        if (log.isInfoEnabled())
            log.info("socketTimeout is set to " + socketTimeoutParam);
        socketTimeout = Integer.parseInt(socketTimeoutParam);
    }/*from www.j a  v a  2  s .com*/

    HttpFetcher httpFetcher = new DefaultHttpFetcher();
    HostMetaFetcher defaultMetaFetcher = new DefaultHostMetaFetcher(httpFetcher);
    HostMetaFetcher googleMetaFetcher = new GoogleHostedHostMetaFetcher(httpFetcher);
    HostMetaFetcher continuousMetaFetcher = new ContinuousHostMetaFetcher(googleMetaFetcher,
            defaultMetaFetcher);

    TrustRootsProvider trustRootsProvider = new DefaultTrustRootsProvider();
    CachedCertPathValidator cachedCertPathValidator = new CachedCertPathValidator(trustRootsProvider);
    Verifier verifier = new Verifier(cachedCertPathValidator, httpFetcher);
    CertValidator certValidator = new DefaultCertValidator();
    XrdDiscoveryResolver xrdDiscoveryResolver = new LegacyXrdsResolver(httpFetcher, verifier, certValidator);

    HttpFetcherFactory httpFetcherFactory = new HttpFetcherFactory();
    HtmlResolver htmlResolver = new HtmlResolver(httpFetcherFactory);
    YadisResolver yadisResolver = new YadisResolver(httpFetcherFactory);
    XriResolver xriResolver = new XriDotNetProxyResolver();

    Discovery2 discovery = new Discovery2(continuousMetaFetcher, xrdDiscoveryResolver, htmlResolver,
            yadisResolver, xriResolver);

    ConsumerManager consumerMgr = new ConsumerManager();
    consumerMgr.setAssociations(new InMemoryConsumerAssociationStore());
    consumerMgr.setNonceVerifier(new InMemoryNonceVerifier(5000));
    consumerMgr.setSocketTimeout(socketTimeout);

    return new ConsumerHelper(consumerMgr, discovery);
}

From source file:org.glite.slcs.acl.impl.XMLFileAccessControlList.java

public void init(FilterConfig filterConfig) throws SLCSException {

    // initialize the AttributeDefintions from the servlet context
    ServletContext context = filterConfig.getServletContext();
    AttributeDefinitionsFactory.initialize(context);

    String filename = filterConfig.getInitParameter(ACLFILE_CONFIG_PARAM);
    LOG.info(ACLFILE_CONFIG_PARAM + "=" + filename);
    if (filename == null) {
        LOG.info("Parameter '" + ACLFILE_CONFIG_PARAM + "' is not defined, trying parameter '"
                + ACLFILE_CONTEXT_PARAM + "'");
        String contextKey = filterConfig.getInitParameter(ACLFILE_CONTEXT_PARAM);
        LOG.info(ACLFILE_CONTEXT_PARAM + "=" + contextKey);
        if (contextKey != null) {
            filename = context.getInitParameter(contextKey);
            if (filename == null) {
                throw new SLCSConfigurationException(
                        "Filter parameter ContextParamACLFile references a undefined Context parameter.");
            }//ww  w  .j  a v  a 2 s . c  o m
            LOG.debug("ACL filename=" + filename);
        } else {
            throw new SLCSConfigurationException("Filter parameter ACLFile or ContextParamACLFile not defined");
        }
    }

    // load the XML file
    aclXMLConfiguration_ = createACLXMLConfiguration(filename);

    // create the access control rules list
    accessControlRules_ = createACLAccessControlRules(aclXMLConfiguration_);

    // deals with the FileConfigurationMonitor
    String monitoringInterval = filterConfig.getInitParameter("ACLFileMonitoringInterval");
    if (monitoringInterval != null) {
        LOG.info("ACLFileMonitoringInterval=" + monitoringInterval);
        File file = aclXMLConfiguration_.getFile();
        aclConfigurationMonitor_ = FileConfigurationMonitor.createFileConfigurationMonitor(file,
                monitoringInterval, this);
        // and start
        aclConfigurationMonitor_.start();
    }
}

From source file:org.apdplat.module.security.service.filter.JCaptchaFilter.java

protected void initParameters(final FilterConfig fConfig) {
    failureUrl = "/" + PropertyHolder.getProperty("login.page") + "?state=checkCodeError";
    if ("true".equals(PropertyHolder.getProperty("login.code"))) {
        LOG.info("???");
        filter = true;//w  ww .j  a va 2  s . c o  m
    } else {
        filter = false;
        LOG.info("???");
    }
    if (StringUtils.isNotBlank(fConfig.getInitParameter(PARAM_FILTER_PROCESSES_URL))) {
        filterProcessesUrl = fConfig.getInitParameter(PARAM_FILTER_PROCESSES_URL);
    }

    if (StringUtils.isNotBlank(fConfig.getInitParameter(PARAM_CAPTCHA_PARAMTER_NAME))) {
        captchaParamterName = fConfig.getInitParameter(PARAM_CAPTCHA_PARAMTER_NAME);
    }
}