1 28 29 package com.caucho.server.security; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.server.dispatch.UrlMap; 33 import com.caucho.server.util.CauchoSystem; 34 import com.caucho.util.L10N; 35 36 import java.util.ArrayList ; 37 import java.util.regex.Pattern ; 38 import java.util.regex.PatternSyntaxException ; 39 40 43 public class WebResourceCollection { 44 static L10N L = new L10N(WebResourceCollection.class); 45 46 public enum HttpMethod { GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE }; 47 48 private String _webResourceName; 49 private String _description; 50 private ArrayList <String > _methodList; 51 private ArrayList <Pattern > _urlPatternList = new ArrayList <Pattern >(); 52 53 54 57 public void setWebResourceName(String name) 58 { 59 _webResourceName = name; 60 } 61 62 65 public void setDescription(String name) 66 { 67 _description = name; 68 } 69 70 73 public void addURLPattern(String pattern) 74 throws PatternSyntaxException 75 { 76 String regexpPattern = UrlMap.urlPatternToRegexpPattern(pattern); 77 78 int flags = (CauchoSystem.isCaseInsensitive() ? 79 Pattern.CASE_INSENSITIVE : 80 0); 81 82 Pattern regexp = Pattern.compile(regexpPattern, flags); 83 84 _urlPatternList.add(regexp); 85 } 86 87 90 public ArrayList getURLPatternList() 91 { 92 return _urlPatternList; 93 } 94 95 98 public void addMethod(String method) 99 { 100 if (_methodList == null) 101 _methodList = new ArrayList <String >(); 102 103 _methodList.add(method); 104 } 105 106 109 public void addHttpMethod(String method) 110 { 111 if (! Pattern.matches("[a-zA-Z]+", method)) { 112 throw new ConfigException(L.l("'{0}' is not a valid http-method.", 113 method)); 114 } 115 116 133 134 if (_methodList == null) 135 _methodList = new ArrayList <String >(); 136 137 _methodList.add(method); 138 } 139 140 143 public ArrayList <String > getMethods() 144 { 145 return _methodList; 146 } 147 148 151 public boolean isMatch(String url) 152 { 153 if (_urlPatternList.size() == 0) 154 return true; 155 156 for (int i = 0; i < _urlPatternList.size(); i++) { 157 Pattern pattern = _urlPatternList.get(i); 158 159 if (pattern.matcher(url).find()) 160 return true; 161 } 162 163 return false; 164 } 165 } 166 | Popular Tags |