45 * 46 * @see java.security.Permission 47 * @see java.security.AccessController 48 * @see java.security.Permissions 49 * @see java.security.PermissionCollection 50 * @see java.lang.SecurityManager 51 * 52 * 53 * @author Roland Schemers 54 * 55 * @serial exclude 56 */ 57 58 public final class AllPermission extends Permission { 59 60 private static final long serialVersionUID = -2916474571451318075L; 61 62 /** 63 * Creates a new AllPermission object. 64 */ 65 66 public AllPermission() 67 { 68 super("<all permissions>"); 69 } 70 71 72 /** 73 * Creates a new AllPermission object. This 74 * constructor exists for use by the <code>Policy</code> object 75 * to instantiate new Permission objects. 76 * 77 * @param name ignored 78 * @param actions ignored. 79 */ 80 public AllPermission(String name, String actions) 81 { 82 this(); 83 } 84 85 /** 86 * Checks if the specified permission is "implied" by 87 * this object. This method always returns true. 88 * 89 * @param p the permission to check against. 90 * 91 * @return return 92 */ 93 public boolean implies(Permission p) { 94 return true; 95 } 96 97 /** 98 * Checks two AllPermission objects for equality. Two AllPermission 99 * objects are always equal. 100 * 101 * @param obj the object we are testing for equality with this object. 103 */ 104 public boolean equals(Object obj) { 105 return (obj instanceof AllPermission); 106 } 107 108 /** 109 * Returns the hash code value for this object. 110 * 111 * @return a hash code value for this object. 112 */ 113 114 public int hashCode() { 115 return 1; 116 } 117 118 /** 119 * Returns the canonical string representation of the actions. 120 * 121 * @return the actions. 122 */ 123 public String getActions() 124 { 125 return "<all actions>"; 126 } 127 128 /** 129 * Returns a new PermissionCollection object for storing AllPermission 130 * objects. 131 * <p> 132 * 133 * @return a new PermissionCollection object suitable for 134 * storing AllPermissions. 135 */ 136 137 public PermissionCollection newPermissionCollection() { 138 return new AllPermissionCollection(); 139 } 140 141 } 142 143 /** 144 * A AllPermissionCollection stores a collection 145 * of AllPermission permissions. AllPermission objects 146 * must be stored in a manner that allows them to be inserted in any 147 * order, but enable the implies function to evaluate the implies 148 * method in an efficient (and consistent) manner. 149 * 150 * @see java.security.Permission 151 * @see java.security.Permissions 152 * 153 * 154 * @author Roland Schemers 155 * 156 * @serial include 157 */ 158 159 final class AllPermissionCollection 160 extends PermissionCollection 161 implements java.io.Serializable 162 { 163 164 // use serialVersionUID from JDK 1.2.2 for interoperability 165 private static final long serialVersionUID = -4023755556366636806L; 166 167 private boolean all_allowed; // true if any all permissions have been added 168 169 /** 170 * Create an empty AllPermissions object. 171 * 172 */ 173 174 public AllPermissionCollection() { 175 all_allowed = false; 176 } 177 178 /** 179 * Adds a permission to the AllPermissions. The key for the hash is 180 * permission.path. 181 * 182 * @param permission the Permission object to add. 183 * 184 * @exception IllegalArgumentException - if the permission is not a 185 * AllPermission 186 * 187 * @exception SecurityException - if this AllPermissionCollection object 188 * has been marked readonly 189 */ 190 191 public void add(Permission permission) 192 { 193 if (! (permission instanceof AllPermission)) 194 throw new IllegalArgumentException("invalid permission: "+ 195 permission); 196 if (isReadOnly()) 197 throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection"); 198 199 all_allowed = true; // No sync; staleness OK 200 } 201 202 /** 203 * Check and see if this set of permissions implies the permissions 204 * expressed in "permission". 205 * 206 * @param p the Permission object to compare 207 * 208 * @return always returns true. 209 */ 210 211 public boolean implies(Permission permission) 212 { 213 return all_allowed; // No sync; staleness OK 214 } 215 216 /** 217 * Returns an enumeration of all the AllPermission objects in the 218 * container. 219 * 220 * @return an enumeration of all the AllPermission objects. 221 */ 222 public Enumeration<Permission> elements() 223 { 224 return new Enumeration<Permission>() { 225 private boolean hasMore = all_allowed; 226 227 public boolean hasMoreElements() { 228 return hasMore; 229 } 230 231 public Permission nextElement() { 232 hasMore = false; 233 return SecurityConstants.ALL_PERMISSION; 234 } 235 }; 236 } 237 } | 45 * 46 * @see java.security.Permission 47 * @see java.security.AccessController 48 * @see java.security.Permissions 49 * @see java.security.PermissionCollection 50 * @see java.lang.SecurityManager 51 * 52 * 53 * @author Roland Schemers 54 * 55 * @serial exclude 56 */ 57 58 public final class AllPermission extends Permission { 59 60 private static final long serialVersionUID = -2916474571451318075L; 61 62 /** 63 * Creates a new AllPermission object. 64 */ 65 public AllPermission() { 66 super("<all permissions>"); 67 } 68 69 70 /** 71 * Creates a new AllPermission object. This 72 * constructor exists for use by the <code>Policy</code> object 73 * to instantiate new Permission objects. 74 * 75 * @param name ignored 76 * @param actions ignored. 77 */ 78 public AllPermission(String name, String actions) { 79 this(); 80 } 81 82 /** 83 * Checks if the specified permission is "implied" by 84 * this object. This method always returns true. 85 * 86 * @param p the permission to check against. 87 * 88 * @return return 89 */ 90 public boolean implies(Permission p) { 91 return true; 92 } 93 94 /** 95 * Checks two AllPermission objects for equality. Two AllPermission 96 * objects are always equal. 97 * 98 * @param obj the object we are testing for equality with this object. 100 */ 101 public boolean equals(Object obj) { 102 return (obj instanceof AllPermission); 103 } 104 105 /** 106 * Returns the hash code value for this object. 107 * 108 * @return a hash code value for this object. 109 */ 110 111 public int hashCode() { 112 return 1; 113 } 114 115 /** 116 * Returns the canonical string representation of the actions. 117 * 118 * @return the actions. 119 */ 120 public String getActions() { 121 return "<all actions>"; 122 } 123 124 /** 125 * Returns a new PermissionCollection object for storing AllPermission 126 * objects. 127 * <p> 128 * 129 * @return a new PermissionCollection object suitable for 130 * storing AllPermissions. 131 */ 132 public PermissionCollection newPermissionCollection() { 133 return new AllPermissionCollection(); 134 } 135 136 } 137 138 /** 139 * A AllPermissionCollection stores a collection 140 * of AllPermission permissions. AllPermission objects 141 * must be stored in a manner that allows them to be inserted in any 142 * order, but enable the implies function to evaluate the implies 143 * method in an efficient (and consistent) manner. 144 * 145 * @see java.security.Permission 146 * @see java.security.Permissions 147 * 148 * 149 * @author Roland Schemers 150 * 151 * @serial include 152 */ 153 154 final class AllPermissionCollection 155 extends PermissionCollection 156 implements java.io.Serializable 157 { 158 159 // use serialVersionUID from JDK 1.2.2 for interoperability 160 private static final long serialVersionUID = -4023755556366636806L; 161 162 private boolean all_allowed; // true if any all permissions have been added 163 164 /** 165 * Create an empty AllPermissions object. 166 * 167 */ 168 169 public AllPermissionCollection() { 170 all_allowed = false; 171 } 172 173 /** 174 * Adds a permission to the AllPermissions. The key for the hash is 175 * permission.path. 176 * 177 * @param permission the Permission object to add. 178 * 179 * @exception IllegalArgumentException - if the permission is not a 180 * AllPermission 181 * 182 * @exception SecurityException - if this AllPermissionCollection object 183 * has been marked readonly 184 */ 185 186 public void add(Permission permission) { 187 if (! (permission instanceof AllPermission)) 188 throw new IllegalArgumentException("invalid permission: "+ 189 permission); 190 if (isReadOnly()) 191 throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection"); 192 193 all_allowed = true; // No sync; staleness OK 194 } 195 196 /** 197 * Check and see if this set of permissions implies the permissions 198 * expressed in "permission". 199 * 200 * @param permission the Permission object to compare 201 * 202 * @return always returns true. 203 */ 204 205 public boolean implies(Permission permission) { 206 return all_allowed; // No sync; staleness OK 207 } 208 209 /** 210 * Returns an enumeration of all the AllPermission objects in the 211 * container. 212 * 213 * @return an enumeration of all the AllPermission objects. 214 */ 215 public Enumeration<Permission> elements() { 216 return new Enumeration<Permission>() { 217 private boolean hasMore = all_allowed; 218 219 public boolean hasMoreElements() { 220 return hasMore; 221 } 222 223 public Permission nextElement() { 224 hasMore = false; 225 return SecurityConstants.ALL_PERMISSION; 226 } 227 }; 228 } 229 } |