Class RetainAnchorFilter

  • All Implemented Interfaces:
    javax.servlet.Filter, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.EnvironmentAware, org.springframework.core.env.EnvironmentCapable, org.springframework.web.context.ServletContextAware

    public class RetainAnchorFilter
    extends org.springframework.web.filter.GenericFilterBean
    Spring Security filter that preserves the URL anchor if the authentication process contains redirects (e.g. if the login is performed via CAS or form login). With standard redirects (default Spring Security behavior), Internet Explorer (6.0 and 8.0) discard the anchor part of the URL such that e.g. bookmarking does not work properly. Firefox re-appends the anchor part. This filter replaces redirects to URLs that match a certain pattern (storeUrlPattern) with a Javascript page that stores the URL anchor in a cookie, and replaces redirects to URLs that match another pattern ( restoreUrlPattern) with a Javascript page that restores the URL anchor from that cookie. The cookie name can be set via the attribute cookieName.
    See Also:
    Forum post of guidow08, Forum post of mpickell
    • Field Detail

      • storeUrlPattern

        private String storeUrlPattern
      • restoreUrlPattern

        private String restoreUrlPattern
      • cookieName

        private String cookieName
    • Constructor Detail

      • RetainAnchorFilter

        public RetainAnchorFilter()
    • Method Detail

      • setStoreUrlPattern

        public void setStoreUrlPattern​(String storeUrlPattern)
        Sets the url pattern for storing anchors.
        Parameters:
        storeUrlPattern - url regular expression
      • setRestoreUrlPattern

        public void setRestoreUrlPattern​(String restoreUrlPattern)
        Sets the url pattern for restoring anchors.
        Parameters:
        restoreUrlPattern - url regular expression
      • setCookieName

        public void setCookieName​(String cookieName)
        Sets the cookie name in which the anchor data should be saved.
        Parameters:
        cookieName - name of the cookie
      • doFilter

        public void doFilter​(javax.servlet.ServletRequest request,
                             javax.servlet.ServletResponse response,
                             javax.servlet.FilterChain chain)
                      throws IOException,
                             javax.servlet.ServletException
        Throws:
        IOException
        javax.servlet.ServletException