View Javadoc

1   package com.atlassian.security.auth.trustedapps;
2   
3   import java.util.Iterator;
4   import java.util.LinkedList;
5   import java.util.List;
6   import java.util.Set;
7   
8   /**
9    * Takes a set of patterns and assumes a URL matches if it starts with one of the given patterns.
10   */
11  public class DefaultURLMatcher implements URLMatcher
12  {
13      private final List patterns;
14  
15      public DefaultURLMatcher(Set patterns)
16      {
17          this.patterns = new LinkedList(patterns);
18      }
19  
20      /**
21       * returns true if the given URL starts with one of the given patterns and false otherwise
22       */
23      public boolean match(String urlPath)
24      {
25          if (patterns.isEmpty())
26          {
27              return true;
28          }
29          for (Iterator iterator = patterns.iterator(); iterator.hasNext();)
30          {
31              String pattern = (String) iterator.next();
32              if (urlPath.startsWith(pattern))
33              {
34                  return true;
35              }
36          }
37          return false;
38      }
39  }