KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > ProsePermission


1 //
2
// This file is part of the prose package.
3
//
4
// The contents of this file are subject to the Mozilla Public License
5
// Version 1.1 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
// http://www.mozilla.org/MPL/
8
//
9
// Software distributed under the License is distributed on an "AS IS" basis,
10
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
// for the specific language governing rights and limitations under the
12
// License.
13
//
14
// The Original Code is prose.
15
//
16
// The Initial Developer of the Original Code is Andrei Popovici. Portions
17
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18
// All Rights Reserved.
19
//
20
// Contributor(s):
21
// $Id: ProsePermission.java,v 1.1.1.1 2003/07/02 15:30:50 apopovic Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.prose;
28
29 // used packages
30
import java.io.Serializable JavaDoc;
31 import java.security.Permission JavaDoc;
32
33 /**
34  * The class ProsePermission is used for access control of critical parts
35  * in the RUNES system. The names recognized and their semantics can be
36  * seen in the following list, to specify all names, one can use the wildcard "*".<p>
37  *
38  * <ul>
39  * <li> registerListener: guards the creation of breakpoints
40  * <li> startupExtensionSystem: if granted, <code>ProseSystem.startup</code>
41  * will be performed privileged under the the restrictions of <code>ProseSystem</code>
42  * only. This permission should simplify the Java security policy definition, as
43  * only <code>ProseSystem</code> needs several fine grained permissions, and all
44  * classes that need to start runes can do with the ProsePermission "startupExtensionSystem"
45  * </ul>
46  * <p>
47  * So an entry in the standard policy file allowing all classes to install
48  * extensions would look like:<p><pre>
49  * grant {
50  * ch.ethz.prose.ProsePermission "registerListener";
51  * }
52  * </pre>
53  *
54  * @version $Revision: 1.1.1.1 $
55  * @author Marcel Muller
56  */

57 public final class ProsePermission extends Permission JavaDoc implements Serializable JavaDoc {
58     private final static String JavaDoc[] NAMES = {"registerListener", "startupExtensionSystem"};
59     private final static String JavaDoc WILDCARD = "*";
60
61     private int nameIndex = -1;
62
63     /**
64      * Constructs a runes permission with the specified name.
65      *
66      * @param name the name of the permission or <code>*</code> for all names.
67      */

68     public ProsePermission(String JavaDoc name) {
69     super(name);
70
71     if (name == null) {
72         throw new NullPointerException JavaDoc("name can't be null");
73     }
74
75     for (int i=0; i<NAMES.length; i++) {
76         if (name.equals(NAMES[i])) {
77         nameIndex = i;
78         break;
79         }
80     }
81
82     if (nameIndex == -1) {
83         String JavaDoc names = NAMES[0];
84         for (int i=1; i<NAMES.length; i++) {
85         names += ", " + NAMES[i];
86         }
87
88         throw new IllegalArgumentException JavaDoc("Invalid name \""+name+"\". Valid choices are: " + names);
89     }
90     }
91
92     /**
93      * Constructs a runes permission with the specified name and action. This constructor
94      * seems to be necessary to the standard policy file implementation though this
95      * class completely ignores the action parameter.
96      *
97      * @param name the name of the permission or <code>*</code> for all names.
98      * @param actions ignored!!!
99      */

100     public ProsePermission(String JavaDoc name, String JavaDoc actions) {
101     this(name);
102     }
103
104     /**
105      * Checks whether this permission implies permission <code>p</code> (if names are
106      * equal or at least this permission was created with the wildcard as parameter) or not.
107      *
108      * @param p the permission to be compared to
109      */

110     public boolean implies(Permission JavaDoc p) {
111     if (p instanceof ProsePermission) {
112         if (getName().equals(WILDCARD)) {
113         return true;
114         }
115
116         return nameIndex == ((ProsePermission) p).nameIndex;
117     }
118
119     return false;
120     }
121
122     /**
123      * Returns an empty string as this class does not use actions.
124      */

125     public String JavaDoc getActions() {
126     return "";
127     }
128
129     public boolean equals(Object JavaDoc obj) {
130     if (obj instanceof ProsePermission) {
131         return nameIndex == ((ProsePermission) obj).nameIndex;
132     } else {
133         return false;
134     }
135     }
136
137     public int hashCode() {
138     return getName().hashCode();
139     }
140 }
141
142
143 //======================================================================
144
//
145
// $Log: ProsePermission.java,v $
146
// Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
147
// Imported from ETH Zurich
148
//
149
// Revision 1.1 2003/05/05 13:58:29 popovici
150
// renaming from runes to prose
151
//
152
// Revision 1.4 2003/03/04 18:36:37 popovici
153
// Organization of imprts
154
//
155
// Revision 1.3 2003/03/04 11:27:16 popovici
156
// Important refactorization step (march):
157
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
158
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
159
// structures
160
//
161
// Revision 1.2 2002/03/28 13:48:37 popovici
162
// Mozilla-ified
163
//
164
// Revision 1.1.1.1 2001/11/29 18:13:16 popovici
165
// Sources from runes
166
//
167
// Revision 1.1.2.3 2001/04/04 13:08:52 mrmuller
168
// JavaDoc improved
169
//
170
// Revision 1.1.2.2 2001/03/16 17:29:15 mrmuller
171
// cosmetics, javadoc and exception handling changes
172
//
173
// Revision 1.1.2.1 2001/03/16 13:12:29 mrmuller
174
// initial release of new (really) secure extension insertion mechanism
175
//
176
//
177
Popular Tags