1 23 package com.sun.enterprise.security.acl; 24 25 import java.security.Principal ; 26 29 public class WebResource extends Resource { 30 private transient boolean wildcard; 31 private transient String path; 32 33 public WebResource(String app, String name, String method) { 34 super(app,name,method); 35 init(name); 36 } 37 38 private void init(String name) 39 { 40 if (name == null) 41 throw new IllegalArgumentException ("name can't be null"); 42 43 if (name.endsWith("/*") || name.equals("*")) { 44 wildcard = true; 45 if (name.length() == 1) { 46 path = ""; 47 } else { 48 path = name.substring(0, name.length()-1); 49 } 50 } else { 51 path = name; 52 } 53 } 54 55 public boolean equals(Object obj) { 56 if(obj == this) 57 return true; 58 59 if ((obj == null) || (obj.getClass() != getClass())) 60 return false; 61 62 Resource r = (Resource) obj; 63 64 return getApplication().equals(r.getApplication()) && 65 getMethod().equals(r.getMethod()) && 66 getName().equals(r.getName()); 67 } 68 69 public boolean implies(Resource resource) { 70 if(( resource == null) || (resource.getClass() != getClass())) 71 return false; 72 73 WebResource that = (WebResource) resource; 74 75 if(!getMethod().equals(that.getMethod())) 77 return false; 78 79 if(this.wildcard) { 80 if (that.wildcard) 81 return that.path.startsWith(path); 83 else 84 return (that.path.length() > this.path.length()) && 86 that.path.startsWith(this.path); 87 } else { 88 if (that.wildcard) { 89 return false; 91 } 92 else { 93 return this.path.equals(that.path); 94 } 95 } 96 } 97 } 98 | Popular Tags |