Esempio n. 1
0
 private void InitializeMaxAge(FilterConfig filterConfig)
 {
     maxAge = filterConfig.GetInitParameter(MaxAge);
     if (maxAge == null)
     {
         maxAge = MaxAgeDefault;
     }
     Log.Info("Max Age: " + maxAge);
 }
Esempio n. 2
0
        private void InitializeAllowedHeaders(FilterConfig filterConfig)
        {
            string allowedHeadersConfig = filterConfig.GetInitParameter(AllowedHeaders);

            if (allowedHeadersConfig == null)
            {
                allowedHeadersConfig = AllowedHeadersDefault;
            }
            Collections.AddAll(allowedHeaders, Arrays.AsList(allowedHeadersConfig.Trim
                                                                 ().Split("\\s*,\\s*")));
            Log.Info("Allowed Headers: " + GetAllowedHeadersHeader());
        }
Esempio n. 3
0
 //update the proxy IP list about every 5 min
 /// <exception cref="Javax.Servlet.ServletException"/>
 public virtual void Init(FilterConfig conf)
 {
     // Maintain for backwards compatibility
     if (conf.GetInitParameter(ProxyHost) != null && conf.GetInitParameter(ProxyUriBase
                                                                           ) != null)
     {
         proxyHosts             = new string[] { conf.GetInitParameter(ProxyHost) };
         proxyUriBases          = new Dictionary <string, string>(1);
         proxyUriBases["dummy"] = conf.GetInitParameter(ProxyUriBase);
     }
     else
     {
         proxyHosts = conf.GetInitParameter(ProxyHosts).Split(ProxyHostsDelimiter);
         string[] proxyUriBasesArr = conf.GetInitParameter(ProxyUriBases).Split(ProxyUriBasesDelimiter
                                                                                );
         proxyUriBases = new Dictionary <string, string>(proxyUriBasesArr.Length);
         foreach (string proxyUriBase in proxyUriBasesArr)
         {
             try
             {
                 Uri url = new Uri(proxyUriBase);
                 proxyUriBases[url.GetHost() + ":" + url.Port] = proxyUriBase;
             }
             catch (UriFormatException e)
             {
                 Log.Warn("{} does not appear to be a valid URL", proxyUriBase, e);
             }
         }
     }
 }
Esempio n. 4
0
        private void InitializeAllowedOrigins(FilterConfig filterConfig)
        {
            string allowedOriginsConfig = filterConfig.GetInitParameter(AllowedOrigins);

            if (allowedOriginsConfig == null)
            {
                allowedOriginsConfig = AllowedOriginsDefault;
            }
            Collections.AddAll(allowedOrigins, Arrays.AsList(allowedOriginsConfig.Trim
                                                                 ().Split("\\s*,\\s*")));
            allowAllOrigins = allowedOrigins.Contains("*");
            Log.Info("Allowed Origins: " + StringUtils.Join(allowedOrigins, ','));
            Log.Info("Allow All Origins: " + allowAllOrigins);
        }
        /// <summary>Returns the filtered configuration (only properties starting with the specified prefix).
        ///     </summary>
        /// <remarks>
        /// Returns the filtered configuration (only properties starting with the specified prefix). The property keys
        /// are also trimmed from the prefix. The returned
        /// <see cref="Properties"/>
        /// object is used to initialized the
        /// <see cref="AuthenticationHandler"/>
        /// .
        /// <p>
        /// This method can be overriden by subclasses to obtain the configuration from other configuration source than
        /// the web.xml file.
        /// </remarks>
        /// <param name="configPrefix">configuration prefix to use for extracting configuration properties.
        ///     </param>
        /// <param name="filterConfig">filter configuration object</param>
        /// <returns>
        /// the configuration to be used with the
        /// <see cref="AuthenticationHandler"/>
        /// instance.
        /// </returns>
        /// <exception cref="Javax.Servlet.ServletException">thrown if the configuration could not be created.
        ///     </exception>
        protected internal virtual Properties GetConfiguration(string configPrefix, FilterConfig
                                                               filterConfig)
        {
            Properties           props = new Properties();
            Enumeration <object> names = filterConfig.GetInitParameterNames();

            while (names.MoveNext())
            {
                string name = (string)names.Current;
                if (name.StartsWith(configPrefix))
                {
                    string value = filterConfig.GetInitParameter(name);
                    props[Runtime.Substring(name, configPrefix.Length)] = value;
                }
            }
            return(props);
        }
Esempio n. 6
0
        /// <summary>Returns the proxyuser configuration.</summary>
        /// <remarks>
        /// Returns the proxyuser configuration. All returned properties must start
        /// with <code>proxyuser.</code>'
        /// <p/>
        /// Subclasses may override this method if the proxyuser configuration is
        /// read from other place than the filter init parameters.
        /// </remarks>
        /// <param name="filterConfig">filter configuration object</param>
        /// <returns>the proxyuser configuration properties.</returns>
        /// <exception cref="Javax.Servlet.ServletException">thrown if the configuration could not be created.
        ///     </exception>
        protected internal virtual Configuration GetProxyuserConfiguration(FilterConfig filterConfig
                                                                           )
        {
            // 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 <object> names = filterConfig.GetInitParameterNames();

            while (names.MoveNext())
            {
                string name = (string)names.Current;
                if (name.StartsWith(ProxyuserPrefix + "."))
                {
                    string value = filterConfig.GetInitParameter(name);
                    conf.Set(name, value);
                }
            }
            return(conf);
        }
        /// <summary>
        /// <p>Initializes the authentication filter and signer secret provider.</p>
        /// It instantiates and initializes the specified
        /// <see cref="AuthenticationHandler"/>
        /// .
        /// </summary>
        /// <param name="filterConfig">filter configuration.</param>
        /// <exception cref="Javax.Servlet.ServletException">thrown if the filter or the authentication handler could not be initialized properly.
        ///     </exception>
        public virtual void Init(FilterConfig filterConfig)
        {
            string configPrefix = filterConfig.GetInitParameter(ConfigPrefix);

            configPrefix = (configPrefix != null) ? configPrefix + "." : string.Empty;
            config       = GetConfiguration(configPrefix, filterConfig);
            string authHandlerName = config.GetProperty(AuthType, null);
            string authHandlerClassName;

            if (authHandlerName == null)
            {
                throw new ServletException("Authentication type must be specified: " + PseudoAuthenticationHandler
                                           .Type + "|" + KerberosAuthenticationHandler.Type + "|<class>");
            }
            if (authHandlerName.ToLower(Extensions.GetEnglishCulture()).Equals(PseudoAuthenticationHandler
                                                                               .Type))
            {
                authHandlerClassName = typeof(PseudoAuthenticationHandler).FullName;
            }
            else
            {
                if (authHandlerName.ToLower(Extensions.GetEnglishCulture()).Equals(KerberosAuthenticationHandler
                                                                                   .Type))
                {
                    authHandlerClassName = typeof(KerberosAuthenticationHandler).FullName;
                }
                else
                {
                    authHandlerClassName = authHandlerName;
                }
            }
            validity = long.Parse(config.GetProperty(AuthTokenValidity, "36000")) * 1000;
            //10 hours
            InitializeSecretProvider(filterConfig);
            InitializeAuthHandler(authHandlerClassName, filterConfig);
            cookieDomain = config.GetProperty(CookieDomain, null);
            cookiePath   = config.GetProperty(CookiePath, null);
        }
Esempio n. 8
0
 /// <exception cref="Javax.Servlet.ServletException"/>
 public virtual void Init(FilterConfig conf)
 {
     this.username = conf.GetInitParameter(CommonConfigurationKeys.HadoopHttpStaticUser
                                           );
     this.user = new StaticUserWebFilter.User(username);
 }