List of usage examples for javax.servlet FilterConfig getServletContext
public ServletContext getServletContext();
From source file:dk.dma.msinm.user.security.SecurityServletFilter.java
/** * Initializes the security configuration * @param filterConfig the servlet filter configuration *//*from www.j a v a 2 s .co m*/ @Override public void init(FilterConfig filterConfig) throws ServletException { // Initialize the security configuration if (StringUtils.isNotBlank(securityConfFile)) { try { securityConf = new SecurityConf( filterConfig.getServletContext().getResourceAsStream(securityConfFile)); } catch (Exception e) { log.error("Error loading security config file " + securityConfFile, e); throw new ServletException("Error loading security config file " + securityConfFile, e); } } else { securityConf = new SecurityConf(); } log.info("Loaded security configuration " + securityConf); }
From source file:cc.kune.core.server.rack.RackServletFilter.java
private Injector installInjector(final FilterConfig filterConfig, final Rack rack, final Injector waveChildInjector, final Module otherModule) { final List<Module> guiceModules = rack.getGuiceModules(); guiceModules.add(otherModule);//from w w w . jav a2s. co m final Injector childInjector = waveChildInjector.createChildInjector(guiceModules); filterConfig.getServletContext().setAttribute(INJECTOR_ATTRIBUTE, childInjector); return childInjector; }
From source file:org.jasig.cas.util.AbstractConfigurationFilter.java
/** * Retrieves the property from the FilterConfig. First it checks the FilterConfig's initParameters to see if it * has a value./* w w w. j a va 2s . c o m*/ * If it does, it returns that, otherwise it retrieves the ServletContext's initParameters and returns that value if any. * <p> * Finally, it will check JNDI if all other methods fail. All the JNDI properties should be stored under either java:comp/env/cas/SHORTFILTERNAME/{propertyName} * or java:comp/env/cas/{propertyName} * <p> * Essentially the documented order is: * <ol> * <li>FilterConfig.getInitParameter</li> * <li>ServletContext.getInitParameter</li> * <li>java:comp/env/cas/SHORTFILTERNAME/{propertyName}</li> * <li>java:comp/env/cas/{propertyName}</li> * <li>Default Value</li> * </ol> * * * @param filterConfig the Filter Configuration. * @param propertyName the property to retrieve. * @param defaultValue the default value if the property is not found. * @return the property value, following the above conventions. It will always return the more specific value (i.e. * filter vs. context). */ protected final String getPropertyFromInitParams(final FilterConfig filterConfig, final String propertyName, final String defaultValue) { final String value = filterConfig.getInitParameter(propertyName); if (CommonUtils.isNotBlank(value)) { log.info("Property [" + propertyName + "] loaded from FilterConfig.getInitParameter with value [" + value + "]"); return value; } final String value2 = filterConfig.getServletContext().getInitParameter(propertyName); if (CommonUtils.isNotBlank(value2)) { log.info("Property [" + propertyName + "] loaded from ServletContext.getInitParameter with value [" + value2 + "]"); return value2; } InitialContext context; try { context = new InitialContext(); } catch (final NamingException e) { log.warn(e, e); return defaultValue; } final String shortName = this.getClass().getName() .substring(this.getClass().getName().lastIndexOf(".") + 1); final String value3 = loadFromContext(context, "java:comp/env/cas/" + shortName + "/" + propertyName); if (CommonUtils.isNotBlank(value3)) { log.info("Property [" + propertyName + "] loaded from JNDI Filter Specific Property with value [" + value3 + "]"); return value3; } final String value4 = loadFromContext(context, "java:comp/env/cas/" + propertyName); if (CommonUtils.isNotBlank(value4)) { log.info("Property [" + propertyName + "] loaded from JNDI with value [" + value4 + "]"); return value4; } log.info("Property [" + propertyName + "] not found. Using default value [" + defaultValue + "]"); return defaultValue; }
From source file:com.mindquarry.user.webapp.AuthenticationFilter.java
/** * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) *//*from w w w .ja va 2 s . com*/ 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:org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter.java
/** * Constructs a Cas20ServiceTicketValidator or a Cas20ProxyTicketValidator based on supplied parameters. * * @param filterConfig the Filter Configuration object. * @return a fully constructed TicketValidator. *///from w ww . j av a 2s . c o m protected final TicketValidator getTicketValidator(final FilterConfig filterConfig) { final String allowAnyProxy = getPropertyFromInitParams(filterConfig, "acceptAnyProxy", null); final String allowedProxyChains = getPropertyFromInitParams(filterConfig, "allowedProxyChains", null); // TODO ? ServletContext context = filterConfig.getServletContext(); String casServerContextName = context.getInitParameter(CAS_SERVER_NAME_CONTEXT_PARAMETER); CommonUtils.assertNotNull(casServerContextName, "casServerContextName cannot be null."); String casServerAddress = getCasServerAddress(); logger.trace(this.getClass() + ".getTicketValidator(): casServerAddress = " + casServerAddress); final String casServerUrlPrefix = casServerAddress + "/" + casServerContextName + "/"; logger.trace(this.getClass() + ".getTicketValidator(): casServerUrlPrefix = " + casServerUrlPrefix); final Cas20ServiceTicketValidator validator; if (CommonUtils.isNotBlank(allowAnyProxy) || CommonUtils.isNotBlank(allowedProxyChains)) { final Cas20ProxyTicketValidator v = new Cas20ProxyTicketValidator(casServerUrlPrefix); v.setAcceptAnyProxy(parseBoolean(allowAnyProxy)); v.setAllowedProxyChains(CommonUtils.createProxyList(allowedProxyChains)); validator = v; } else { validator = new Cas20ServiceTicketValidator(casServerUrlPrefix); } validator.setProxyCallbackPath(getPropertyFromInitParams(filterConfig, "proxyCallbackPath", null)); validator.setProxyGrantingTicketStorage(this.proxyGrantingTicketStorage); validator.setProxyRetriever(new Cas20ProxyRetriever(casServerUrlPrefix, getPropertyFromInitParams(filterConfig, "encoding", null))); validator.setRenew(parseBoolean(getPropertyFromInitParams(filterConfig, "renew", "false"))); validator.setEncoding(getPropertyFromInitParams(filterConfig, "encoding", null)); final Map additionalParameters = new HashMap(); final List params = Arrays.asList(RESERVED_INIT_PARAMS); for (final Enumeration e = filterConfig.getInitParameterNames(); e.hasMoreElements();) { final String s = (String) e.nextElement(); if (!params.contains(s)) { additionalParameters.put(s, filterConfig.getInitParameter(s)); } } validator.setCustomParameters(additionalParameters); validator.setHostnameVerifier(getHostnameVerifier(filterConfig)); return validator; }
From source file:org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter.java
@Override protected void initializeAuthHandler(String authHandlerClassName, FilterConfig filterConfig) throws ServletException { // A single CuratorFramework should be used for a ZK cluster. // If the ZKSignerSecretProvider has already created it, it has to // be set here... to be used by the ZKDelegationTokenSecretManager ZKDelegationTokenSecretManager.setCurator((CuratorFramework) filterConfig.getServletContext() .getAttribute(ZKSignerSecretProvider.ZOOKEEPER_SIGNER_SECRET_PROVIDER_CURATOR_CLIENT_ATTRIBUTE)); super.initializeAuthHandler(authHandlerClassName, filterConfig); ZKDelegationTokenSecretManager.setCurator(null); }
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 *//* w ww.ja v 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.onehippo.forge.hst.pdf.renderer.servlet.HtmlPDFRenderingFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { Properties tidyProps = new Properties(); String param = StringUtils.trim(filterConfig.getInitParameter(TIDY_PROPS_PARAM)); if (!StringUtils.isEmpty(param)) { InputStream input = null; try {// ww w .ja v a2 s . c o m input = filterConfig.getServletContext().getResourceAsStream(param); tidyProps.load(input); } catch (Exception e) { log.error("Failed to parse Tidy properties from '" + param + "'.", e); } finally { IOUtils.closeQuietly(input); } } pdfRenderer = new HtmlPDFRenderer(tidyProps); param = StringUtils.trim(filterConfig.getInitParameter(CSS_URI_PARAM)); if (!StringUtils.isEmpty(param)) { String[] cssURIParams = StringUtils.split(param, ";, \t\r\n"); List<URI> cssURIList = new ArrayList<URI>(); for (String cssURIParam : cssURIParams) { if (StringUtils.startsWith(cssURIParam, "file:") || StringUtils.startsWith(cssURIParam, "http:") || StringUtils.startsWith(cssURIParam, "https:") || StringUtils.startsWith(cssURIParam, "ftp:") || StringUtils.startsWith(cssURIParam, "sftp:")) { cssURIList.add(URI.create(param)); } else { File cssFile = null; if (StringUtils.startsWith(cssURIParam, "/")) { cssFile = new File(filterConfig.getServletContext().getRealPath(cssURIParam)); } else { cssFile = new File(cssURIParam); } if (!cssFile.isFile()) { log.error("Cannot find the css file: {}", cssFile); } else { cssURIList.add(cssFile.toURI()); } } } if (!cssURIList.isEmpty()) { pdfRenderer.setCssURIs(cssURIList.toArray(new URI[cssURIList.size()])); } } param = StringUtils.trim(filterConfig.getInitParameter(BUFFER_SIZE_PARAM)); if (!StringUtils.isEmpty(param)) { pdfRenderer.setBufferSize(Math.max(512, NumberUtils.toInt(param, 4096))); } param = StringUtils.trim(filterConfig.getInitParameter(USER_AGENT_CALLBACK_CLASS_PARAM)); if (!StringUtils.isEmpty(param)) { try { Class<?> userAgentCallBackClass = Thread.currentThread().getContextClassLoader().loadClass(param); if (!UserAgentCallback.class.isAssignableFrom(userAgentCallBackClass)) { log.error("The class, '{}' is not an type of '{}'.", param, UserAgentCallback.class); } else { pdfRenderer.setUserAgentCallback((UserAgentCallback) userAgentCallBackClass.newInstance()); } } catch (Exception e) { log.error("Failed to set userAgentClassCallback object", e); } } param = StringUtils.trim(filterConfig.getInitParameter(FONT_PATHS_PARAM)); if (!StringUtils.isEmpty(param)) { String[] fontPaths = StringUtils.split(param, ";, \t\r\n"); pdfRenderer.setFontPaths(fontPaths); } }
From source file:au.org.paperminer.main.UserFilter.java
@Override public void init(FilterConfig config) throws ServletException { m_logger = Logger.getLogger(PaperMinerConstants.LOGGER); m_logger.info("AddUserFilter init"); ServletContext ctx = config.getServletContext(); m_serverName = ctx.getInitParameter("server-name"); m_logger.debug("Server=" + m_serverName); }