1 23 24 package javax.security.jacc; 25 26 import java.io.IOException ; 27 import java.io.ObjectStreamField ; 28 29 import javax.security.jacc.URLPatternSpec ; 30 import javax.security.jacc.HttpMethodSpec ; 31 32 import java.security.*; 33 34 import javax.servlet.http.HttpServletRequest ; 35 36 54 55 public final class WebResourcePermission extends Permission 56 implements java.io.Serializable 57 { 58 59 private transient HttpMethodSpec methodSpec; 60 61 private transient URLPatternSpec urlPatternSpec = null; 62 63 private transient int hashCodeValue = 0; 64 65 private transient static final String EMPTY_STRING = ""; 66 67 private static final long serialVersionUID = 1L; 68 69 76 private static final ObjectStreamField [] serialPersistentFields = { 77 new ObjectStreamField ("actions", java.lang.String .class) 78 }; 79 80 159 160 public WebResourcePermission(String name, String actions) 161 { 162 super(name); 163 this.urlPatternSpec = new URLPatternSpec (name); 164 this.methodSpec = HttpMethodSpec.getSpec(actions); 165 } 166 167 184 185 public WebResourcePermission(String urlPatternSpec, String [] HTTPMethods) 186 { 187 super(urlPatternSpec); 188 this.urlPatternSpec = new URLPatternSpec (urlPatternSpec); 189 this.methodSpec = HttpMethodSpec.getSpec(HTTPMethods); 190 } 191 192 205 206 public WebResourcePermission(HttpServletRequest request) 207 { 208 super(getUriMinusContextPath(request)); 209 this.urlPatternSpec = new URLPatternSpec (super.getName()); 210 this.methodSpec= HttpMethodSpec.getSpec(request.getMethod()); 211 } 212 213 233 234 public boolean equals(Object o) { 235 if (o == null || ! (o instanceof WebResourcePermission )) return false; 236 237 WebResourcePermission that = (WebResourcePermission ) o; 238 239 if (!this.methodSpec.equals(that.methodSpec)) return false; 240 241 return this.urlPatternSpec.equals(that.urlPatternSpec); 242 } 243 244 255 256 public String getActions() { 257 return this.methodSpec.getActions(); 258 } 259 260 277 278 public int hashCode() { 279 if (this.hashCodeValue == 0) { 280 String hashInput = new String (this.urlPatternSpec.toString()+ " " + 281 this.methodSpec.hashCode()); 282 283 this.hashCodeValue = hashInput.hashCode(); 284 } 285 return this.hashCodeValue; 286 } 287 288 332 public boolean implies(Permission permission) { 333 if (permission == null || 334 ! (permission instanceof WebResourcePermission )) return false; 335 336 WebResourcePermission that = (WebResourcePermission ) permission; 337 338 if (!this.methodSpec.implies(that.methodSpec)) 339 return false; 340 341 return this.urlPatternSpec.implies(that.urlPatternSpec); 342 } 343 344 346 352 private static String getUriMinusContextPath(HttpServletRequest request) { 353 String uri = request.getRequestURI(); 354 if (uri != null) { 355 String contextPath = request.getContextPath(); 356 int contextLength = contextPath == null ? 0 : contextPath.length(); 357 if (contextLength > 0) { 358 uri = uri.substring(contextLength); 359 } 360 if (uri.equals("/")) { 361 uri = EMPTY_STRING; 362 } 363 } else { 364 uri = EMPTY_STRING; 365 } 366 return uri; 367 } 368 369 376 private synchronized void readObject(java.io.ObjectInputStream s) 377 throws IOException ,ClassNotFoundException 378 { 379 this.methodSpec = HttpMethodSpec.getSpec 380 ((String ) s.readFields().get("actions",null)); 381 this.urlPatternSpec = new URLPatternSpec (super.getName()); 382 } 383 384 392 private synchronized void writeObject(java.io.ObjectOutputStream s) 393 throws IOException 394 { 395 s.putFields().put("actions",this.getActions()); 396 s.writeFields(); 397 } 398 399 } 400 401 402 403 | Popular Tags |