JSEC-120 - added PatternMatcher interface to support pluggable pattern matching implementations for configuration

git-svn-id: https://svn.apache.org/repos/asf/incubator/jsecurity/trunk@711066 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/org/jsecurity/util/AntPathMatcher.java b/src/org/jsecurity/util/AntPathMatcher.java
index 65d77c6..723c6c6 100644
--- a/src/org/jsecurity/util/AntPathMatcher.java
+++ b/src/org/jsecurity/util/AntPathMatcher.java
@@ -60,7 +60,7 @@
  * @author Rob Harrop
  * @since 16.07.2003
  */
-public class AntPathMatcher {
+public class AntPathMatcher implements PatternMatcher {
 
     /**
      * Default path separator: "/"
@@ -83,6 +83,10 @@
         return (path.indexOf('*') != -1 || path.indexOf('?') != -1);
     }
 
+    public boolean matches(String pattern, String source) {
+        return match(pattern, source);
+    }
+
     public boolean match(String pattern, String path) {
         return doMatch(pattern, path, true);
     }
diff --git a/src/org/jsecurity/util/PatternMatcher.java b/src/org/jsecurity/util/PatternMatcher.java
new file mode 100644
index 0000000..e2bddab
--- /dev/null
+++ b/src/org/jsecurity/util/PatternMatcher.java
@@ -0,0 +1,43 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *     http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.jsecurity.util;

+

+/**

+ * Interface for components that can match source strings against a specified pattern string.

+ * <p/>

+ * Different implementations can support different pattern types, for example, Ant style path expressions, or

+ * regular expressions, or other types of text based patterns.

+ *

+ * @author Les Hazlewood

+ * @see org.jsecurity.util.AntPathMatcher AntPathMatcher

+ * @since 0.9 RC2

+ */

+public interface PatternMatcher {

+

+    /**

+     * Returns <code>true</code> if the given <code>source</code> matches the specified <code>pattern</code>,

+     * <code>false</code> otherwise.

+     *

+     * @param pattern the pattern to match against

+     * @param source  the source to match

+     * @return <code>true</code> if the given <code>source</code> matches the specified <code>pattern</code>,

+     *         <code>false</code> otherwise.

+     */

+    boolean matches(String pattern, String source);

+}

diff --git a/src/org/jsecurity/web/config/IniWebConfiguration.java b/src/org/jsecurity/web/config/IniWebConfiguration.java
index c858fd8..b537d4f 100644
--- a/src/org/jsecurity/web/config/IniWebConfiguration.java
+++ b/src/org/jsecurity/web/config/IniWebConfiguration.java
@@ -25,6 +25,7 @@
 import org.jsecurity.config.ReflectionBuilder;
 import org.jsecurity.mgt.RealmSecurityManager;
 import org.jsecurity.util.AntPathMatcher;
+import org.jsecurity.util.PatternMatcher;
 import static org.jsecurity.util.StringUtils.split;
 import org.jsecurity.web.DefaultWebSecurityManager;
 import org.jsecurity.web.WebUtils;
@@ -49,7 +50,7 @@
  */
 public class IniWebConfiguration extends IniConfiguration implements WebConfiguration {
 
-    private static final Log log = LogFactory.getLog(IniWebConfiguration.class);    
+    private static final Log log = LogFactory.getLog(IniWebConfiguration.class);
 
     public static final String FILTERS = "filters";
     public static final String URLS = "urls";
@@ -58,7 +59,7 @@
 
     protected Map<String, List<Filter>> chains;
 
-    protected AntPathMatcher pathMatcher = new AntPathMatcher();
+    protected PatternMatcher pathMatcher = new AntPathMatcher();
 
     public IniWebConfiguration() {
         chains = new LinkedHashMap<String, List<Filter>>();
@@ -82,7 +83,7 @@
         for (String path : this.chains.keySet()) {
 
             // If the path does match, then pass on to the subclass implementation for specific checks:
-            if (pathMatcher.match(path, requestURI)) {
+            if (pathMatches(path, requestURI)) {
                 if (log.isTraceEnabled()) {
                     log.trace("Matched path [" + path + "] for requestURI [" + requestURI + "].  " +
                             "Utilizing corresponding filter chain...");
@@ -97,6 +98,23 @@
         return null;
     }
 
+    /**
+     * Returns <code>true</code> if the <code>path</code> matches the specified <code>pattern</code> string,
+     * <code>false</code> otherwise.
+     * <p/>
+     * Simply delegates to
+     * <b><code>this.pathMatcher.{@link org.jsecurity.util.PatternMatcher#matches(String, String) matches(pattern,path)}</code></b>,
+     * but can be overridden by subclasses for custom matching behavior.
+     *
+     * @param pattern the pattern to match against
+     * @param path    the value to match with the specified <code>pattern</code>
+     * @return <code>true</code> if the <code>path</code> matches the specified <code>pattern</code> string,
+     *         <code>false</code> otherwise.
+     */
+    protected boolean pathMatches(String pattern, String path) {
+        return pathMatcher.matches(pattern, path);
+    }
+
     protected String getPathWithinApplication(ServletRequest request) {
         return WebUtils.getPathWithinApplication(WebUtils.toHttp(request));
     }
diff --git a/src/org/jsecurity/web/filter/PathMatchingFilter.java b/src/org/jsecurity/web/filter/PathMatchingFilter.java
index bfccf23..ab0173c 100644
--- a/src/org/jsecurity/web/filter/PathMatchingFilter.java
+++ b/src/org/jsecurity/web/filter/PathMatchingFilter.java
@@ -21,6 +21,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jsecurity.util.AntPathMatcher;
+import org.jsecurity.util.PatternMatcher;
 import static org.jsecurity.util.StringUtils.split;
 import org.jsecurity.web.WebUtils;
 import org.jsecurity.web.servlet.AdviceFilter;
@@ -39,11 +40,15 @@
  */
 public abstract class PathMatchingFilter extends AdviceFilter implements PathConfigProcessor {
 
-    /** Log available to this class only */
+    /**
+     * Log available to this class only
+     */
     private static final Log log = LogFactory.getLog(PathMatchingFilter.class);
 
-    /** PathMatcher used in determining which paths to react to for a given request. */
-    protected AntPathMatcher pathMatcher = new AntPathMatcher();
+    /**
+     * PatternMatcher used in determining which paths to react to for a given request.
+     */
+    protected PatternMatcher pathMatcher = new AntPathMatcher();
 
     /**
      * A collection of path-to-config entries where the key is a path which this filter should process and
@@ -68,7 +73,8 @@
      *
      * this.{@link #appliedPaths appliedPaths}.put(path, values);
      * </code></pre>
-     * @param path the application context path to match for executing this filter.
+     *
+     * @param path   the application context path to match for executing this filter.
      * @param config the specified for <em>this particular filter only</em> for the given <code>path</code>
      */
     public void processPathConfig(String path, String config) {
@@ -122,7 +128,7 @@
      * <code>false</code> otherwise.
      * <p/>
      * Simply delegates to
-     * <b><code>this.pathMatcher.{@link AntPathMatcher#match(String, String) match(pattern,path)}</code></b>,
+     * <b><code>this.pathMatcher.{@link PatternMatcher#matches(String, String) matches(pattern,path)}</code></b>,
      * but can be overridden by subclasses for custom matching behavior.
      *
      * @param pattern the pattern to match against
@@ -131,7 +137,7 @@
      *         <code>false</code> otherwise.
      */
     protected boolean pathsMatch(String pattern, String path) {
-        return pathMatcher.match(pattern, path);
+        return pathMatcher.matches(pattern, path);
     }
 
     /**