GNU Classpath (0.95) | |
Frames | No Frames |
1: /* AllPermission.java -- Permission to do anything 2: Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package java.security; 40: 41: import gnu.java.util.EmptyEnumeration; 42: 43: import java.util.Collections; 44: import java.util.Enumeration; 45: 46: /** 47: * This class is a permission that implies all other permissions. Granting 48: * this permission effectively grants all others. Extreme caution should 49: * be exercised in granting this permission. 50: * 51: * @author Aaron M. Renn (arenn@urbanophile.com) 52: * @author Eric Blake (ebb9@email.byu.edu) 53: * @see AccessController 54: * @see Permissions 55: * @see SecurityManager 56: * @since 1.1 57: * @status updated to 1.4 58: */ 59: public final class AllPermission extends Permission 60: { 61: /** 62: * Compatible with JDK 1.1+. 63: */ 64: private static final long serialVersionUID = -2916474571451318075L; 65: 66: /** 67: * Create a new AllPermission object. 68: */ 69: public AllPermission() 70: { 71: super("*"); 72: } 73: 74: /** 75: * Create a new AllPermission object. The parameters are ignored, as all 76: * permission implies ALL PERMISSION. 77: * 78: * @param name ignored 79: * @param actions ignored 80: */ 81: public AllPermission(String name, String actions) 82: { 83: super("*"); 84: } 85: 86: /** 87: * This method always returns <code>true</code> to indicate that this 88: * permission always implies that any other permission is also granted. 89: * 90: * @param perm ignored 91: * @return true, the permission is implied 92: */ 93: public boolean implies(Permission perm) 94: { 95: return true; 96: } 97: 98: /** 99: * Checks an object for equality. All AllPermissions are equal. 100: * 101: * @param obj the <code>Object</code> to test for equality 102: */ 103: public boolean equals(Object obj) 104: { 105: return obj instanceof AllPermission; 106: } 107: 108: /** 109: * This method returns a hash code for this object. This returns 1. 110: * 111: * @return a hash value for this object 112: */ 113: public int hashCode() 114: { 115: return 1; 116: } 117: 118: /** 119: * This method returns the list of actions associated with this object. 120: * This will always be the empty string ("") for this class. 121: * 122: * @return the action list 123: */ 124: public String getActions() 125: { 126: return ""; 127: } 128: 129: /** 130: * Returns a PermissionCollection which can hold AllPermission. 131: * 132: * @return a permission collection 133: */ 134: public PermissionCollection newPermissionCollection() 135: { 136: return new AllPermissionCollection(); 137: } 138: 139: /** 140: * Implements AllPermission.newPermissionCollection, and obeys serialization 141: * of JDK. 142: * 143: * @author Eric Blake (ebb9@email.byu.edu) 144: */ 145: private static final class AllPermissionCollection extends PermissionCollection 146: { 147: /** 148: * Compatible with JDK 1.1+. 149: */ 150: private static final long serialVersionUID = -4023755556366636806L; 151: 152: /** 153: * Whether an AllPermission has been added to the collection. 154: * 155: * @serial if all permission is in the collection yet 156: */ 157: private boolean all_allowed; 158: 159: /** 160: * Add an AllPermission. 161: * 162: * @param perm the permission to add 163: * @throws IllegalArgumentException if perm is not an AllPermission 164: * @throws SecurityException if the collection is read-only 165: */ 166: public void add(Permission perm) 167: { 168: if (isReadOnly()) 169: throw new SecurityException(); 170: if (! (perm instanceof AllPermission)) 171: throw new IllegalArgumentException(); 172: all_allowed = true; 173: } 174: 175: /** 176: * Returns true if this collection implies a permission. 177: * 178: * @param perm the permission to check 179: * @return true if this collection contains an AllPermission 180: */ 181: public boolean implies(Permission perm) 182: { 183: return all_allowed; 184: } 185: 186: /** 187: * Returns an enumeration of the elements in the collection. 188: * 189: * @return the elements in the collection 190: */ 191: public Enumeration elements() 192: { 193: return all_allowed 194: ? Collections.enumeration(Collections.singleton(new AllPermission())) 195: : EmptyEnumeration.getInstance(); 196: } 197: } // class AllPermissionCollection 198: } // class AllPermission
GNU Classpath (0.95) |