- Timestamp:
- Apr 27, 2004, 8:39:34 PM (22 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
libjava/java/security/BasicPermission.java (modified) (5 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libjava/java/security/BasicPermission.java
-
Property cvs2svn:cvs-rev
changed from
1.1to1.1.1.2
r1390 r1391 1 /* BasicPermission.java -- Implements a simple named permission.2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.1 /* BasicPermission.java -- 2 Copyright (C) 1998, 1999 Free Software Foundation, Inc. 3 3 4 4 This file is part of GNU Classpath. … … 45 45 * This class implements a simple model for named permissions without an 46 46 * associated action list. That is, either the named permission is granted 47 * or it is not. 48 * <p>49 * It also supports trailing wildcards to allow the50 * easy granting of permissions in a hierarchical fashion. (For example,51 * the name "org.gnu.*" might grant all permissions under the "org.gnu"52 * permissions hierarchy). The only valid wildcard character is a '*'53 * which matches anything. It must be the rightmost element in the54 * permission name and must follow a '.' or else the Permission name must55 * consist of only a '*'. Any otheroccurrence of a '*' is not valid.56 * <p>57 * This class ignores the action list. Subclasses can choose to implement47 * or it is not. 48 * 49 * 50 * 51 * 52 * 53 * 54 * 55 * occurrence of a '*' is not valid. 56 * 57 * This class ignores the action list. Subclasses can choose to implement 58 58 * actions on top of this class if desired. 59 59 * 60 * @version 0.1 61 * 62 * @author Aaron M. Renn ([email protected]) 60 * @author Aaron M. Renn <[email protected]> 61 * @author Eric Blake <[email protected]> 62 * @see Permission 63 * @see Permissions 64 * @see PermissionCollection 65 * @see RuntimePermission 66 * @see SecurityPermission 67 * @see PropertyPermission 68 * @see AWTPermission 69 * @see NetPermission 70 * @see SecurityManager 71 * @since 1.1 72 * @status updated to 1.4 63 73 */ 64 74 public abstract class BasicPermission extends java.security.Permission 65 75 implements Serializable 66 // FIXME extends with fully qualified classname as workaround for gcj 3.0.476 // FIXME extends with fully qualified classname 67 77 { 68 78 /** 69 * This method initializes a new instance of <code>BasicPermission</code> 70 * with the specified name. If the name contains an illegal wildcard 71 * character, an exception is thrown. 72 * 73 * @param name The name of this permission. 74 * 75 * @exception IllegalArgumentException If the name contains an invalid wildcard character 76 * @exception NullPointerException If the name is null 77 */ 78 public BasicPermission(String name) 79 throws IllegalArgumentException, NullPointerException 79 * Compatible with JDK 1.1+. 80 */ 81 private static final long serialVersionUID = 6279438298436773498L; 82 83 /** 84 * Create a new instance with the specified permission name. If the name 85 * is empty, or contains an illegal wildcard character, an exception is 86 * thrown. 87 * 88 * @param name the name of this permission 89 * @throws NullPointerException if name is null 90 * @throws IllegalArgumentException if name is invalid 91 */ 92 public BasicPermission(String name) 80 93 { 81 94 super(name); 82 83 95 if (name.indexOf("*") != -1) 84 96 { 85 if (!name.endsWith(".*") && !name.equals("*")) 86 throw new IllegalArgumentException("Bad wildcard: " + name); 87 88 if (name.indexOf("*") != name.lastIndexOf("*")) 89 throw new IllegalArgumentException("Bad wildcard: " + name); 97 if ((! name.endsWith(".*") && ! name.equals("*")) 98 || name.indexOf("*") != name.lastIndexOf("*")) 99 throw new IllegalArgumentException("Bad wildcard: " + name); 90 100 } 91 } 92 93 /** 94 * This method initializes a new instance of <code>BasicPermission</code> 95 * with the specified name. If the name contains an illegal wildcard 96 * character, an exception is thrown. The action list passed to this 97 * form of the constructor is ignored. 98 * 99 * @param name The name of this permission. 100 * @param actions The list of actions for this permission - ignored in this class. 101 * 102 * @exception IllegalArgumentException If the name contains an invalid wildcard character 103 * @exception NullPointerException If the name is null 104 */ 105 public BasicPermission(String name, String actions) 106 throws IllegalArgumentException, NullPointerException 107 { 108 // ignore actions 101 if ("".equals(name)) 102 throw new IllegalArgumentException("Empty name"); 103 } 104 105 /** 106 * Create a new instance with the specified permission name. If the name 107 * is empty, or contains an illegal wildcard character, an exception is 108 * thrown. The actions parameter is ignored. 109 * 110 * @param name the name of this permission 111 * @param actions ignored 112 * @throws NullPointerException if name is null 113 * @throws IllegalArgumentException if name is invalid 114 */ 115 public BasicPermission(String name, String actions) 116 { 109 117 this(name); 110 118 } 111 119 112 120 /** 113 * This method tests to see if the specified permission is implied by 114 * this permission. This will be true if the following conditions are met: 115 * <p> 116 * <ul> 117 * <li>The specified object is an instance of <code>BasicPermission</code>, 118 * or a subclass. 119 * <li>The name of the specified permission is identical to this permission's 120 * name or the name of the specified permission satisfies a wildcard match 121 * on this permission. 121 * This method tests to see if the specified permission is implied by this 122 * permission. This will be true if the following conditions are met:<ul> 123 * <li>The specified object is an instance of the same class as this 124 * object.</li> 125 * <li>The name of the specified permission is implied by this permission's 126 * name based on wildcard matching. For example, "a.*" implies "a.b".</li> 122 127 * </ul> 123 128 * 124 * @param perm The <code>Permission</code> object to test against. 125 * 126 * @return <code>true</code> if the specified permission is implied by this one or <code>false</code> otherwise. 129 * @param perm the <code>Permission</code> object to test against 130 * @return true if the specified permission is implied 127 131 */ 128 132 public boolean implies(Permission perm) 129 133 { 130 if (! (perm instanceof BasicPermission))134 if (!)) 131 135 return false; 132 136 … … 138 142 139 143 int last = name.length() - 1; 140 if (name.charAt(last) == '*' 141 && otherName.startsWith(name.substring(0, last))) 142 return true; 143 144 return false; 144 return name.charAt(last) == '*' 145 && otherName.startsWith(name.substring(0, last)); 145 146 } 146 147 … … 148 149 * This method tests to see if this object is equal to the specified 149 150 * <code>Object</code>. This will be true if and only if the specified 150 * object meets the following conditions: 151 * <p> 152 * <ul> 153 * <li>It is an instance of <code>BasicPermission</code>, or a subclass. 154 * <li>It has the same name as this permission. 151 * object meets the following conditions:<ul> 152 * <li>It is an instance of the same class as this.</li> 153 * <li>It has the same name as this permission.</li> 155 154 * </ul> 156 155 * 157 * @param obj The <code>Object</code> to test for equality against this object 158 * 159 * @return <code>true</code> if the specified <code>Object</code> is equal to this object or <code>false</code> otherwise. 156 * @param obj the <code>Object</code> to test for equality 157 * @return true if obj is semantically equal to this 160 158 */ 161 159 public boolean equals(Object obj) 162 160 { 163 if (!(obj instanceof BasicPermission)) 164 return (false); 165 166 if (!getName().equals(((BasicPermission) obj).getName())) 167 return (false); 168 169 return (true); 161 return getClass().isInstance(obj) 162 && getName().equals(((BasicPermission) obj).getName()); 170 163 } 171 164 … … 175 168 * method on the <code>String</code> that is the name of this permission. 176 169 * 177 * @return Ahash value for this object170 * @return hash value for this object 178 171 */ 179 172 public int hashCode() 180 173 { 181 return (getName().hashCode());182 } 183 184 /** 185 * This method returns a list of the actions associated with this 174 return ); 175 } 176 177 /** 178 * This method returns a list of the actions associated with this 186 179 * permission. This method always returns the empty string ("") since 187 180 * this class ignores actions. 188 181 * 189 * @return The action list.182 * @return 190 183 */ 191 184 public String getActions() 192 185 { 193 return ("");186 return ; 194 187 } 195 188 196 189 /** 197 190 * This method returns an instance of <code>PermissionCollection</code> 198 * suitable for storing <code>BasicPermission</code> objects. This returns 199 * be a sub class of <code>PermissionCollection</code> 200 * that allows for an efficient and consistent implementation of 201 * the <code>implies</code> method. The collection doesn't handle subclasses 202 * of BasicPermission correctly; they must override this method. 203 * 204 * @return A new empty <code>PermissionCollection</code> object. 191 * suitable for storing <code>BasicPermission</code> objects. The 192 * collection returned can only store objects of the same type as this. 193 * Subclasses which use actions must override this method; but a class with 194 * no actions will work fine with this. 195 * 196 * @return a new empty <code>PermissionCollection</code> object 205 197 */ 206 198 public PermissionCollection newPermissionCollection() 207 199 { 208 return new PermissionCollection() 209 { 210 Hashtable permissions = new Hashtable(); 211 boolean allAllowed = false; 212 213 public void add(Permission permission) 200 return new BasicPermissionCollection(getClass()); 201 } 202 } // class BasicPermission 203 204 /** 205 * Implements AllPermission.newPermissionCollection, and obeys serialization 206 * of JDK. 207 * 208 * @author Eric Blake <[email protected]> 209 */ 210 final class BasicPermissionCollection extends PermissionCollection 211 { 212 /** 213 * Compatible with JDK 1.1+. 214 */ 215 private static final long serialVersionUID = 739301742472979399L; 216 217 /** 218 * The permissions in the collection. 219 * 220 * @serial a hash mapping name to permissions, all of type permClass 221 */ 222 private final Hashtable permissions = new Hashtable(); 223 224 /** 225 * If "*" is in the collection. 226 * 227 * @serial true if a permission named "*" is in the collection 228 */ 229 private boolean all_allowed; 230 231 /** 232 * The runtime class which all entries in the table must belong to. 233 * 234 * @serial the limiting subclass of this collection 235 */ 236 private final Class permClass; 237 238 /** 239 * Construct a collection over the given runtime class. 240 * 241 * @param c the class 242 */ 243 BasicPermissionCollection(Class c) 244 { 245 permClass = c; 246 } 247 248 /** 249 * Add a Permission. It must be of the same type as the permission which 250 * created this collection. 251 * 252 * @param perm the permission to add 253 * @throws IllegalArgumentException if perm is not the correct type 254 * @throws SecurityException if the collection is read-only 255 */ 256 public void add(Permission perm) 257 { 258 if (isReadOnly()) 259 throw new SecurityException("readonly"); 260 if (! permClass.isInstance(perm)) 261 throw new IllegalArgumentException("Expecting instance of " + permClass); 262 BasicPermission bp = (BasicPermission) perm; 263 String name = bp.getName(); 264 if (name.equals("*")) 265 all_allowed = true; 266 permissions.put(name, bp); 267 } 268 269 /** 270 * Returns true if this collection implies the given permission. 271 * 272 * @param permission the permission to check 273 * @return true if it is implied by this 274 */ 275 public boolean implies(Permission permission) 276 { 277 if (! permClass.isInstance(permission)) 278 return false; 279 if (all_allowed) 280 return true; 281 BasicPermission toImply = (BasicPermission) permission; 282 String name = toImply.getName(); 283 if (name.equals("*")) 284 return false; 285 int prefixLength = name.length(); 286 if (name.endsWith("*")) 287 prefixLength -= 2; 288 289 while (true) 214 290 { 215 if (isReadOnly()) 216 throw new IllegalStateException("readonly"); 217 218 BasicPermission bp = (BasicPermission) permission; 219 String name = bp.getName(); 220 if (name.equals("*")) 221 allAllowed = true; 222 permissions.put(name, bp); 291 if (permissions.get(name) != null) 292 return true; 293 prefixLength = name.lastIndexOf('.', prefixLength); 294 if (prefixLength < 0) 295 return false; 296 name = name.substring(0, prefixLength + 1) + '*'; 223 297 } 224 225 public boolean implies(Permission permission) 226 { 227 if (!(permission instanceof BasicPermission)) 228 return false; 229 230 if (allAllowed) 231 return true; 232 233 BasicPermission toImply = (BasicPermission) permission; 234 String name = toImply.getName(); 235 if (name.equals("*")) 236 return false; 237 238 int prefixLength = name.length(); 239 if (name.endsWith("*")) 240 prefixLength -= 2; 241 242 while (true) 243 { 244 if (permissions.get(name) != null) 245 return true; 246 247 prefixLength = name.lastIndexOf('.', prefixLength); 248 if (prefixLength < 0) 249 return false; 250 name = name.substring(0, prefixLength + 1) + '*'; 251 } 252 } 253 254 public Enumeration elements() 255 { 256 return permissions.elements(); 257 } 258 }; 259 } 260 } 298 } 299 300 /** 301 * Enumerate over the collection. 302 * 303 * @return an enumeration of the collection contents 304 */ 305 public Enumeration elements() 306 { 307 return permissions.elements(); 308 } 309 } // class BasicPermissionCollection -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
