//
// This file is part of the prose package.
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// The Original Code is prose.
//
// The Initial Developer of the Original Code is Andrei Popovici. Portions
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
// All Rights Reserved.
//
// Contributor(s):
// $Id: ProsePermission.java,v 1.1.1.1 2003/07/02 15:30:50 apopovic Exp $
// =====================================================================
//
// (history at end)
//
package ch.ethz.prose;
// used packages
import java.io.Serializable;
import java.security.Permission;
/**
* The class ProsePermission is used for access control of critical parts
* in the RUNES system. The names recognized and their semantics can be
* seen in the following list, to specify all names, one can use the wildcard "*".<p>
*
* <ul>
* <li> registerListener: guards the creation of breakpoints
* <li> startupExtensionSystem: if granted, <code>ProseSystem.startup</code>
* will be performed privileged under the the restrictions of <code>ProseSystem</code>
* only. This permission should simplify the Java security policy definition, as
* only <code>ProseSystem</code> needs several fine grained permissions, and all
* classes that need to start runes can do with the ProsePermission "startupExtensionSystem"
* </ul>
* <p>
* So an entry in the standard policy file allowing all classes to install
* extensions would look like:<p><pre>
* grant {
* ch.ethz.prose.ProsePermission "registerListener";
* }
* </pre>
*
* @version $Revision: 1.1.1.1 $
* @author Marcel Muller
*/
public final class ProsePermission extends Permission implements Serializable {
private static final long serialVersionUID = 3258134652291133489L;
private final static String[] NAMES = {"registerListener", "startupExtensionSystem"};
private final static String WILDCARD = "*";
private int nameIndex = -1;
/**
* Constructs a runes permission with the specified name.
*
* @param name the name of the permission or <code>*</code> for all names.
*/
public ProsePermission(String name) {
super(name);
if (name == null) {
throw new NullPointerException("name can't be null");
}
for (int i=0; i<NAMES.length; i++) {
if (name.equals(NAMES[i])) {
nameIndex = i;
break;
}
}
if (nameIndex == -1) {
String names = NAMES[0];
for (int i=1; i<NAMES.length; i++) {
names += ", " + NAMES[i];
}
throw new IllegalArgumentException("Invalid name \""+name+"\". Valid choices are: " + names);
}
}
/**
* Constructs a runes permission with the specified name and action. This constructor
* seems to be necessary to the standard policy file implementation though this
* class completely ignores the action parameter.
*
* @param name the name of the permission or <code>*</code> for all names.
* @param actions ignored!!!
*/
public ProsePermission(String name, String actions) {
this(name);
}
/**
* Checks whether this permission implies permission <code>p</code> (if names are
* equal or at least this permission was created with the wildcard as parameter) or not.
*
* @param p the permission to be compared to
*/
public boolean implies(Permission p) {
if (p instanceof ProsePermission) {
if (getName().equals(WILDCARD)) {
return true;
}
return nameIndex == ((ProsePermission) p).nameIndex;
}
return false;
}
/**
* Returns an empty string as this class does not use actions.
*/
public String getActions() {
return "";
}
public boolean equals(Object obj) {
if (obj instanceof ProsePermission) {
return nameIndex == ((ProsePermission) obj).nameIndex;
} else {
return false;
}
}
public int hashCode() {
return getName().hashCode();
}
}
//======================================================================
//
// $Log: ProsePermission.java,v $
// Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
// Imported from ETH Zurich
//
// Revision 1.1 2003/05/05 13:58:29 popovici
// renaming from runes to prose
//
// Revision 1.4 2003/03/04 18:36:37 popovici
// Organization of imprts
//
// Revision 1.3 2003/03/04 11:27:16 popovici
// Important refactorization step (march):
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
// structures
//
// Revision 1.2 2002/03/28 13:48:37 popovici
// Mozilla-ified
//
// Revision 1.1.1.1 2001/11/29 18:13:16 popovici
// Sources from runes
//
// Revision 1.1.2.3 2001/04/04 13:08:52 mrmuller
// JavaDoc improved
//
// Revision 1.1.2.2 2001/03/16 17:29:15 mrmuller
// cosmetics, javadoc and exception handling changes
//
// Revision 1.1.2.1 2001/03/16 13:12:29 mrmuller
// initial release of new (really) secure extension insertion mechanism
//
//
|