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.cws.esolutions.security.filters.SessionAuthenticationFilter.java
public void init(final FilterConfig filterConfig) throws ServletException { final String methodName = SessionAuthenticationFilter.CNAME + "#init(final FilterConfig filterConfig) throws ServletException"; if (DEBUG) {//from w w w .ja va 2s . co m DEBUGGER.debug(methodName); DEBUGGER.debug("FilterConfig: {}", filterConfig); } ResourceBundle rBundle = null; try { if (filterConfig.getInitParameter(SessionAuthenticationFilter.FILTER_CONFIG_PARAM_NAME) == null) { ERROR_RECORDER.error("Filter configuration not found. Using default !"); rBundle = ResourceBundle.getBundle(SessionAuthenticationFilter.FILTER_CONFIG_FILE_NAME); } else { rBundle = ResourceBundle.getBundle( filterConfig.getInitParameter(SessionAuthenticationFilter.FILTER_CONFIG_PARAM_NAME)); } this.loginURI = rBundle.getString(SessionAuthenticationFilter.LOGIN_URI); this.passwordURI = rBundle.getString(SessionAuthenticationFilter.PASSWORD_URI); this.ignoreURIs = (StringUtils .isNotEmpty(rBundle.getString(SessionAuthenticationFilter.IGNORE_URI_LIST))) ? rBundle.getString(SessionAuthenticationFilter.IGNORE_URI_LIST).trim().split(",") : null; if (DEBUG) { if (this.ignoreURIs != null) { for (String str : this.ignoreURIs) { DEBUGGER.debug(str); } } } } catch (MissingResourceException mre) { ERROR_RECORDER.error(mre.getMessage(), mre); throw new UnavailableException(mre.getMessage()); } }
From source file:nl.b3p.commons.security.aselect.ASelectAuthorizationFilter.java
/** * Deze functie initialiseert het filter en controleert de init parameters. * Indien deze parameters ongeldig zijn wordt dit gelogd en wordt in de * doFilter() methode een exception gethrowd en niet de filter chain * voortgezet./*from ww w . j a v a2 s. co m*/ */ public void init(FilterConfig filterConfig) { if (log.isInfoEnabled()) { log.info("init"); } configOK = false; try { this.filterConfig = filterConfig; String apiString = filterConfig.getInitParameter("api"); if (apiString != null) { apiString = apiString.toLowerCase(); } /* voorlopig is alleen de agent API geimplementeerd. */ if (apiString.equals("agent")) { api = ASELECT_API_AGENT; client = new ASelectAgentClient(filterConfigToProperties(filterConfig)); } else { throw new IllegalArgumentException("invalid \"api\" init parameter"); } appId = filterConfig.getInitParameter("app_id"); if (appId == null) { throw new IllegalArgumentException("\"app_id\" init parameter required"); } avoidURLParamsInRedirect = "true".equals(filterConfig.getInitParameter("avoid_url_params_in_redirect")); configOK = true; } catch (IllegalArgumentException e) { log.error("error initializing filter " + filterConfig.getFilterName(), e); } if (!configOK) { log.error("bad config; disallowing access to application"); } }
From source file:org.alfresco.web.app.servlet.HTTPRequestAuthenticationFilter.java
public void init(FilterConfig config) throws ServletException { // Save the context this.context = config.getServletContext(); // Setup the authentication context WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); authComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); authenticationService = (AuthenticationService) ctx.getBean("AuthenticationService"); httpServletRequestAuthHeaderName = config.getInitParameter("httpServletRequestAuthHeaderName"); if (httpServletRequestAuthHeaderName == null) { httpServletRequestAuthHeaderName = "x-user"; }/* w w w . ja v a2 s .c om*/ this.authPatternString = config.getInitParameter("authPatternString"); if (this.authPatternString != null) { try { authPattern = Pattern.compile(this.authPatternString); } catch (PatternSyntaxException e) { logger.warn("Invalid pattern: " + this.authPatternString, e); authPattern = null; } } }
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 w ww.j a v a 2 s . co 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:nl.b3p.commons.security.aselect.ASelectAuthorizationFilter.java
/** * Hulpfunctie om een FilterConfig object om te zetten naar Properties *///from w ww .ja v a 2 s . c o m private Properties filterConfigToProperties(FilterConfig c) { Properties result = new Properties(); Enumeration params = c.getInitParameterNames(); while (params.hasMoreElements()) { String name = (String) params.nextElement(); result.setProperty(name, c.getInitParameter(name)); } return result; }
From source file:com.ultrapower.eoms.common.plugin.ecside.filter.ECSideFilter.java
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; servletContext=filterConfig.getServletContext(); servletRealPath=servletContext.getRealPath("/"); initEncoding();/*from ww w .jav a 2s.co m*/ initEasyList(); initProperties(); String responseHeadersSetBeforeDoFilter = filterConfig.getInitParameter("responseHeadersSetBeforeDoFilter"); if (StringUtils.isNotBlank(responseHeadersSetBeforeDoFilter)) { ECSideFilter.responseHeadersSetBeforeDoFilter = Boolean.valueOf(responseHeadersSetBeforeDoFilter).booleanValue(); } }
From source file:org.rhq.helpers.rtfilter.filter.RtFilter.java
/** * Initialize parameters from the web.xml filter init-params * * @param conf the filter configuration/*www . jav a 2s .c om*/ */ private void initializeParameters(FilterConfig conf) throws UnavailableException { String chop = conf.getInitParameter(InitParams.CHOP_QUERY_STRING); if (chop != null) { this.chopUrl = Boolean.valueOf(chop.trim()).booleanValue(); } String logDirectoryPath = conf.getInitParameter(InitParams.LOG_DIRECTORY); if (logDirectoryPath != null) { this.logDirectory = new File(logDirectoryPath.trim()); } else { /* * If this is a JBossAS deployed container, or a Standalone TC container, use a logical * default (so those plugins can be written in a compatible way). * First, try to default to "${JBOSS_SERVER_HOME_DIR_SYSPROP}/JBOSSAS_SERVER_LOG_SUBDIR/rt"; * If not set try "${TOMCAT_SERVER_HOME_DIR_SYSPROP}/TOMCAT_SERVER_LOG_SUBDIR/rt"; * If, for some reason, neither property is set, fall back to "${java.io.tmpdir}/rhq/rt". */ File serverLogDir = null; String serverHomeDirPath = System.getProperty(JBOSSAS_SERVER_HOME_DIR_SYSPROP); if (null != serverHomeDirPath) { serverLogDir = new File(serverHomeDirPath, JBOSSAS_SERVER_LOG_SUBDIR); } else { serverHomeDirPath = System.getProperty(TOMCAT_SERVER_HOME_DIR_SYSPROP); if (serverHomeDirPath != null) { serverLogDir = new File(serverHomeDirPath, TOMCAT_SERVER_LOG_SUBDIR); } } if (null != serverLogDir) { this.logDirectory = new File(serverLogDir, "rt"); } else { this.logDirectory = new File(System.getProperty(JAVA_IO_TMPDIR_SYSPROP), "rhq/rt"); log.warn( "The 'logDirectory' filter init param was not set. Also, the standard system properties were not set (" + JBOSSAS_SERVER_HOME_DIR_SYSPROP + ", " + TOMCAT_SERVER_HOME_DIR_SYSPROP + "); defaulting RT log directory to '" + this.logDirectory + "'."); } } if (this.logDirectory.exists()) { if (!this.logDirectory.isDirectory()) { throw new UnavailableException( "Log directory '" + this.logDirectory + "' exists but is not a directory."); } } else { try { this.logDirectory.mkdirs(); } catch (Exception e) { throw new UnavailableException( "Unable to create log directory '" + this.logDirectory + "' - cause: " + e); } if (!logDirectory.exists()) { throw new UnavailableException("Unable to create log directory '" + this.logDirectory + "'."); } } String logFilePrefixString = conf.getInitParameter(InitParams.LOG_FILE_PREFIX); if (logFilePrefixString != null) { this.logFilePrefix = logFilePrefixString.trim(); } String dontLog = conf.getInitParameter(InitParams.DONT_LOG_REG_EX); if (dontLog != null) { this.dontLogPattern = Pattern.compile(dontLog.trim()); } String flushTimeout = conf.getInitParameter(InitParams.TIME_BETWEEN_FLUSHES_IN_SEC); if (flushTimeout != null) { try { timeBetweenFlushes = Long.parseLong(flushTimeout.trim()) * 1000; } catch (NumberFormatException nfe) { timeBetweenFlushes = DEFAULT_FLUSH_TIMEOUT; } } String uriOnly = conf.getInitParameter(InitParams.MATCH_ON_URI_ONLY); if (uriOnly != null) { matchOnUriOnly = Boolean.getBoolean(uriOnly.trim()); } String lines = conf.getInitParameter(InitParams.FLUSH_AFTER_LINES); if (lines != null) { try { flushAfterLines = Long.parseLong(lines.trim()); if (flushAfterLines <= 0) { throw new NumberFormatException(); } } catch (NumberFormatException nfe) { log.error("Invalid '" + InitParams.FLUSH_AFTER_LINES + "' init parameter: " + lines + " (value must be a positive integer) - using default."); flushAfterLines = DEFAULT_FLUSH_AFTER_LINES; } } String maxLogFileSizeString = conf.getInitParameter(InitParams.MAX_LOG_FILE_SIZE); if (maxLogFileSizeString != null) { try { this.maxLogFileSize = Long.parseLong(maxLogFileSizeString.trim()); if (this.maxLogFileSize <= 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { log.error("Invalid '" + InitParams.MAX_LOG_FILE_SIZE + "' init parameter: " + maxLogFileSizeString + " (value must be a positive integer) - using default."); this.maxLogFileSize = DEFAULT_MAX_LOG_FILE_SIZE; } } /* * Read mappings from a vhost mapping file in the format of a properties file * inputhost = mapped host * This file needs to live in the search path - e.g. in server/<config>/conf/ * The name of it must be passed as init-param to the filter. Otherwise the mapping * will not be used. * <param-name>vHostMappingFile</param-name> */ String vhostMappingFileString = conf.getInitParameter(InitParams.VHOST_MAPPING_FILE); if (vhostMappingFileString != null) { InputStream stream = getClass().getClassLoader().getResourceAsStream(vhostMappingFileString); if (stream != null) { try { vhostMappings.load(stream); } catch (IOException e) { log.warn("Can't read vhost mappings from " + vhostMappingFileString + " :" + e.getMessage()); } finally { if (stream != null) try { stream.close(); } catch (Exception e) { log.debug(e); } } } else { log.warn("Can't read vhost mappings from " + vhostMappingFileString); } } }
From source file:com.wordpress.metaphorm.authProxy.hook.AuthProxyServletFilter.java
public void init(FilterConfig filterConfig) { _log.debug("init()"); // Hash Secret is read from web.xml so that each installation of Social Apps Proxy // can use a different value, yet the same value for all nodes in a cluster String secret = filterConfig.getInitParameter("hashSecret"); _log.debug("hashSecret set to \"" + secret + "\" using liferay-hook.xml"); if ("change-me-to-something-random".equals(secret)) _log.warn(/*from w ww . ja va 2 s .c o m*/ "IMPORTANT: You should set hashSecret (see liferay-hook.xml) to a value other than the default before using Social Apps Proxy in production. Failing to do so may leave your portal vulnerable to user impersonation."); UserToken.secret = secret; this.filterConfig = filterConfig; }
From source file:com.mindquarry.user.webapp.AuthenticationFilter.java
/** * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) *///from w ww . j a v a 2s . c om public void init(FilterConfig config) throws ServletException { ServletContext servletContext = config.getServletContext(); beanFactory_ = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); log_ = (Logger) beanFactory_.getBean(AvalonUtils.LOGGER_ROLE); realm_ = config.getInitParameter("realm"); String authenticationBeanName = Authentication.class.getName(); if (!beanFactory_.containsBean(authenticationBeanName)) { throw new ServletException( "there is no spring bean with name: " + authenticationBeanName + " available."); } }
From source file:uk.ac.cam.ucs.webauth.RavenFilter.java
@Override public void init(FilterConfig config) throws ServletException { // check if a different authenticate page is configured. // eg https://demo.raven.cam.ac.uk/auth/authenticate.html String authenticatePage = config.getInitParameter(INIT_PARAM_AUTHENTICATE_URL); if (authenticatePage != null) sRavenAuthenticatePage = authenticatePage; // get the path to the raven certificate or use a default String sCertContextPath = config.getInitParameter(INIT_PARAM_CERTIFICATE_PATH); if (sCertContextPath == null) sCertContextPath = DEFAULT_CERTIFICATE_PATH; // calculate real path from web app relative version sCertRealPath = config.getServletContext().getRealPath(sCertContextPath); log.debug("Certificate will be loaded from: " + sCertRealPath); // ensure KeyStore is initialised. keyStore = getKeyStore();/* w w w . j ava 2s. com*/ // ensure WebauthValidator is initialised. webauthValidator = getWebauthValidator(); String sTestingMode = config.getServletContext().getInitParameter(CONTEXT_PARAM_TESTING_MODE); log.debug("Testing mode: " + sTestingMode); testingMode = "true".equals(sTestingMode); serverURLPrefix = config.getServletContext().getInitParameter(CONTEXT_PARAM_URL_PREFIX); log.debug("Server url prefix: " + serverURLPrefix); String sAllowedPrincipals = config.getInitParameter(INIT_PARAM_ALLOWED_PRINCIPALS); if (sAllowedPrincipals != null) { allowedPrincipals = new HashSet<String>(Arrays.asList(sAllowedPrincipals.split(","))); log.debug("Restricting access to " + sAllowedPrincipals); } else { log.debug("Granting access to all principals"); } }