Class AbstractCachePreventionFilter

  • All Implemented Interfaces:
    javax.servlet.Filter
    Direct Known Subclasses:
    ContentTypeBasedCachePreventionFilter, URLBasedCachePreventionFilter

    public abstract class AbstractCachePreventionFilter
    extends Object
    implements javax.servlet.Filter
    This filter implements browser/proxy cache prevention. It would prevent sensitive information being cached on web browsers and intermediate network devices that adhere to protocols HTTP 1.0 through HTTP 1.1. In order to accommodate future modifications to protocol specifications and introduction of custom cache prevention headers and values, the filter can also utilize headers and values that are defined in the web.xml file.
    Since:
    4.2.0
    • Constructor Detail

      • AbstractCachePreventionFilter

        public AbstractCachePreventionFilter()
    • Method Detail

      • init

        public void init​(javax.servlet.FilterConfig filterConfig)
                  throws javax.servlet.ServletException
        Specified by:
        init in interface javax.servlet.Filter
        Throws:
        javax.servlet.ServletException
      • initHeaders

        protected void initHeaders​(javax.servlet.FilterConfig filterConfig)
                            throws javax.servlet.ServletException
        This method will check for any headers defined in the web.xml. If any headers are found in the web.xml, those headers with the corresponding values will be set to prevent caching. If any headers aren't found in the web.xml, the default headers with values will be set for cache prevention.
        Parameters:
        filterConfig - Configurations specific to this filter in the web.xml
        Throws:
        javax.servlet.ServletException
      • initPatternsAndAction

        protected void initPatternsAndAction​(javax.servlet.FilterConfig filterConfig)
        Reading the filtering pattern and the action to be performed against the pattern from the web.xml. The pattern is a regex that could define content types or URLs. Multiple patterns can be defined in each new line.
        Parameters:
        filterConfig - Configurations specific to this filter in the web.xml
      • canApplyCachePreventionHeaders

        protected boolean canApplyCachePreventionHeaders​(String stringToBeMatched)
        Checks for a match with the filtering pattern and the Content Type/ URL.
        Parameters:
        stringToBeMatched - Requested URL or the Content Type in the response
        Returns:
        true for either to set headers for a match, or skip setting headers to a match
      • applyCachePreventionHeaders

        protected void applyCachePreventionHeaders​(javax.servlet.http.HttpServletResponse response)
        Setting cache prevention headers to responses.
        Parameters:
        response - HTTP Servlet Response
      • doFilter

        public abstract void doFilter​(javax.servlet.ServletRequest servletRequest,
                                      javax.servlet.ServletResponse servletResponse,
                                      javax.servlet.FilterChain filterChain)
                               throws IOException,
                                      javax.servlet.ServletException
        Specified by:
        doFilter in interface javax.servlet.Filter
        Throws:
        IOException
        javax.servlet.ServletException
      • destroy

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