001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developer of the Original Code is Andrei Popovici. Portions
017: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id: ProsePermission.java,v 1.1.1.1 2003/07/02 15:30:50 apopovic Exp $
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.prose;
028:
029: // used packages
030: import java.io.Serializable;
031: import java.security.Permission;
032:
033: /**
034: * The class ProsePermission is used for access control of critical parts
035: * in the RUNES system. The names recognized and their semantics can be
036: * seen in the following list, to specify all names, one can use the wildcard "*".<p>
037: *
038: * <ul>
039: * <li> registerListener: guards the creation of breakpoints
040: * <li> startupExtensionSystem: if granted, <code>ProseSystem.startup</code>
041: * will be performed privileged under the the restrictions of <code>ProseSystem</code>
042: * only. This permission should simplify the Java security policy definition, as
043: * only <code>ProseSystem</code> needs several fine grained permissions, and all
044: * classes that need to start runes can do with the ProsePermission "startupExtensionSystem"
045: * </ul>
046: * <p>
047: * So an entry in the standard policy file allowing all classes to install
048: * extensions would look like:<p><pre>
049: * grant {
050: * ch.ethz.prose.ProsePermission "registerListener";
051: * }
052: * </pre>
053: *
054: * @version $Revision: 1.1.1.1 $
055: * @author Marcel Muller
056: */
057: public final class ProsePermission extends Permission implements
058: Serializable {
059:
060: private static final long serialVersionUID = 3258134652291133489L;
061: private final static String[] NAMES = { "registerListener",
062: "startupExtensionSystem" };
063: private final static String WILDCARD = "*";
064:
065: private int nameIndex = -1;
066:
067: /**
068: * Constructs a runes permission with the specified name.
069: *
070: * @param name the name of the permission or <code>*</code> for all names.
071: */
072: public ProsePermission(String name) {
073: super (name);
074:
075: if (name == null) {
076: throw new NullPointerException("name can't be null");
077: }
078:
079: for (int i = 0; i < NAMES.length; i++) {
080: if (name.equals(NAMES[i])) {
081: nameIndex = i;
082: break;
083: }
084: }
085:
086: if (nameIndex == -1) {
087: String names = NAMES[0];
088: for (int i = 1; i < NAMES.length; i++) {
089: names += ", " + NAMES[i];
090: }
091:
092: throw new IllegalArgumentException("Invalid name \"" + name
093: + "\". Valid choices are: " + names);
094: }
095: }
096:
097: /**
098: * Constructs a runes permission with the specified name and action. This constructor
099: * seems to be necessary to the standard policy file implementation though this
100: * class completely ignores the action parameter.
101: *
102: * @param name the name of the permission or <code>*</code> for all names.
103: * @param actions ignored!!!
104: */
105: public ProsePermission(String name, String actions) {
106: this (name);
107: }
108:
109: /**
110: * Checks whether this permission implies permission <code>p</code> (if names are
111: * equal or at least this permission was created with the wildcard as parameter) or not.
112: *
113: * @param p the permission to be compared to
114: */
115: public boolean implies(Permission p) {
116: if (p instanceof ProsePermission) {
117: if (getName().equals(WILDCARD)) {
118: return true;
119: }
120:
121: return nameIndex == ((ProsePermission) p).nameIndex;
122: }
123:
124: return false;
125: }
126:
127: /**
128: * Returns an empty string as this class does not use actions.
129: */
130: public String getActions() {
131: return "";
132: }
133:
134: public boolean equals(Object obj) {
135: if (obj instanceof ProsePermission) {
136: return nameIndex == ((ProsePermission) obj).nameIndex;
137: } else {
138: return false;
139: }
140: }
141:
142: public int hashCode() {
143: return getName().hashCode();
144: }
145: }
146:
147: //======================================================================
148: //
149: // $Log: ProsePermission.java,v $
150: // Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
151: // Imported from ETH Zurich
152: //
153: // Revision 1.1 2003/05/05 13:58:29 popovici
154: // renaming from runes to prose
155: //
156: // Revision 1.4 2003/03/04 18:36:37 popovici
157: // Organization of imprts
158: //
159: // Revision 1.3 2003/03/04 11:27:16 popovici
160: // Important refactorization step (march):
161: // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
162: // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
163: // structures
164: //
165: // Revision 1.2 2002/03/28 13:48:37 popovici
166: // Mozilla-ified
167: //
168: // Revision 1.1.1.1 2001/11/29 18:13:16 popovici
169: // Sources from runes
170: //
171: // Revision 1.1.2.3 2001/04/04 13:08:52 mrmuller
172: // JavaDoc improved
173: //
174: // Revision 1.1.2.2 2001/03/16 17:29:15 mrmuller
175: // cosmetics, javadoc and exception handling changes
176: //
177: // Revision 1.1.2.1 2001/03/16 13:12:29 mrmuller
178: // initial release of new (really) secure extension insertion mechanism
179: //
180: //
|