Class GlobalHeadersFilter

  • All Implemented Interfaces:
    javax.servlet.Filter

    public class GlobalHeadersFilter
    extends java.lang.Object
    implements javax.servlet.Filter
    Implementation of Servlet filter that adds one or more headers to each and every HTTP response.

    The headers and their values are specified as a comma-separated list in the headerConfig parameter in the filter config. If a header value happens to have commas, specify it within quotes.

    The headers will be added to every resource that matches the 'url-pattern' specified in the filter-mapping configuring the filter.

    For example, the snippet from WEB.XML below will cause the following three headers

    • X-XSS-Protection:1; mode=block
    • Cache-Control: no-cache, no-store, must-revalidate
    • X-Content-Type-Options:nosniff
    to be added as HTTP headers to all (*) responses.

    <filter> <filter-name>GlobalHeaders</filter-name> <filter-class>com.microstrategy.web.filter.GlobalHeadersFilter</filter-class> <init-param> <param-name>headerConfig</param-name> <param-value> X-XSS-Protection:1; mode=block, "Cache-Control: no-cache, no-store, must-revalidate", X-Content-Type-Options:nosniff </param-value> </init-param> </filter> <filter-mapping> <filter-name>GlobalHeaders</filter-name> <url-pattern>*</url-pattern> </filter-mapping>

    The filter can be configured multiple times using different url-pattern to apply different headers to different file types

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()  
      void doFilter​(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
      Called once per HTTP request that matches the "url-pattern" as set in the servlet's configuration.
      void init​(javax.servlet.FilterConfig cfg)
      Called once to initialize the filter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GlobalHeadersFilter

        public GlobalHeadersFilter()
    • Method Detail

      • doFilter

        public void doFilter​(javax.servlet.ServletRequest request,
                             javax.servlet.ServletResponse response,
                             javax.servlet.FilterChain chain)
                      throws java.io.IOException,
                             javax.servlet.ServletException
        Called once per HTTP request that matches the "url-pattern" as set in the servlet's configuration.
        Specified by:
        doFilter in interface javax.servlet.Filter
        Throws:
        java.io.IOException
        javax.servlet.ServletException
        See Also:
        Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
      • init

        public void init​(javax.servlet.FilterConfig cfg)
                  throws javax.servlet.ServletException
        Called once to initialize the filter. Since only one instance is ever created the data loaded into member variables is shared across all HTTP requests. i.e. no need to make this stuff static.
        Specified by:
        init in interface javax.servlet.Filter
        Throws:
        javax.servlet.ServletException
        See Also:
        Filter.init(javax.servlet.FilterConfig)
      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Filter