Class PluginFilter

  • All Implemented Interfaces:
    javax.servlet.Filter

    public class PluginFilter
    extends Object
    implements javax.servlet.Filter
    A servlet filter that plugin classes can use to dynamically register and un-register filter logic. The original, now deprecated, filter logic that each plugin can register was fairly limited; instead of having full control over the filter chain, each instance of PluginFilter.SimpleFilter only has the ability to use the ServletRequest and ServletResponse objects and then return true if further filters in the chain should be run. The new, non-deprecated functionality allows for regular Filter instances to be registered with this class, which removes much of the limitations that was present in the SimpleFilter approach. This implementation assumes, but does not enforce, that filters installed by plugins are applied to URL patterns that match the plugin. When filters installed by different plugins are applied to the same URL, the behavior of this implementation is undetermined.
    Author:
    Matt Tucker, Guus der Kinderen, guus.der.kinderen@gmail.com
    • Constructor Detail

      • PluginFilter

        public PluginFilter()
    • Method Detail

      • addPluginFilter

        public static void addPluginFilter​(String filterUrl,
                                           javax.servlet.Filter filter)
        Adds a filter to the list of filters that will be run on every request of which the URL matches the URL that is registered with this filter. More specifically, the request URL should be equal to, or start with, the filter URL. Multiple filters can be registered on the same URL, in which case they will be executed in the order in which they were added. Adding a filter does not initialize the plugin instance.
        Parameters:
        filterUrl - The URL pattern to which the filter is to be applied. Cannot be null nor an empty string.
        filter - The filter. Cannot be null.
      • removePluginFilter

        @Deprecated
        public static void removePluginFilter​(PluginFilter.SimpleFilter filter)
        Deprecated.
        Removes a filter from the list of filters that will be run on every request. This method should be called by plugins when shutting down.
        Parameters:
        filter - the filter.
      • removePluginFilter

        public static javax.servlet.Filter removePluginFilter​(String filterUrl,
                                                              String filterClassName)
        Removes a filter that is applied to a certain URL. Removing a filter does not destroy the plugin instance.
        Parameters:
        filterUrl - The URL pattern to which the filter is applied. Cannot be null nor an empty string.
        filterClassName - The filter class name. Cannot be null or empty string.
        Returns:
        The filter instance that was removed, or null if the URL and name combination did not match a filter.
      • init

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

        public void doFilter​(javax.servlet.ServletRequest servletRequest,
                             javax.servlet.ServletResponse servletResponse,
                             javax.servlet.FilterChain filterChain)
                      throws IOException,
                             javax.servlet.ServletException
        This class is a Filter implementation itself. It acts as a dynamic proxy to filters that are registered by Openfire plugins.
        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