| 1 | /* AllPermission.java -- Permission to do anything
|
|---|
| 2 | Copyright (C) 1998, 2001, 2002 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., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 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 | package java.security;
|
|---|
| 39 |
|
|---|
| 40 | import java.util.Enumeration;
|
|---|
| 41 | import java.util.Collections;
|
|---|
| 42 | import gnu.java.util.EmptyEnumeration;
|
|---|
| 43 |
|
|---|
| 44 | /**
|
|---|
| 45 | * This class is a permission that implies all other permissions. Granting
|
|---|
| 46 | * this permission effectively grants all others. Extreme caution should
|
|---|
| 47 | * be exercised in granting this permission.
|
|---|
| 48 | *
|
|---|
| 49 | * @author Aaron M. Renn <[email protected]>
|
|---|
| 50 | * @author Eric Blake <[email protected]>
|
|---|
| 51 | * @see AccessController
|
|---|
| 52 | * @see Permissions
|
|---|
| 53 | * @see SecurityManager
|
|---|
| 54 | * @since 1.1
|
|---|
| 55 | * @status updated to 1.4
|
|---|
| 56 | */
|
|---|
| 57 | public final class AllPermission extends Permission
|
|---|
| 58 | {
|
|---|
| 59 | /**
|
|---|
| 60 | * Compatible with JDK 1.1+.
|
|---|
| 61 | */
|
|---|
| 62 | private static final long serialVersionUID = -2916474571451318075L;
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * Create a new AllPermission object.
|
|---|
| 66 | */
|
|---|
| 67 | public AllPermission()
|
|---|
| 68 | {
|
|---|
| 69 | super("*");
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | /**
|
|---|
| 73 | * Create a new AllPermission object. The parameters are ignored, as all
|
|---|
| 74 | * permission implies ALL PERMISSION.
|
|---|
| 75 | *
|
|---|
| 76 | * @param name ignored
|
|---|
| 77 | * @param actions ignored
|
|---|
| 78 | */
|
|---|
| 79 | public AllPermission(String name, String actions)
|
|---|
| 80 | {
|
|---|
| 81 | super("*");
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /**
|
|---|
| 85 | * This method always returns <code>true</code> to indicate that this
|
|---|
| 86 | * permission always implies that any other permission is also granted.
|
|---|
| 87 | *
|
|---|
| 88 | * @param perm ignored
|
|---|
| 89 | * @return true, the permission is implied
|
|---|
| 90 | */
|
|---|
| 91 | public boolean implies(Permission perm)
|
|---|
| 92 | {
|
|---|
| 93 | return true;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /**
|
|---|
| 97 | * Checks an object for equality. All AllPermissions are equal.
|
|---|
| 98 | *
|
|---|
| 99 | * @param obj the <code>Object</code> to test for equality
|
|---|
| 100 | */
|
|---|
| 101 | public boolean equals(Object obj)
|
|---|
| 102 | {
|
|---|
| 103 | return obj instanceof AllPermission;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | /**
|
|---|
| 107 | * This method returns a hash code for this object. This returns 1.
|
|---|
| 108 | *
|
|---|
| 109 | * @return a hash value for this object
|
|---|
| 110 | */
|
|---|
| 111 | public int hashCode()
|
|---|
| 112 | {
|
|---|
| 113 | return 1;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /**
|
|---|
| 117 | * This method returns the list of actions associated with this object.
|
|---|
| 118 | * This will always be the empty string ("") for this class.
|
|---|
| 119 | *
|
|---|
| 120 | * @return the action list
|
|---|
| 121 | */
|
|---|
| 122 | public String getActions()
|
|---|
| 123 | {
|
|---|
| 124 | return "";
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | * Returns a PermissionCollection which can hold AllPermission.
|
|---|
| 129 | *
|
|---|
| 130 | * @return a permission collection
|
|---|
| 131 | */
|
|---|
| 132 | public PermissionCollection newPermissionCollection()
|
|---|
| 133 | {
|
|---|
| 134 | return new AllPermissionCollection();
|
|---|
| 135 | }
|
|---|
| 136 | } // class AllPermission
|
|---|
| 137 |
|
|---|
| 138 | /**
|
|---|
| 139 | * Implements AllPermission.newPermissionCollection, and obeys serialization
|
|---|
| 140 | * of JDK.
|
|---|
| 141 | *
|
|---|
| 142 | * @author Eric Blake <[email protected]>
|
|---|
| 143 | */
|
|---|
| 144 | final class AllPermissionCollection extends PermissionCollection
|
|---|
| 145 | {
|
|---|
| 146 | /**
|
|---|
| 147 | * Compatible with JDK 1.1+.
|
|---|
| 148 | */
|
|---|
| 149 | private static final long serialVersionUID = -4023755556366636806L;
|
|---|
| 150 |
|
|---|
| 151 | /**
|
|---|
| 152 | * Whether an AllPermission has been added to the collection.
|
|---|
| 153 | *
|
|---|
| 154 | * @serial if all permission is in the collection yet
|
|---|
| 155 | */
|
|---|
| 156 | private boolean all_allowed;
|
|---|
| 157 |
|
|---|
| 158 | /**
|
|---|
| 159 | * Add an AllPermission.
|
|---|
| 160 | *
|
|---|
| 161 | * @param perm the permission to add
|
|---|
| 162 | * @throws IllegalArgumentException if perm is not an AllPermission
|
|---|
| 163 | * @throws SecurityException if the collection is read-only
|
|---|
| 164 | */
|
|---|
| 165 | public void add(Permission perm)
|
|---|
| 166 | {
|
|---|
| 167 | if (isReadOnly())
|
|---|
| 168 | throw new SecurityException();
|
|---|
| 169 | if (! (perm instanceof AllPermission))
|
|---|
| 170 | throw new IllegalArgumentException();
|
|---|
| 171 | all_allowed = true;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | /**
|
|---|
| 175 | * Returns true if this collection implies a permission.
|
|---|
| 176 | *
|
|---|
| 177 | * @param perm the permission to check
|
|---|
| 178 | * @return true if this collection contains an AllPermission
|
|---|
| 179 | */
|
|---|
| 180 | public boolean implies(Permission perm)
|
|---|
| 181 | {
|
|---|
| 182 | return all_allowed;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | /**
|
|---|
| 186 | * Returns an enumeration of the elements in the collection.
|
|---|
| 187 | *
|
|---|
| 188 | * @return the elements in the collection
|
|---|
| 189 | */
|
|---|
| 190 | public Enumeration elements()
|
|---|
| 191 | {
|
|---|
| 192 | return all_allowed
|
|---|
| 193 | ? Collections.enumeration(Collections.singleton(new AllPermission()))
|
|---|
| 194 | : EmptyEnumeration.getInstance();
|
|---|
| 195 | }
|
|---|
| 196 | } // class AllPermissionCollection
|
|---|