📄 securitymanager.java
字号:
* this, you should call <code>super.checkCreateClassLoader()</code> rather * than throwing an exception. * * @throws SecurityException if permission is denied * @see ClassLoader#ClassLoader() */ public void checkCreateClassLoader() { checkPermission(new RuntimePermission("createClassLoader")); } /** * Check if the current thread is allowed to modify another Thread. This is * called by Thread.stop(), suspend(), resume(), interrupt(), destroy(), * setPriority(), setName(), and setDaemon(). The default implementation * checks <code>RuntimePermission("modifyThread") on system threads (ie. * threads in ThreadGroup with a null parent), and returns silently on * other threads. * * <p>If you override this, you must do two things. First, call * <code>super.checkAccess(t)</code>, to make sure you are not relaxing * requirements. Second, if the calling thread has * <code>RuntimePermission("modifyThread")</code>, return silently, so that * core classes (the Classpath library!) can modify any thread. * * @param t the other Thread to check * @throws SecurityException if permission is denied * @throws NullPointerException if t is null * @see Thread#stop() * @see Thread#suspend() * @see Thread#resume() * @see Thread#setPriority(int) * @see Thread#setName(String) * @see Thread#setDaemon(boolean) */ public void checkAccess(Thread t) { if (t.group != null && t.group.getParent() != null) checkPermission(new RuntimePermission("modifyThread")); } /** * Check if the current thread is allowed to modify a ThreadGroup. This is * 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(). The default implementation * checks <code>RuntimePermission("modifyThread") on the system group (ie. * the one with a null parent), and returns silently on other groups. * * <p>If you override this, you must do two things. First, call * <code>super.checkAccess(t)</code>, to make sure you are not relaxing * requirements. Second, if the calling thread has * <code>RuntimePermission("modifyThreadGroup")</code>, return silently, * so that core classes (the Classpath library!) can modify any thread. * * @param g the ThreadGroup to check * @throws SecurityException if permission is denied * @throws NullPointerException if g is null * @see Thread#Thread() * @see ThreadGroup#ThreadGroup() * @see ThreadGroup#stop() * @see ThreadGroup#suspend() * @see ThreadGroup#resume() * @see ThreadGroup#interrupt() * @see ThreadGroup#setDaemon(boolean) * @see ThreadGroup#setMaxPriority(int) */ public void checkAccess(ThreadGroup g) { if (g.getParent() != null) checkPermission(new RuntimePermission("modifyThreadGroup")); } /** * Check if the current thread is allowed to exit the JVM with the given * status. This method is called from Runtime.exit() and Runtime.halt(). * The default implementation checks * <code>RuntimePermission("exitVM")</code>. If you override this, call * <code>super.checkExit</code> rather than throwing an exception. * * @param status the status to exit with * @throws SecurityException if permission is denied * @see Runtime#exit(int) * @see Runtime#halt(int) */ public void checkExit(int status) { checkPermission(new RuntimePermission("exitVM")); } /** * Check if the current thread is allowed to execute the given program. This * method is called from Runtime.exec(). If the name is an absolute path, * the default implementation checks * <code>FilePermission(program, "execute")</code>, otherwise it checks * <code>FilePermission("<<ALL FILES>>", "execute")</code>. If * you override this, call <code>super.checkExec</code> rather than * throwing an exception. * * @param program the name of the program to exec * @throws SecurityException if permission is denied * @throws NullPointerException if program is null * @see Runtime#exec(String[], String[], File) */ public void checkExec(String program) { if (! program.equals(new File(program).getAbsolutePath())) program = "<<ALL FILES>>"; checkPermission(new FilePermission(program, "execute")); } /** * 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). The default implementation checks * <code>RuntimePermission("loadLibrary." + filename)</code>. If you * override this, call <code>super.checkLink</code> rather than throwing * an exception. * * @param filename the full name of the library to load * @throws SecurityException if permission is denied * @throws NullPointerException if filename is null * @see Runtime#load(String) */ public void checkLink(String filename) { // Use the toString() hack to do the null check. checkPermission(new RuntimePermission("loadLibrary." + filename.toString())); } /** * Check if the current thread is allowed to read the given file using the * FileDescriptor. This method is called from * FileInputStream.FileInputStream(). The default implementation checks * <code>RuntimePermission("readFileDescriptor")</code>. If you override * this, call <code>super.checkRead</code> rather than throwing an * exception. * * @param desc the FileDescriptor representing the file to access * @throws SecurityException if permission is denied * @throws NullPointerException if desc is null * @see FileInputStream#FileInputStream(FileDescriptor) */ public void checkRead(FileDescriptor desc) { if (desc == null) throw new NullPointerException(); checkPermission(new RuntimePermission("readFileDescriptor")); } /** * 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(). The default * implementation checks <code>FilePermission(filename, "read")</code>. If * you override this, call <code>super.checkRead</code> rather than * throwing an exception. * * @param filename the full name of the file to access * @throws SecurityException if permission is denied * @throws NullPointerException if filename is null * @see File * @see FileInputStream#FileInputStream(String) * @see RandomAccessFile#RandomAccessFile(String) */ public void checkRead(String filename) { checkPermission(new FilePermission(filename, "read")); } /** * Check if the current thread is allowed to read the given file. using the * given security context. The context must be a result of a previous call * to <code>getSecurityContext()</code>. The default implementation checks * <code>AccessControlContext.checkPermission(new FilePermission(filename, * "read"))</code>. If you override this, call <code>super.checkRead</code> * rather than throwing an exception. * * @param filename the full name of the file to access * @param context the context to determine access for * @throws SecurityException if permission is denied, or if context is * not an AccessControlContext * @throws NullPointerException if filename is null * @see #getSecurityContext() * @see AccessControlContext#checkPermission(Permission) */ public void checkRead(String filename, Object context) { // XXX Should be: // if (! (context instanceof AccessControlContext)) // throw new SecurityException("Missing context"); // AccessControlContext ac = (AccessControlContext) context; // ac.checkPermission(new FilePermission(filename, "read")); throw new SecurityException("Cannot read files via file names."); } /** * Check if the current thread is allowed to write the given file using the * FileDescriptor. This method is called from * FileOutputStream.FileOutputStream(). The default implementation checks * <code>RuntimePermission("writeFileDescriptor")</code>. If you override * this, call <code>super.checkWrite</code> rather than throwing an * exception. * * @param desc the FileDescriptor representing the file to access * @throws SecurityException if permission is denied * @throws NullPointerException if desc is null * @see FileOutputStream#FileOutputStream(FileDescriptor) */ public void checkWrite(FileDescriptor desc) { if (desc == null) throw new NullPointerException(); checkPermission(new RuntimePermission("writeFileDescriptor")); } /** * Check if the current thread is allowed to write the given file. This * method is called from FileOutputStream.FileOutputStream(), * RandomAccessFile.RandomAccessFile(), File.canWrite(), mkdir(), and * renameTo(). The default implementation checks * <code>FilePermission(filename, "write")</code>. If you override this, * call <code>super.checkWrite</code> rather than throwing an exception. * * @param filename the full name of the file to access * @throws SecurityException if permission is denied * @throws NullPointerException if filename is null * @see File * @see File#canWrite() * @see File#mkdir() * @see File#renameTo() * @see FileOutputStream#FileOutputStream(String) * @see RandomAccessFile#RandomAccessFile(String) */ public void checkWrite(String filename) { checkPermission(new FilePermission(filename, "write")); } /** * Check if the current thread is allowed to delete the given file. This * method is called from File.delete(). The default implementation checks * <code>FilePermission(filename, "delete")</code>. If you override this, * call <code>super.checkDelete</code> rather than throwing an exception. * * @param filename the full name of the file to delete * @throws SecurityException if permission is denied * @throws NullPointerException if filename is null * @see File#delete() */ public void checkDelete(String filename) { checkPermission(new FilePermission(filename, "delete")); } /** * Check if the current thread is allowed to connect to a given host on a * given port. This method is called from Socket.Socket(). A port number * of -1 indicates the caller is attempting to determine an IP address, so * the default implementation checks * <code>SocketPermission(host, "resolve")</code>. Otherwise, the default * implementation checks * <code>SocketPermission(host + ":" + port, "connect")</code>. If you * override this, call <code>super.checkConnect</code> rather than throwing * an exception. * * @param host the host to connect to * @param port the port to connect on * @throws SecurityException if permission is denied * @throws NullPointerException if host is null * @see Socket#Socket() */ public void checkConnect(String host, int port) { if (port == -1) checkPermission(new SocketPermission(host, "resolve")); else // Use the toString() hack to do the null check. checkPermission(new SocketPermission(host.toString() + ":" + port, "connect")); } /** * Check if the current thread is allowed to connect to a given host on a * given port, using the given security context. The context must be a * result of a previous call to <code>getSecurityContext</code>. A port * number of -1 indicates the caller is attempting to determine an IP * address, so the default implementation checks * <code>AccessControlContext.checkPermission(new SocketPermission(host, * "resolve"))</code>. Otherwise, the default implementation checks * <code>AccessControlContext.checkPermission(new SocketPermission(host * + ":" + port, "connect"))</code>. If you override this, call * <code>super.checkConnect</code> rather than throwing an exception. * * @param host the host to connect to * @param port the port to connect on * @param context the context to determine access for * @throws SecurityException if permission is denied, or if context is * not an AccessControlContext * @throws NullPointerException if host is null * @see #getSecurityContext() * @see AccessControlContext#checkPermission(Permission) */ public void checkConnect(String host, int port, Object securityContext) { // XXX Should be: // if (! (context instanceof AccessControlContext)) // throw new SecurityException("Missing context"); // AccessControlContext ac = (AccessControlContext) context; // if (port == -1) // ac.checkPermission(new SocketPermission(host, "resolve")); // else // // Use the toString() hack to do the null check. // ac.checkPermission(new SocketPermission(host.toString + ":" +port, // "connect")); 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(). The default * implementation checks * <code>SocketPermission("localhost:" + (port == 0 ? "1024-" : "" + port), * "listen")</code>. If you override this, call * <code>super.checkListen</code> rather than throwing an exception. * * @param port the port to listen on * @throws SecurityException if permission is denied * @see ServerSocket#ServerSocket(int) */ public void checkListen(int port) { checkPermission(new SocketPermission("localhost:" + (port == 0 ? "1024-" : "" +port), "listen")); } /** * 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(). The default implementation checks * <code>SocketPermission(host + ":" + port, "accept")</code>. If you * override this, call <code>super.checkAccept</code> rather than throwing * an exception.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -