1 7 8 package java.security; 9 10 import java.security.*; 11 import java.util.Enumeration ; 12 import java.util.Hashtable ; 13 import java.util.StringTokenizer ; 14 import sun.security.util.SecurityConstants; 15 16 40 41 public final class AllPermission extends Permission { 42 43 private static final long serialVersionUID = -2916474571451318075L; 44 45 48 49 public AllPermission() 50 { 51 super("<all permissions>"); 52 } 53 54 55 63 public AllPermission(String name, String actions) 64 { 65 this(); 66 } 67 68 76 public boolean implies(Permission p) { 77 return true; 78 } 79 80 87 public boolean equals(Object obj) { 88 return (obj instanceof AllPermission ); 89 } 90 91 96 97 public int hashCode() { 98 return 1; 99 } 100 101 106 public String getActions() 107 { 108 return "<all actions>"; 109 } 110 111 119 120 public PermissionCollection newPermissionCollection() { 121 return new AllPermissionCollection(); 122 } 123 124 } 125 126 142 143 final class AllPermissionCollection 144 extends PermissionCollection 145 implements java.io.Serializable 146 { 147 148 private static final long serialVersionUID = -4023755556366636806L; 150 151 private boolean all_allowed; 153 157 158 public AllPermissionCollection() { 159 all_allowed = false; 160 } 161 162 174 175 public void add(Permission permission) 176 { 177 if (! (permission instanceof AllPermission )) 178 throw new IllegalArgumentException ("invalid permission: "+ 179 permission); 180 if (isReadOnly()) 181 throw new SecurityException ("attempt to add a Permission to a readonly PermissionCollection"); 182 183 all_allowed = true; } 185 186 194 195 public boolean implies(Permission permission) 196 { 197 return all_allowed; } 199 200 206 public Enumeration elements() 207 { 208 return new Enumeration () { 209 private boolean hasMore = all_allowed; 210 211 public boolean hasMoreElements() { 212 return hasMore; 213 } 214 215 public Object nextElement() { 216 hasMore = false; 217 return SecurityConstants.ALL_PERMISSION; 218 } 219 }; 220 } 221 } 222 223 | Popular Tags |