1 17 18 19 package org.apache.catalina.deploy; 20 21 22 import org.apache.catalina.util.RequestUtil; 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 27 import java.io.Serializable ; 28 29 30 44 45 public class SecurityCollection implements Serializable { 46 47 private static Log log = LogFactory.getLog(SecurityCollection.class); 48 49 50 52 53 56 public SecurityCollection() { 57 58 this(null, null); 59 60 } 61 62 63 68 public SecurityCollection(String name) { 69 70 this(name, null); 71 72 } 73 74 75 81 public SecurityCollection(String name, String description) { 82 83 super(); 84 setName(name); 85 setDescription(description); 86 87 } 88 89 90 92 93 96 private String description = null; 97 98 99 102 private String methods[] = new String [0]; 103 104 105 108 private String name = null; 109 110 111 114 private String patterns[] = new String [0]; 115 116 117 119 120 123 public String getDescription() { 124 125 return (this.description); 126 127 } 128 129 130 135 public void setDescription(String description) { 136 137 this.description = description; 138 139 } 140 141 142 145 public String getName() { 146 147 return (this.name); 148 149 } 150 151 152 157 public void setName(String name) { 158 159 this.name = name; 160 161 } 162 163 164 166 167 170 public void addMethod(String method) { 171 172 if (method == null) 173 return; 174 String results[] = new String [methods.length + 1]; 175 for (int i = 0; i < methods.length; i++) 176 results[i] = methods[i]; 177 results[methods.length] = method; 178 methods = results; 179 180 } 181 182 183 186 public void addPattern(String pattern) { 187 188 if (pattern == null) 189 return; 190 191 if(pattern.endsWith("*")) { 193 if (pattern.charAt(pattern.length()-1) != '/') { 194 if (log.isDebugEnabled()) { 195 log.warn("Suspicious url pattern: \"" + pattern + "\"" + 196 " - see http://java.sun.com/aboutJava/communityprocess/first/jsr053/servlet23_PFD.pdf" + 197 " section 11.2" ); 198 } 199 } 200 } 201 202 pattern = RequestUtil.URLDecode(pattern); 203 String results[] = new String [patterns.length + 1]; 204 for (int i = 0; i < patterns.length; i++) { 205 results[i] = patterns[i]; 206 } 207 results[patterns.length] = pattern; 208 patterns = results; 209 210 } 211 212 213 219 public boolean findMethod(String method) { 220 221 if (methods.length == 0) 222 return (true); 223 for (int i = 0; i < methods.length; i++) { 224 if (methods[i].equals(method)) 225 return (true); 226 } 227 return (false); 228 229 } 230 231 232 237 public String [] findMethods() { 238 239 return (methods); 240 241 } 242 243 244 249 public boolean findPattern(String pattern) { 250 251 for (int i = 0; i < patterns.length; i++) { 252 if (patterns[i].equals(pattern)) 253 return (true); 254 } 255 return (false); 256 257 } 258 259 260 265 public String [] findPatterns() { 266 267 return (patterns); 268 269 } 270 271 272 278 public void removeMethod(String method) { 279 280 if (method == null) 281 return; 282 int n = -1; 283 for (int i = 0; i < methods.length; i++) { 284 if (methods[i].equals(method)) { 285 n = i; 286 break; 287 } 288 } 289 if (n >= 0) { 290 int j = 0; 291 String results[] = new String [methods.length - 1]; 292 for (int i = 0; i < methods.length; i++) { 293 if (i != n) 294 results[j++] = methods[i]; 295 } 296 methods = results; 297 } 298 299 } 300 301 302 308 public void removePattern(String pattern) { 309 310 if (pattern == null) 311 return; 312 int n = -1; 313 for (int i = 0; i < patterns.length; i++) { 314 if (patterns[i].equals(pattern)) { 315 n = i; 316 break; 317 } 318 } 319 if (n >= 0) { 320 int j = 0; 321 String results[] = new String [patterns.length - 1]; 322 for (int i = 0; i < patterns.length; i++) { 323 if (i != n) 324 results[j++] = patterns[i]; 325 } 326 patterns = results; 327 } 328 329 } 330 331 332 335 public String toString() { 336 337 StringBuffer sb = new StringBuffer ("SecurityCollection["); 338 sb.append(name); 339 if (description != null) { 340 sb.append(", "); 341 sb.append(description); 342 } 343 sb.append("]"); 344 return (sb.toString()); 345 346 } 347 348 349 } 350 | Popular Tags |