Class Whitelist


  • public class Whitelist
    extends java.lang.Object
    A URL whitelist. This object is immutable and the list of matching patterns and the HTTP status code is unmodifiable after creation. Enabling, disabling, or modifying the whitelist can be safely and easily accomplished by updating the whitelist reference to a new whitelist.
    • Constructor Summary

      Constructors 
      Constructor Description
      Whitelist()
      Creates an empty, disabled Whitelist.
      Whitelist​(int statusCode)
      Creates an empty, enabled whitelist with the specified response code.
      Whitelist​(java.lang.String[] patterns, int statusCode)
      Whitelist​(java.util.Collection<java.lang.String> patterns, int statusCode)
      Creates a whitelist for the specified patterns, returning the given statusCode when a URL does not match one of the patterns.
    • Field Detail

      • WHITELIST_DISABLED

        public static final Whitelist WHITELIST_DISABLED
        A disabled Whitelist.
    • Constructor Detail

      • Whitelist

        public Whitelist()
        Creates an empty, disabled Whitelist.
      • Whitelist

        public Whitelist​(int statusCode)
        Creates an empty, enabled whitelist with the specified response code.
        Parameters:
        statusCode - the response code that the (enabled) Whitelist will return for all URLs.
      • Whitelist

        @Deprecated
        public Whitelist​(java.lang.String[] patterns,
                         int statusCode)
        Parameters:
        patterns - String[] patterns
        statusCode - int statusCode
      • Whitelist

        public Whitelist​(java.util.Collection<java.lang.String> patterns,
                         int statusCode)
        Creates a whitelist for the specified patterns, returning the given statusCode when a URL does not match one of the patterns. A null or empty collection will result in an empty whitelist.
        Parameters:
        patterns - URL-matching regular expression patterns to whitelist
        statusCode - the HTTP status code to return when a request URL matches a whitelist pattern
    • Method Detail

      • isEnabled

        public boolean isEnabled()
        Returns:
        true if this whitelist is enabled, otherwise false
      • getPatterns

        public java.util.Collection<java.util.regex.Pattern> getPatterns()
        Returns:
        regular expression patterns describing the URLs that should be whitelisted, or an empty collection if the whitelist is disabled
      • getStatusCode

        public int getStatusCode()
        Returns:
        HTTP status code returned by the whitelist, or -1 if the whitelist is disabled
      • getResponseCode

        @Deprecated
        public int getResponseCode()
        Deprecated.
        Returns:
        response code
      • matches

        public boolean matches​(java.lang.String url)
        Returns true if the specified URL matches a whitelisted URL regular expression. If the whitelist is disabled, this method always returns false.
        Parameters:
        url - URL to match against the whitelist
        Returns:
        true if the whitelist is enabled and the URL matched an entry in the whitelist, otherwise false