Jumbo patch:
* Imported beans and serialization * Updated IA-64 port * Miscellaneous bug fixes From-SVN: r34028
This commit is contained in:
parent
021c89ed68
commit
6c80c45e30
125 changed files with 18458 additions and 560 deletions
271
libjava/java/security/BasicPermission.java
Normal file
271
libjava/java/security/BasicPermission.java
Normal file
|
@ -0,0 +1,271 @@
|
|||
/* BasicPermission.java -- Implements a simple named permission.
|
||||
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
As a special exception, if you link this library with other files to
|
||||
produce an executable, this library does not by itself cause the
|
||||
resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why the
|
||||
executable file might be covered by the GNU General Public License. */
|
||||
|
||||
|
||||
package java.security;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* This class implements a simple model for named permissions without an
|
||||
* associated action list. That is, either the named permission is granted
|
||||
* or it is not.
|
||||
* <p>
|
||||
* It also supports trailing wildcards to allow the
|
||||
* easy granting of permissions in a hierarchical fashion. (For example,
|
||||
* the name "org.gnu.*" might grant all permissions under the "org.gnu"
|
||||
* permissions hierarchy). The only valid wildcard character is a '*'
|
||||
* which matches anything. It must be the rightmost element in the
|
||||
* permission name and must follow a '.' or else the Permission name must
|
||||
* consist of only a '*'. Any other occurrence of a '*' is not valid.
|
||||
* <p>
|
||||
* This class ignores the action list. Subclasses can choose to implement
|
||||
* actions on top of this class if desired.
|
||||
*
|
||||
* @version 0.1
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public abstract class BasicPermission extends Permission implements Serializable
|
||||
{
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method initializes a new instance of <code>BasicPermission</code>
|
||||
* with the specified name. If the name contains an illegal wildcard
|
||||
* character, an exception is thrown.
|
||||
*
|
||||
* @param name The name of this permission.
|
||||
*
|
||||
* @exception IllegalArgumentException If the name contains an invalid wildcard character
|
||||
* @exception NullPointerException If the name is null
|
||||
*/
|
||||
public
|
||||
BasicPermission(String name) throws IllegalArgumentException, NullPointerException
|
||||
{
|
||||
super(name);
|
||||
|
||||
if (name.indexOf("*") != -1)
|
||||
{
|
||||
if (!name.endsWith(".*") && !name.equals("*"))
|
||||
throw new IllegalArgumentException("Bad wildcard: " + name);
|
||||
|
||||
if (name.indexOf("*") != name.lastIndexOf("*"))
|
||||
throw new IllegalArgumentException("Bad wildcard: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method initializes a new instance of <code>BasicPermission</code>
|
||||
* with the specified name. If the name contains an illegal wildcard
|
||||
* character, an exception is thrown. The action list passed to this
|
||||
* form of the constructor is ignored.
|
||||
*
|
||||
* @param name The name of this permission.
|
||||
* @param actions The list of actions for this permission - ignored in this class.
|
||||
*
|
||||
* @exception IllegalArgumentException If the name contains an invalid wildcard character
|
||||
* @exception NullPointerException If the name is null
|
||||
*/
|
||||
public
|
||||
BasicPermission(String name, String actions) throws IllegalArgumentException, NullPointerException
|
||||
{
|
||||
// ignore actions
|
||||
this(name);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method tests to see if the specified permission is implied by
|
||||
* this permission. This will be true if the following conditions are met:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>The specified object is an instance of <code>BasicPermission</code>,
|
||||
* or a subclass.
|
||||
* <li>The name of the specified permission is identical to this permission's
|
||||
* name or the name of the specified permission satisfies a wildcard match
|
||||
* on this permission.
|
||||
* </ul>
|
||||
*
|
||||
* @param perm The <code>Permission</code> object to test against.
|
||||
*
|
||||
* @return <code>true</code> if the specified permission is implied by this one or <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean
|
||||
implies(Permission perm)
|
||||
{
|
||||
if (!(perm instanceof BasicPermission))
|
||||
return false;
|
||||
|
||||
String otherName = perm.getName();
|
||||
String name = getName();
|
||||
|
||||
if (name.equals(otherName))
|
||||
return true;
|
||||
|
||||
int last = name.length() - 1;
|
||||
if (name.charAt(last) == '*'
|
||||
&& otherName.startsWith(name.substring(0, last)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method tests to see if this object is equal to the specified
|
||||
* <code>Object</code>. This will be true if and only if the specified
|
||||
* object meets the following conditions:
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>It is an instance of <code>BasicPermission</code>, or a subclass.
|
||||
* <li>It has the same name as this permission.
|
||||
* </ul>
|
||||
*
|
||||
* @param obj The <code>Object</code> to test for equality against this object
|
||||
*
|
||||
* @return <code>true</code> if the specified <code>Object</code> is equal to this object or <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean
|
||||
equals(Object obj)
|
||||
{
|
||||
if (!(obj instanceof BasicPermission))
|
||||
return(false);
|
||||
|
||||
if (!getName().equals(((BasicPermission)obj).getName()))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns a hash code for this permission object. The hash
|
||||
* code returned is the value returned by calling the <code>hashCode</code>
|
||||
* method on the <code>String</code> that is the name of this permission.
|
||||
*
|
||||
* @return A hash value for this object
|
||||
*/
|
||||
public int
|
||||
hashCode()
|
||||
{
|
||||
return(getName().hashCode());
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns a list of the actions associated with this
|
||||
* permission. This method always returns the empty string ("") since
|
||||
* this class ignores actions.
|
||||
*
|
||||
* @return The action list.
|
||||
*/
|
||||
public String
|
||||
getActions()
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns an instance of <code>PermissionCollection</code>
|
||||
* suitable for storing <code>BasicPermission</code> objects. This returns
|
||||
* be a sub class of <code>PermissionCollection</code>
|
||||
* that allows for an efficient and consistent implementation of
|
||||
* the <code>implies</code> method. The collection doesn't handle subclasses
|
||||
* of BasicPermission correctly; they must override this method.
|
||||
*
|
||||
* @return A new empty <code>PermissionCollection</code> object.
|
||||
*/
|
||||
public PermissionCollection
|
||||
newPermissionCollection()
|
||||
{
|
||||
return new PermissionCollection()
|
||||
{
|
||||
Hashtable permissions = new Hashtable();
|
||||
boolean allAllowed = false;
|
||||
|
||||
public void add(Permission permission)
|
||||
{
|
||||
if (isReadOnly())
|
||||
throw new IllegalStateException("readonly");
|
||||
|
||||
BasicPermission bp = (BasicPermission) permission;
|
||||
String name = bp.getName();
|
||||
if (name.equals("*"))
|
||||
allAllowed = true;
|
||||
permissions.put(name, bp);
|
||||
}
|
||||
|
||||
public boolean implies(Permission permission)
|
||||
{
|
||||
if (!(permission instanceof BasicPermission))
|
||||
return false;
|
||||
|
||||
if (allAllowed)
|
||||
return true;
|
||||
|
||||
BasicPermission toImply = (BasicPermission) permission;
|
||||
String name = toImply.getName();
|
||||
if (name.equals("*"))
|
||||
return false;
|
||||
|
||||
int prefixLength = name.length();
|
||||
if (name.endsWith("*"))
|
||||
prefixLength -= 2;
|
||||
|
||||
while (true) {
|
||||
if (permissions.get(name) != null)
|
||||
return true;
|
||||
|
||||
prefixLength = name.lastIndexOf('.', prefixLength);
|
||||
if (prefixLength < 0)
|
||||
return false;
|
||||
name = name.substring(0, prefixLength + 1) + '*';
|
||||
}
|
||||
}
|
||||
|
||||
public Enumeration elements()
|
||||
{
|
||||
return permissions.elements();
|
||||
}
|
||||
};
|
||||
}
|
||||
} // class BasicPermission
|
147
libjava/java/security/DigestOutputStream.java
Normal file
147
libjava/java/security/DigestOutputStream.java
Normal file
|
@ -0,0 +1,147 @@
|
|||
/* DigestOutputStream.java --- An output stream tied to a message digest
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
As a special exception, if you link this library with other files to
|
||||
produce an executable, this library does not by itself cause the
|
||||
resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why the
|
||||
executable file might be covered by the GNU General Public License. */
|
||||
|
||||
|
||||
package java.security;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
DigestOutputStream is a class that ties an OutputStream with a
|
||||
MessageDigest. The Message Digest is used by the class to update it
|
||||
self as bytes are written to the OutputStream.
|
||||
|
||||
The updating to the digest depends on the on flag which is set to
|
||||
true by default that tells the class to update the data in the
|
||||
message digest.
|
||||
|
||||
@version 0.0
|
||||
@author Mark Benvenuto <ivymccough@worldnet.att.net>
|
||||
*/
|
||||
public class DigestOutputStream extends FilterOutputStream
|
||||
{
|
||||
/**
|
||||
The message digest for the DigestOutputStream
|
||||
*/
|
||||
protected MessageDigest digest;
|
||||
|
||||
//Manages the on flag
|
||||
private boolean state = true;
|
||||
|
||||
/**
|
||||
Constructs a new DigestOutputStream. It associates a
|
||||
MessageDigest with the stream to compute the stream as data is
|
||||
written.
|
||||
|
||||
@param stream An OutputStream to associate this stream with
|
||||
@param digest A MessageDigest to hash the stream with
|
||||
*/
|
||||
public DigestOutputStream (OutputStream stream, MessageDigest digest)
|
||||
{
|
||||
super (stream);
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the MessageDigest associated with this DigestOutputStream
|
||||
|
||||
@return The MessageDigest used to hash this stream
|
||||
*/
|
||||
public MessageDigest getMessageDigest ()
|
||||
{
|
||||
return digest;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the current MessageDigest to current parameter
|
||||
|
||||
@param digest A MessageDigest to associate with this stream
|
||||
*/
|
||||
public void setMessageDigest (MessageDigest digest)
|
||||
{
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Updates the hash if the on flag is true and then writes a byte to
|
||||
the underlying output stream.
|
||||
|
||||
@param b A byte to write to the output stream
|
||||
|
||||
@exception IOException if the underlying output stream
|
||||
cannot write the byte, this is thrown.
|
||||
*/
|
||||
public void write (int b) throws IOException
|
||||
{
|
||||
if (state)
|
||||
digest.update ((byte)b);
|
||||
|
||||
super.write (b);
|
||||
}
|
||||
|
||||
/**
|
||||
Updates the hash if the on flag is true and then writes the bytes
|
||||
to the underlying output stream.
|
||||
|
||||
@param b Bytes to write to the output stream
|
||||
@param off Offset to start to start at in array
|
||||
@param len Length of data to write
|
||||
|
||||
@exception IOException if the underlying output stream
|
||||
cannot write the bytes, this is thrown.
|
||||
*/
|
||||
public void write (byte[] b, int off, int len) throws IOException
|
||||
{
|
||||
if (state)
|
||||
digest.update (b, off, len);
|
||||
|
||||
super.write (b, off, len);
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the flag specifying if this DigestOutputStream updates the
|
||||
digest in the write() methods. The default is on;
|
||||
|
||||
@param on True means it digests stream, false means it does not
|
||||
*/
|
||||
public void on (boolean on)
|
||||
{
|
||||
state = on;
|
||||
}
|
||||
|
||||
/**
|
||||
Converts the output stream and underlying message digest to a string.
|
||||
|
||||
@return A string representing the output stream and message digest.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "[Digest Output Stream] " + digest.toString();
|
||||
}
|
||||
}
|
54
libjava/java/security/Guard.java
Normal file
54
libjava/java/security/Guard.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* Guard.java -- Check access to a guarded object
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
As a special exception, if you link this library with other files to
|
||||
produce an executable, this library does not by itself cause the
|
||||
resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why the
|
||||
executable file might be covered by the GNU General Public License. */
|
||||
|
||||
|
||||
package java.security;
|
||||
|
||||
/**
|
||||
* This interface specifies a mechanism for querying whether or not
|
||||
* access is allowed to a guarded object.
|
||||
*
|
||||
* @version 0.0
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public interface Guard
|
||||
{
|
||||
|
||||
/**
|
||||
* This method tests whether or not access is allowed to the specified
|
||||
* guarded object. Access is allowed if this method returns silently. If
|
||||
* access is denied, an exception is generated.
|
||||
*
|
||||
* @param obj The <code>Object</code> to test
|
||||
*
|
||||
* @exception SecurityException If access to the object is denied.
|
||||
*/
|
||||
public abstract void
|
||||
checkGuard(Object obj) throws SecurityException;
|
||||
|
||||
} // interface Guard
|
||||
|
191
libjava/java/security/Permission.java
Normal file
191
libjava/java/security/Permission.java
Normal file
|
@ -0,0 +1,191 @@
|
|||
/* Permission.java -- The superclass for all permission objects
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
As a special exception, if you link this library with other files to
|
||||
produce an executable, this library does not by itself cause the
|
||||
resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why the
|
||||
executable file might be covered by the GNU General Public License. */
|
||||
|
||||
|
||||
package java.security;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class is the abstract superclass of all classes that implement
|
||||
* the concept of a permission. A permission consists of a permission name
|
||||
* and optionally a list of actions that relate to the permission. The
|
||||
* actual meaning of the name of the permission is defined only in the
|
||||
* context of a subclass. It may name a resource to which access permissions
|
||||
* are granted (for example, the name of a file) or it might represent
|
||||
* something else entirely. Similarly, the action list only has meaning
|
||||
* within the context of a subclass. Some permission names may have no
|
||||
* actions associated with them. That is, you either have the permission
|
||||
* or you don't.
|
||||
*
|
||||
* The most important method in this class is <code>implies</code>. This
|
||||
* checks whether if one has this permission, then the specified
|
||||
* permission is also implied. As a conceptual example, consider the
|
||||
* permissions "Read All Files" and "Read File foo". The permission
|
||||
* "Read All Files" implies that the caller has permission to read the
|
||||
* file foo.
|
||||
*
|
||||
* <code>Permission</code>'s are not dynamic objects. Once created, a
|
||||
* <code>Permission</code>'s name and action list cannot be changed.
|
||||
*
|
||||
* @version 0.0
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public abstract class Permission implements Guard, Serializable
|
||||
{
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the name assigned to this permission object.
|
||||
*/
|
||||
protected String name; // Taken from the serializable form information
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method initializes a new instance of <code>Permission</code> to
|
||||
* have the specified name.
|
||||
*/
|
||||
public
|
||||
Permission(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method returns the name of this <code>Permission</code>
|
||||
*
|
||||
* @return The name of this <code>Permission</code>
|
||||
*/
|
||||
public String
|
||||
getName()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns the list of actions for this <code>Permission</code>
|
||||
* as a <code>String</code>.
|
||||
*
|
||||
* @return The action list for this <code>Permission</code>.
|
||||
*/
|
||||
public abstract String
|
||||
getActions();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method implements the <code>Guard</code> interface for this class.
|
||||
* It calls the <code>checkPermission</code> method in
|
||||
* <code>SecurityManager</code> with this <code>Permission</code> as its
|
||||
* argument. This method returns silently if the security check succeeds
|
||||
* or throws an exception if it fails.
|
||||
*
|
||||
* @param obj The <code>Object</code> being guarded - ignored by this class
|
||||
*
|
||||
* @exception SecurityException If the security check fails
|
||||
*/
|
||||
public void
|
||||
checkGuard(Object obj) throws SecurityException
|
||||
{
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
// if (sm != null)
|
||||
// sm.checkPermission(this);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method tests whether this <code>Permission</code> implies that the
|
||||
* specified <code>Permission</code> is also granted.
|
||||
*
|
||||
* @param perm The <code>Permission</code> to test against
|
||||
*
|
||||
* @return <code>true</code> if the specified <code>Permission</code> is implied by this one, <code>false</code> otherwise.
|
||||
*/
|
||||
public abstract boolean
|
||||
implies(Permission perm);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns a hash code for this <code>Permission</code>.
|
||||
*
|
||||
* @return A hash value.
|
||||
*/
|
||||
public abstract int
|
||||
hashCode();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns a <code>String</code> representation of this
|
||||
* <code>Permission</code> object.
|
||||
*
|
||||
* @return This object as a <code>String</code>.
|
||||
*/
|
||||
public String
|
||||
toString()
|
||||
{
|
||||
return("'\"" + getClass().getName() + "\" \"" + getName() +
|
||||
"\"" + " \"" + getActions() + "\")'");
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns an empty <code>PermissionCollection</code> object
|
||||
* that can store permissions of this type, or <code>null</code> if no
|
||||
* such collection is defined.
|
||||
*
|
||||
* @return A new <code>PermissionCollection</code>
|
||||
*/
|
||||
public PermissionCollection
|
||||
newPermissionCollection()
|
||||
{
|
||||
return(null);
|
||||
}
|
||||
|
||||
} // class Permission
|
||||
|
207
libjava/java/security/PermissionCollection.java
Normal file
207
libjava/java/security/PermissionCollection.java
Normal file
|
@ -0,0 +1,207 @@
|
|||
/* PermissionCollection.java -- A collection of permission objects
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
As a special exception, if you link this library with other files to
|
||||
produce an executable, this library does not by itself cause the
|
||||
resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why the
|
||||
executable file might be covered by the GNU General Public License. */
|
||||
|
||||
|
||||
package java.security;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* This class models a group of Java permissions. It has convenient
|
||||
* methods for determining whether or not a given permission is implied
|
||||
* by any of the permissions in this collection.
|
||||
* <p>
|
||||
* Some care must be taken in storing permissions. First, a collection of
|
||||
* the appropriate type must be created. This is done by calling the
|
||||
* <code>newPermissionCollection</code> method on an object of the
|
||||
* permission class you wish to add to the collection. If this method
|
||||
* returns <code>null</code>, any type of <code>PermissionCollection</code>
|
||||
* can be used to store permissions of that type. However, if a
|
||||
* <code>PermissionCollection</code> collection object is returned, that
|
||||
* type must be used.
|
||||
* <p>
|
||||
* The <code>PermissionCollection</code>'s returned
|
||||
* by the <code>newPermissionCollection</code> instance in a subclass of
|
||||
* <code>Permission</code> is a homogeneous collection. It only will
|
||||
* hold permissions of one specified type - instances of the class that
|
||||
* created it. Not all <code>PermissionCollection</code> subclasses
|
||||
* have to hold permissions of only one type however. For example,
|
||||
* the <code>Permissions</code> class holds permissions of many types.
|
||||
* <p>
|
||||
* Since the <code>newPermissionCollection</code> in <code>Permission</code>
|
||||
* itself returns <code>null</code>, by default a permission can be stored
|
||||
* in any type of collection unless it overrides that method to create its
|
||||
* own collection type.
|
||||
*
|
||||
* @version 0.0
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public abstract class PermissionCollection extends Object implements Serializable
|
||||
{
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Class Variables
|
||||
*/
|
||||
|
||||
public static final String linesep = null;
|
||||
|
||||
static
|
||||
{
|
||||
String linesep = System.getProperty("line.separator");
|
||||
if (linesep == null);
|
||||
linesep = "\n";
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Indicates whether or not this collection is read only.
|
||||
*/
|
||||
private boolean readOnly;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method initializes a new instance of <code>PermissionCollection</code>.
|
||||
* This is provided only as a default constructor and does nothing in this
|
||||
* class.
|
||||
*/
|
||||
public
|
||||
PermissionCollection()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method tests whether or not this <code>PermissionCollection</code>
|
||||
* object is read only.
|
||||
*
|
||||
* @return <code>true</code> if this collection is read only, <code>false</code> otherwise
|
||||
*/
|
||||
public boolean
|
||||
isReadOnly()
|
||||
{
|
||||
return(readOnly);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method sets this <code>PermissionCollection</code> object to be
|
||||
* read only. No further permissions can be added to it after calling this
|
||||
* method.
|
||||
*/
|
||||
public void
|
||||
setReadOnly()
|
||||
{
|
||||
readOnly = true;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method adds a new <code>Permission</code> object to the collection.
|
||||
*
|
||||
* @param perm The <code>Permission</code> to add.
|
||||
*
|
||||
* @exception SecurityException If the collection is marked read only.
|
||||
* @exception IllegalArgumentException If a permission of the specified type cannot be added
|
||||
*/
|
||||
public abstract void
|
||||
add(Permission perm) throws SecurityException, IllegalArgumentException;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns an <code>Enumeration</code> of all the objects in
|
||||
* this collection.
|
||||
*
|
||||
* @return An <code>Enumeration</code> of this collection's objects.
|
||||
*/
|
||||
public abstract Enumeration
|
||||
elements();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method tests whether the specified <code>Permission</code> object is
|
||||
* implied by this collection of <code>Permission</code> objects.
|
||||
*
|
||||
* @param perm The <code>Permission</code> object to test.
|
||||
*
|
||||
* @return <code>true</code> if the specified <code>Permission</code> is implied by this collection, <code>false</code> otherwise.
|
||||
*/
|
||||
public abstract boolean
|
||||
implies(Permission perm);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method returns a <code>String</code> representation of this
|
||||
* collection. It will print the class name and has code in the same
|
||||
* manner as <code>Object.toString()</code> then print a listing of all
|
||||
* the <code>Permission</code> objects contained.
|
||||
*
|
||||
* @return A <code>String</code> representing this object.
|
||||
*/
|
||||
public String
|
||||
toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("");
|
||||
|
||||
sb.append(super.toString() + " (" + linesep);
|
||||
Enumeration e = elements();
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
Object obj = e.nextElement();
|
||||
if (obj instanceof Permission)
|
||||
sb.append(((Permission)obj).toString() + linesep);
|
||||
}
|
||||
|
||||
sb.append(")" + linesep);
|
||||
return(sb.toString());
|
||||
}
|
||||
|
||||
} // class PermissionCollection
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue