Class OncePerRequestFilter

    • Constructor Detail

      • OncePerRequestFilter

        public OncePerRequestFilter()
    • Method Detail

      • isEnabled

        public boolean isEnabled()
        Returns true if this filter should generally* execute for any request, false if it should let the request/response pass through immediately to the next element in the FilterChain. The default value is true, as most filters would inherently need to execute when configured.

        * This configuration property is for general configuration for any request that comes through the filter. The isEnabled(request,response) method actually determines whether or not if the filter is enabled based on the current request.

        Returns:
        true if this filter should generally execute, false if it should let the request/response pass through immediately to the next element in the FilterChain.
        Since:
        1.2
      • setEnabled

        public void setEnabled​(boolean enabled)
        Sets whether or not this filter generally executes for any request. See the isEnabled() JavaDoc as to what general execution means.
        Parameters:
        enabled - whether or not this filter generally executes.
        Since:
        1.2
      • isEnabled

        protected boolean isEnabled​(javax.servlet.ServletRequest request,
                                    javax.servlet.ServletResponse response)
                             throws javax.servlet.ServletException,
                                    IOException
        Returns true if this filter should filter the specified request, false if it should let the request/response pass through immediately to the next element in the FilterChain.

        This default implementation merely returns the value of isEnabled(), which is true by default (to ensure the filter always executes by default), but it can be overridden by subclasses for request-specific behavior if necessary. For example, a filter could be enabled or disabled based on the request path being accessed.

        Helpful Hint: if your subclass extends PathMatchingFilter, you may wish to instead override the PathMatchingFilter.isEnabled(request,response,path,pathSpecificConfig) method if you want to make your enable/disable decision based on any path-specific configuration.

        Parameters:
        request - the incoming servlet request
        response - the outbound servlet response
        Returns:
        true if this filter should filter the specified request, false if it should let the request/response pass through immediately to the next element in the FilterChain.
        Throws:
        IOException - in the case of any IO error
        javax.servlet.ServletException - in the case of any error
        Since:
        1.2
        See Also:
        PathMatchingFilter.isEnabled(javax.servlet.ServletRequest, javax.servlet.ServletResponse, String, Object)
      • getAlreadyFilteredAttributeName

        protected String getAlreadyFilteredAttributeName()
        Return name of the request attribute that identifies that a request has already been filtered.

        The default implementation takes the configured name and appends ".FILTERED". If the filter is not fully initialized, it falls back to the implementation's class name.

        Returns:
        the name of the request attribute that identifies that a request has already been filtered.
        See Also:
        NameableFilter.getName(), ALREADY_FILTERED_SUFFIX
      • shouldNotFilter

        @Deprecated
        protected boolean shouldNotFilter​(javax.servlet.ServletRequest request)
                                   throws javax.servlet.ServletException
        Deprecated.
        in favor of overriding isEnabled(javax.servlet.ServletRequest, javax.servlet.ServletResponse) for custom behavior. This method will be removed in Shiro 2.0.
        Can be overridden in subclasses for custom filtering control, returning true to avoid filtering of the given request.

        The default implementation always returns false.

        Parameters:
        request - current HTTP request
        Returns:
        whether the given request should not be filtered
        Throws:
        javax.servlet.ServletException - in case of errors
      • doFilterInternal

        protected abstract void doFilterInternal​(javax.servlet.ServletRequest request,
                                                 javax.servlet.ServletResponse response,
                                                 javax.servlet.FilterChain chain)
                                          throws javax.servlet.ServletException,
                                                 IOException
        Same contract as for doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain), but guaranteed to be invoked only once per request.
        Parameters:
        request - incoming ServletRequest
        response - outgoing ServletResponse
        chain - the FilterChain to execute
        Throws:
        javax.servlet.ServletException - if there is a problem processing the request
        IOException - if there is an I/O problem processing the request