From 7eee682ba80fbddd26e9ab9ddfa320711485a405 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 2 Sep 2001 06:18:49 +0000 Subject: Makefile.in: Rebuilt. * Makefile.in: Rebuilt. * Makefile.am (core_java_source_files): Added UnsupportedClassVersionError. * java/lang/UnsupportedClassVersionError.java: New file from Classpath. * java/io/CharConversionException.java, java/io/EOFException.java, java/io/FileNotFoundException.java, java/io/IOException.java, java/io/InterruptedIOException.java, java/io/ObjectStreamException.java, java/io/OptionalDataException.java, java/io/StreamCorruptedException.java, java/io/SyncFailedException.java, java/io/UTFDataFormatException.java, java/io/UnsupportedEncodingException.java, java/lang/AbstractMethodError.java, java/lang/ArithmeticException.java, java/lang/ArrayIndexOutOfBoundsException.java, java/lang/ArrayStoreException.java, java/lang/ClassCastException.java, java/lang/ClassCircularityError.java, java/lang/ClassFormatError.java, java/lang/CloneNotSupportedException.java, java/lang/Error.java, java/lang/Exception.java, java/lang/ExceptionInInitializerError.java, java/lang/IllegalAccessError.java, java/lang/IllegalAccessException.java, java/lang/IllegalArgumentException.java, java/lang/IllegalMonitorStateException.java, java/lang/IllegalStateException.java, java/lang/IllegalThreadStateException.java, java/lang/IncompatibleClassChangeError.java, java/lang/IndexOutOfBoundsException.java, java/lang/InstantiationError.java, java/lang/InstantiationException.java, java/lang/InternalError.java, java/lang/InterruptedException.java, java/lang/LinkageError.java, java/lang/NegativeArraySizeException.java, java/lang/NoClassDefFoundError.java, java/lang/NoSuchFieldError.java, java/lang/NoSuchFieldException.java, java/lang/NoSuchMethodError.java, java/lang/NoSuchMethodException.java, java/lang/NullPointerException.java, java/lang/NumberFormatException.java, java/lang/OutOfMemoryError.java, java/lang/RuntimeException.java, java/lang/SecurityException.java, java/lang/StackOverflowError.java, java/lang/StringIndexOutOfBoundsException.java, java/lang/ThreadDeath.java, java/lang/UnknownError.java, java/lang/UnsatisfiedLinkError.java, java/lang/UnsupportedOperationException.java, java/lang/VerifyError.java, java/lang/VirtualMachineError.java, java/lang/reflect/InvocationTargetException.java, java/net/BindException.java, java/net/ConnectException.java, java/net/MalformedURLException.java, java/net/NoRouteToHostException.java, java/net/ProtocolException.java, java/net/SocketException.java, java/net/UnknownHostException.java, java/net/UnknownServiceException.java, java/text/ParseException.java: Copied from Classpath, thanks to Mark Wielaard who did the merge. * java/lang/System.java (getProperty): Use single argument form of SecurityManager.checkPropertyAccess. * Makefile.in: Rebuilt. * Makefile.am (core_java_source_files): Added VMSecurityManager. * java/lang/VMSecurityManager.java: New file. * java/lang/SecurityManager.java: Merged with Classpath. From-SVN: r45353 --- libjava/java/lang/SecurityManager.java | 1011 ++++++++++++++++++++++++-------- 1 file changed, 754 insertions(+), 257 deletions(-) (limited to 'libjava/java/lang/SecurityManager.java') diff --git a/libjava/java/lang/SecurityManager.java b/libjava/java/lang/SecurityManager.java index 9c14552..345bb22 100644 --- a/libjava/java/lang/SecurityManager.java +++ b/libjava/java/lang/SecurityManager.java @@ -1,268 +1,765 @@ -/* Copyright (C) 1998, 1999 Free Software Foundation +/* java.lang.SecurityManager + Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. - This file is part of libgcj. +This file is part of GNU Classpath. -This software is copyrighted work licensed under the terms of the -Libgcj License. Please consult the file "LIBGCJ_LICENSE" for -details. */ +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. */ -// SecurityManager package java.lang; +import java.net.*; +import java.util.*; +import java.io.*; + /** - * @author Anthony Green - * @date October 5, 1998. - */ + ** SecurityManager is a class you can extend to create + ** your own Java security policy. By default, there is + ** no SecurityManager installed in 1.1, which means that + ** all things are permitted to all people.

+ ** + ** The default methods in this class deny all + ** things to all people. + ** + ** @author John Keiser + ** @version 1.1.0, 31 May 1998 + ** @since JDK1.0 + **/ +public class SecurityManager { + /** Tells whether or not the SecurityManager is currently + ** performing a security check. + **/ + protected boolean inCheck; + + /** Tells whether or not the SecurityManager is currently + ** performing a security check. + ** + ** @return whether or not the SecurityManager is + ** currently performing a security check. + **/ + public boolean getInCheck() { + return inCheck; + } -/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 - */ + /** Get a list of all the classes currently executing + ** methods on the Java stack. getClassContext()[0] is + ** the currently executing method + ** Spec Note: does not say whether + ** the stack will include the getClassContext() call or + ** the one just before it. + ** + ** @return an array containing all the methods on classes + ** on the Java execution stack. + **/ + protected Class[] getClassContext() { + return VMSecurityManager.getClassContext(); + } -import java.io.*; -import java.net.*; + /** Find the ClassLoader for the most recent class on the + ** stack that was loaded by an explicit ClassLoader. If + ** everything on the stack was loaded by the system + ** classloader, null is returned. + ** + ** @return the most recent ClassLoader on the execution + ** stack. + **/ + protected ClassLoader currentClassLoader() { + return VMSecurityManager.currentClassLoader(); + } + + /** Find the most recent class on the stack that was + ** loaded by an explicit ClassLoader. If everything on + ** the stack was loaded by the system classloader, null + ** is returned. + ** + ** @return the most recent loaded Class on the execution + ** stack. + **/ + protected Class currentLoadedClass() { + Class[] c = getClassContext(); + for(int i=0;i + ** + ** Currently the only methods that use this are checkRead() + ** and checkConnect(). + ** + ** @see checkConnect(java.lang.String,int,java.lang.Object) + ** @see checkRead(java.lang.String,java.lang.Object) + **/ + public Object getSecurityContext() { + return new SecurityContext(getClassContext()); + } -public abstract class SecurityManager -{ - protected boolean inCheck = false; - - public void checkAccept (String host, int port) - { - throw new SecurityException(); - } - - public void checkAccess (Thread thrd) - { - throw new SecurityException(); - } - - public void checkAccess (ThreadGroup thrdGroup) - { - throw new SecurityException(); - } - - public void checkAwtEventQueueAccess () - { - throw new SecurityException(); - } - - public void checkConnect (String host, int prt) - { - throw new SecurityException(); - } - - public void checkConnect (String host, int prt, Object ctx) - { - throw new SecurityException(); - } - - public void checkCreateClassLoader () - { - throw new SecurityException(); - } - - public void checkDelete (String fileName) - { - throw new SecurityException(); - } - - public void checkExec (String prog) - { - throw new SecurityException(); - } - - public void checkExit (int stat) - { - throw new SecurityException(); - } - - public void checkLink (String lib) - { - throw new SecurityException(); - } - - public void checkListen (int lport) - { - throw new SecurityException(); - } - - public void checkMemberAccess (Class cl, int mtype) - { - throw new SecurityException(); - } - - public void checkMulticast (InetAddress maddr) - { - throw new SecurityException(); - } - - public void checkMulticast (InetAddress maddr, byte ttl) - { - throw new SecurityException(); - } - - public void checkPackageAccess (String pkg) - { - throw new SecurityException(); - } - - public void checkPackageDefinition (String pkg) - { - throw new SecurityException(); - } - - public void checkPermission (java.security.Permission perm) - { - throw new SecurityException(); - } - - public void checkPrintJobAccess () - { - throw new SecurityException(); - } - - public void checkPropertiesAccess () - { - throw new SecurityException(); - } - - public void checkPropertyAccess (String prop) - { - throw new SecurityException(); - } - - public void checkPropertyAccess (String prop, String defval) - { - throw new SecurityException(); - } - - public void checkRead (FileDescriptor fd) - { - throw new SecurityException(); - } - - public void checkRead (String fileName) - { - throw new SecurityException(); - } - - public void checkRead (String fileName, Object ctx) - { - throw new SecurityException(); - } - - public void checkSecurityAccess (String action) - { - throw new SecurityException(); - } - - public void checkSetFactory () - { - throw new SecurityException(); - } - - public void checkSystemClipboardAccess () - { - throw new SecurityException(); - } - - public boolean checkTopLevelWindow (Object window) - { - throw new SecurityException(); - } - - public void checkWrite (FileDescriptor fd) - { - throw new SecurityException(); - } - - public void checkWrite (String fileName) - { - throw new SecurityException(); - } - - // Note: this method is deprecated in JDK 1.2 - protected /* native */ int classDepth (String className) - { - Class[] classStack = getClassContext (); - for (int i = 0; i < classStack.length; i++) - if (classStack[i].getName().compareTo(className) == 0) - return i; - - return -1; - } - - // Note: this method is deprecated in JDK 1.2 - protected /* native */ int classLoaderDepth () - { - Class[] classStack = getClassContext (); - for (int i = 0; i < classStack.length; i++) - if (classStack[i].getClassLoader() != null) - return i; - - return -1; - } - - protected /* native */ ClassLoader currentClassLoader () - { - Class[] classStack = getClassContext (); - for (int i = 0; i < classStack.length; i++) - { - ClassLoader loader = classStack[i].getClassLoader(); - if (loader != null) - return loader; - } - - return null; - } - - protected /* native */ Class currentLoadedClass () - { - Class[] classStack = getClassContext (); - for (int i = 0; i < classStack.length; i++) - { - ClassLoader loader = classStack[i].getClassLoader(); - if (loader != null) - return classStack[i]; - } - - return null; - } - - protected /* native */ Class[] getClassContext () - { - return new Class[0]; - } - - // Note: this method is deprecated in JDK 1.2 - public boolean getInCheck () - { - return inCheck; - } - - public Object getSecurityContext () - { - // FIXME: This has yet to be implemented. - return new String(""); - } - - public ThreadGroup getThreadGroup () - { - return Thread.currentThread().getThreadGroup(); - } - - protected boolean inClass (String className) - { - return (classDepth (className) != -1); - } - - protected boolean inClassLoader () - { - return (classLoaderDepth () != -1); - } - - protected SecurityManager () - { - if (System.getSecurityManager () != null) - throw new SecurityException (); - } + /** Check if the current thread is allowed to create a + ** ClassLoader.

+ ** + ** This method is called from ClassLoader.ClassLoader(), + ** in other words, whenever a ClassLoader is created.

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.ClassLoader#ClassLoader() + **/ + public void checkCreateClassLoader() { + throw new SecurityException("Cannot create new ClassLoaders."); + } + + /** Check if the current thread is allowed to modify this + ** other Thread.

+ ** + ** Called by Thread.stop(), suspend(), resume(), and + ** interrupt(), destroy(), setPriority(), setName() and + ** setDaemon().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param g the Thread to check against + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.Thread#stop() + ** @see java.lang.Thread#suspend() + ** @see java.lang.Thread#resume() + ** @see java.lang.Thread#interrupt() + ** @see java.lang.Thread#destroy() + ** @see java.lang.Thread#setPriority(int) + ** @see java.lang.Thread#setName(java.lang.String) + ** @see java.lang.Thread#setDaemon(boolean) + **/ + public void checkAccess(Thread t) { + throw new SecurityException("Cannot modify Threads."); + } + + /** Check if the current thread is allowed to modify this + ** ThreadGroup.

+ ** + ** Called by Thread.Thread() (to add a thread to the + ** ThreadGroup), ThreadGroup.ThreadGroup() (to add this + ** ThreadGroup to a parent), ThreadGroup.stop(), + ** suspend(), resume(), interrupt(), destroy(), + ** setDaemon(), and setMaxPriority().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param g the ThreadGroup to check against + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.Thread#Thread() + ** @see java.lang.ThreadGroup#ThreadGroup() + ** @see java.lang.ThreadGroup#stop() + ** @see java.lang.ThreadGroup#suspend() + ** @see java.lang.ThreadGroup#resume() + ** @see java.lang.ThreadGroup#interrupt() + ** @see java.lang.ThreadGroup#setDaemon(boolean) + ** @see java.lang.ThreadGroup#setMaxPriority(int) + **/ + public void checkAccess(ThreadGroup g) { + throw new SecurityException("Cannot modify ThreadGroups."); + } + + /** Check if the current thread is allowed to exit the + ** JVM with the given status.

+ ** + ** This method is called from Runtime.exit().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param status the status to exit with + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.Runtime#exit() + ** @see java.lang.Runtime#exit(int) + **/ + public void checkExit(int status) { + throw new SecurityException("Cannot exit JVM."); + } + + /** Check if the current thread is allowed to execute the + ** given program.

+ ** + ** This method is called from Runtime.exec().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param program the name of the program to exec + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.Runtime#exec(java.lang.String[],java.lang.String[]) + **/ + public void checkExec(String program) { + throw new SecurityException("Cannot execute programs."); + } + + /** Check if the current thread is allowed to link in the + ** given native library.

+ ** + ** This method is called from Runtime.load() (and hence, + ** by loadLibrary() as well).

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param filename the full name of the library to load + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.Runtime#load(java.lang.String) + **/ + public void checkLink(String filename) { + throw new SecurityException("Cannot link native libraries."); + } + + /** Check if the current thread is allowed to read the + ** given file using the FileDescriptor.

+ ** + ** This method is called from + ** FileInputStream.FileInputStream().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param desc the FileDescriptor representing the file + ** to access + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.io.FileInputStream#FileInputStream(java.io.FileDescriptor) + **/ + public void checkRead(FileDescriptor desc) { + throw new SecurityException("Cannot read files via file descriptors."); + } + + /** Check if the current thread is allowed to read the + ** given file.

+ ** + ** This method is called from + ** FileInputStream.FileInputStream(), + ** RandomAccessFile.RandomAccessFile(), File.exists(), + ** canRead(), isFile(), isDirectory(), lastModified(), + ** length() and list().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param filename the full name of the file to access + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.io.File + ** @see java.io.FileInputStream#FileInputStream(java.lang.String) + ** @see java.io.RandomAccessFile#RandomAccessFile(java.lang.String) + **/ + public void checkRead(String filename) { + throw new SecurityException("Cannot read files via file names."); + } + + /** Check if the current thread is allowed to read the + ** given file. using the given SecurityContext.

+ ** + ** I know of no core class that calls this method.

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param filename the full name of the file to access + ** @param securityContext the Security Context to + ** determine access for. + ** @exception SecurityException if the operation is not + ** permitted. + **/ + public void checkRead(String filename, Object securityContext) { + throw new SecurityException("Cannot read files via file names."); + } + + /** Check if the current thread is allowed to write to the + ** given file using the FileDescriptor.

+ ** + ** This method is called from + ** FileOutputStream.FileOutputStream().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param desc the FileDescriptor representing the file + ** to access + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor) + **/ + public void checkWrite(FileDescriptor desc) { + throw new SecurityException("Cannot write files via file descriptors."); + } + + /** Check if the current thread is allowed to write to the + ** given file.

+ ** + ** This method is called from + ** FileOutputStream.FileOutputStream(), + ** RandomAccessFile.RandomAccessFile(), + ** File.canWrite(), mkdir(), and renameTo().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param filename the full name of the file to access + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.io.File#canWrite() + ** @see java.io.File#mkdir() + ** @see java.io.File#renameTo() + ** @see java.io.FileOutputStream#FileOutputStream(java.lang.String) + ** @see java.io.RandomAccessFile#RandomAccessFile(java.lang.String) + **/ + public void checkWrite(String filename) { + throw new SecurityException("Cannot write files via file names."); + } + + /** Check if the current thread is allowed to delete the + ** given file.

+ ** + ** This method is called from File.delete().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param filename the full name of the file to delete + ** @exception SecurityException if th operation is not + ** permitted. + ** @see java.io.File#delete() + **/ + public void checkDelete(String filename) { + throw new SecurityException("Cannot delete files."); + } + + /** Check if the current thread is allowed to connect to a + ** given host on a given port.

+ ** + ** This method is called from Socket.Socket(). + ** + ** SecurityManager's implementation always denies access. + ** + ** @param host the host to connect to + ** @param port the port to connect on + ** @exception SecurityException if the operation is not + ** permitted + ** @see java.net.Socket#Socket() + **/ + public void checkConnect(String host, int port) { + throw new SecurityException("Cannot make network connections."); + } + + /** Check if the current thread is allowed to connect to a + ** given host on a given port using a specific security + ** context to determine access.

+ ** + ** This method is not called in the 1.1 core classes.

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param host the host to connect to + ** @param port the port to connect on + ** @param securityContext the security context to + ** determine access with + ** @exception SecurityException if the operation is not + ** permitted + **/ + public void checkConnect(String host, int port, Object securityContext) { + throw new SecurityException("Cannot make network connections."); + } + + /** Check if the current thread is allowed to listen to a + ** specific port for data.

+ ** + ** This method is called by ServerSocket.ServerSocket().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param port the port to listen on + ** @exception SecurityException if the operation is not + ** permitted + ** @see java.net.ServerSocket#ServerSocket(int) + **/ + public void checkListen(int port) { + throw new SecurityException("Cannot listen for connections."); + } + + /** Check if the current thread is allowed to accept a + ** connection from a particular host on a particular + ** port.

+ ** + ** This method is called by ServerSocket.implAccept().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param host the host which wishes to connect + ** @param port the port the connection will be on + ** @exception SecurityException if the operation is not + ** permitted + ** @see java.net.ServerSocket#accept() + **/ + public void checkAccept(String host, int port) { + throw new SecurityException("Cannot accept connections."); + } + + /** Check if the current thread is allowed to read and + ** write multicast to a particular address.

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @XXX where is it called? + ** + ** @param addr the address to multicast to. + ** @exception SecurityException if the operation is not + ** permitted. + **/ + public void checkMulticast(InetAddress addr) { + throw new SecurityException("Cannot read or write multicast."); + } + + /** Check if the current thread is allowed to read and + ** write multicast to a particular address with a + ** particular ttl value.

+ ** + ** SecurityManager's implementation always denies access.

+ ** + ** @XXX where is it called? + ** + ** @XXX what the hell is ttl? Expand abbreviation. + ** + ** @param addr the address to multicast to. + ** @param ttl the ttl value to use + ** @exception SecurityException if the operation is not + ** permitted. + **/ + public void checkMulticast(InetAddress addr, byte ttl) { + throw new SecurityException("Cannot read or write multicast."); + } + + /** + ** Check if the current thread is allowed to perform an + ** operation that requires the specified Permission. + ** + ** @param perm The Permission required. + ** @exception SecurityException If the operation is not allowed. + **/ + public void checkPermission(java.security.Permission perm) { + throw new SecurityException("Operation not allowed"); + } + + /** + ** Check if the current thread is allowed to perform an + ** operation that requires the specified Permission. + ** + ** @param perm The Permission required. + ** @param context A security context + ** @exception SecurityException If the operation is not allowed. + ** @since 1.2 + **/ + public void checkPermission(java.security.Permission perm, + Object context) { + throw new SecurityException("Operation not allowed"); + } + + /** Check if the current thread is allowed to read or + ** write all the system properties at once.

+ ** + ** This method is called by System.getProperties() + ** and setProperties().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.System#getProperties() + ** @see java.lang.System#setProperties(java.util.Properties) + **/ + public void checkPropertiesAccess() { + throw new SecurityException("Cannot access all system properties at once."); + } + + /** Check if the current thread is allowed to read or + ** write a particular system property.

+ ** + ** This method is called by System.getProperty() and + ** setProperty().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @exception SecurityException is the operation is not + ** permitted. + ** @see java.lang.System#getProperty(java.lang.String) + ** @see java.lang.System#setProperty(java.lang.String,java.lang.String) + **/ + public void checkPropertyAccess(String name) { + throw new SecurityException("Cannot access individual system properties."); + } + + /** Check if the current thread is allowed to create a + ** top-level window. If it is not, the operation should + ** still go through, but some sort of nonremovable + ** warning should be placed on the window to show that it + ** is untrusted.

+ ** + ** This method is called by Window.Window().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param window the window to create + ** @see java.awt.Window#Window(java.awt.Frame) + **/ + public boolean checkTopLevelWindow(Object window) { + return false; + } + + /** Check if the current thread is allowed to create a + ** print job.

+ ** + ** This method is called by Toolkit.getPrintJob(). (I + ** assume so, at least, it just don't say nothing about + ** it in the spec.)

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.awt.Toolkit.getPrintJob(java.awt.Frame,java.lang.String,java.util.Properties) + **/ + public void checkPrintJobAccess() { + throw new SecurityException("Cannot create print jobs."); + } + + /** Check if the current thread is allowed to use the + ** system clipboard.

+ ** + ** This method is called by Toolkit.getSystemClipboard(). + ** (I assume.)

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.awt.Toolkit#getSystemClipboard() + **/ + public void checkSystemClipboardAccess() { + throw new SecurityException("Cannot access the system clipboard."); + } + + /** Check if the current thread is allowed to use the AWT + ** event queue.

+ ** + ** This method is called by Toolkit.getSystemEventQueue().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.awt.Toolkit#getSystemEventQueue() + **/ + public void checkAwtEventQueueAccess() { + throw new SecurityException("Cannot access the AWT event queue."); + } + + /** Check if the current thread is allowed to access the + ** specified package at all.

+ ** + ** This method is called by ClassLoader.loadClass() in + ** user-created ClassLoaders.

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param packageName the package name to check access to + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.ClassLoader#loadClass(java.lang.String,boolean) + **/ + public void checkPackageAccess(String packageName) { + throw new SecurityException("Cannot access packages via the ClassLoader."); + } + + /** Check if the current thread is allowed to define + ** classes the specified package. If the class already + ** created, though, ClassLoader.loadClass() can still + ** return the Class if checkPackageAccess() checks out.

+ ** + ** This method is called by ClassLoader.loadClass() in + ** user-created ClassLoaders.

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param packageName the package name to check access to + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.ClassLoader#loadClass(java.lang.String,boolean) + **/ + public void checkPackageDefinition(String packageName) { + throw new SecurityException("Cannot load classes into any packages via the ClassLoader."); + } + + /** Check if the current thread is allowed to set the + ** current socket factory.

+ ** + ** This method is called by Socket.setSocketImplFactory(), + ** ServerSocket.setSocketFactory(), and + ** URL.setURLStreamHandlerFactory().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) + ** @see java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory) + ** @see java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory) + **/ + public void checkSetFactory() { + throw new SecurityException("Cannot set the socket factory."); + } + + /** Check if the current thread is allowed to get certain + ** types of Methods, Fields and Constructors from a Class + ** object.

+ ** + ** This method is called by Class.getMethod[s](), + ** Class.getField[s](), Class.getConstructor[s], + ** Class.getDeclaredMethod[s](), + ** Class.getDeclaredField[s](), and + ** Class.getDeclaredConstructor[s]().

+ ** + ** SecurityManager's implementation always denies access. + ** + ** @param c the Class to check + ** @param memberType the type of members to check + ** against, either Member.DECLARED or + ** Member.PUBLIC. + ** @exception SecurityException if the operation is not + ** permitted. + ** @see java.lang.Class + ** @see java.lang.reflect.Member#DECLARED + ** @see java.lang.reflect.Member#PUBLIC + **/ + public void checkMemberAccess(Class c, int memberType) { + throw new SecurityException("Cannot access members of classes."); + } + + /** Test whether a particular security action may be + ** taken. + ** @param action the desired action to take + ** @exception SecurityException if the action is denied. + ** @XXX I have no idea what actions must be tested + ** or where. + **/ + public void checkSecurityAccess(String action) { + checkPermission (new java.security.SecurityPermission (action)); + } + + /** Get the ThreadGroup that a new Thread should belong + ** to by default.

+ ** + ** Called by Thread.Thread().

+ ** + ** SecurityManager's implementation just uses the + ** ThreadGroup of the current Thread.

+ ** + ** Spec Note: it is not clear whether + ** the new Thread is guaranteed to pass the + ** checkAccessThreadGroup() test when using this + ** ThreadGroup. I presume so. + ** + ** @return the ThreadGroup to put the new Thread into. + **/ + public ThreadGroup getThreadGroup() { + return Thread.currentThread().getThreadGroup(); + } + + protected SecurityManager () { + if (System.getSecurityManager () != null) + throw new SecurityException (); + } +} + +class SecurityContext { + Class[] classes; + SecurityContext(Class[] classes) { + this.classes = classes; + } } -- cgit v1.1