Merge from the pain train
[official-gcc.git] / libjava / java / security / AllPermission.java
blobe7f316917c2c8e91f5a94de171fc7bc6f472f610
1 /* AllPermission.java -- Permission to do anything
2 Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
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.
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. */
39 package java.security;
41 import gnu.java.util.EmptyEnumeration;
43 import java.util.Collections;
44 import java.util.Enumeration;
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.
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
59 public final class AllPermission extends Permission
61 /**
62 * Compatible with JDK 1.1+.
64 private static final long serialVersionUID = -2916474571451318075L;
66 /**
67 * Create a new AllPermission object.
69 public AllPermission()
71 super("*");
74 /**
75 * Create a new AllPermission object. The parameters are ignored, as all
76 * permission implies ALL PERMISSION.
78 * @param name ignored
79 * @param actions ignored
81 public AllPermission(String name, String actions)
83 super("*");
86 /**
87 * This method always returns <code>true</code> to indicate that this
88 * permission always implies that any other permission is also granted.
90 * @param perm ignored
91 * @return true, the permission is implied
93 public boolean implies(Permission perm)
95 return true;
98 /**
99 * Checks an object for equality. All AllPermissions are equal.
101 * @param obj the <code>Object</code> to test for equality
103 public boolean equals(Object obj)
105 return obj instanceof AllPermission;
109 * This method returns a hash code for this object. This returns 1.
111 * @return a hash value for this object
113 public int hashCode()
115 return 1;
119 * This method returns the list of actions associated with this object.
120 * This will always be the empty string ("") for this class.
122 * @return the action list
124 public String getActions()
126 return "";
130 * Returns a PermissionCollection which can hold AllPermission.
132 * @return a permission collection
134 public PermissionCollection newPermissionCollection()
136 return new AllPermissionCollection();
140 * Implements AllPermission.newPermissionCollection, and obeys serialization
141 * of JDK.
143 * @author Eric Blake (ebb9@email.byu.edu)
145 private static final class AllPermissionCollection extends PermissionCollection
148 * Compatible with JDK 1.1+.
150 private static final long serialVersionUID = -4023755556366636806L;
153 * Whether an AllPermission has been added to the collection.
155 * @serial if all permission is in the collection yet
157 private boolean all_allowed;
160 * Add an AllPermission.
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
166 public void add(Permission perm)
168 if (isReadOnly())
169 throw new SecurityException();
170 if (! (perm instanceof AllPermission))
171 throw new IllegalArgumentException();
172 all_allowed = true;
176 * Returns true if this collection implies a permission.
178 * @param perm the permission to check
179 * @return true if this collection contains an AllPermission
181 public boolean implies(Permission perm)
183 return all_allowed;
187 * Returns an enumeration of the elements in the collection.
189 * @return the elements in the collection
191 public Enumeration elements()
193 return all_allowed
194 ? Collections.enumeration(Collections.singleton(new AllPermission()))
195 : EmptyEnumeration.getInstance();
197 } // class AllPermissionCollection
198 } // class AllPermission