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