OSDN Git Service

2007-01-26 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / classpath / java / lang / SecurityManager.java
index ef9e759..ff84d95 100644 (file)
@@ -1,5 +1,5 @@
 /* SecurityManager.java -- security checks for privileged actions
-   Copyright (C) 1998, 1999, 2001, 2002, 200 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -43,17 +43,30 @@ import gnu.classpath.VMStackWalker;
 import java.awt.AWTPermission;
 import java.io.File;
 import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.FilePermission;
+import java.io.RandomAccessFile;
 import java.lang.reflect.Member;
 import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketImplFactory;
 import java.net.SocketPermission;
+import java.net.URL;
+import java.net.URLStreamHandlerFactory;
 import java.security.AccessControlContext;
+import java.security.AccessControlException;
 import java.security.AccessController;
 import java.security.AllPermission;
+import java.security.BasicPermission;
 import java.security.Permission;
+import java.security.Policy;
 import java.security.PrivilegedAction;
+import java.security.ProtectionDomain;
 import java.security.Security;
 import java.security.SecurityPermission;
+import java.util.Properties;
 import java.util.PropertyPermission;
 import java.util.StringTokenizer;
 
@@ -154,6 +167,18 @@ public class SecurityManager
    */
   public SecurityManager()
   {
+    /* "When there is security manager installed, the security manager
+       need to check the package access. However, if the security
+       manager itself uses any unloaded class, it will trigger the
+       classloading, which causes infinite loop. There is no easy
+       legal solution. The workaround will be that security manager
+       can not depend on any unloaded class. In the constructor of
+       security manager, it must transitively load all classes it
+       refers to."  Sun bug #4242924.  */
+
+    // Load and initialize java.security.Security
+    java.security.Security.getProvider((String)null);
+
     SecurityManager sm = System.getSecurityManager();
     if (sm != null)
       sm.checkPermission(new RuntimePermission("createSecurityManager"));
@@ -196,7 +221,7 @@ public class SecurityManager
    * <ul>
    * <li>All methods on the stack are from system classes</li>
    * <li>All methods on the stack up to the first "privileged" caller, as
-   *  created by {@link AccessController.doPrivileged(PrivilegedAction)},
+   *  created by {@link AccessController#doPrivileged(PrivilegedAction)},
    *  are from system classes</li>
    * <li>A check of <code>java.security.AllPermission</code> succeeds.</li>
    * </ul>
@@ -219,7 +244,7 @@ public class SecurityManager
    * <ul>
    * <li>All methods on the stack are from system classes</li>
    * <li>All methods on the stack up to the first "privileged" caller, as
-   *  created by {@link AccessController.doPrivileged(PrivilegedAction)},
+   *  created by {@link AccessController#doPrivileged(PrivilegedAction)},
    *  are from system classes</li>
    * <li>A check of <code>java.security.AllPermission</code> succeeds.</li>
    * </ul>
@@ -227,7 +252,7 @@ public class SecurityManager
    * @return the most recent non-system Class on the execution stack
    * @deprecated use {@link #checkPermission(Permission)} instead
    */
-  protected Class currentLoadedClass()
+  protected Class<?> currentLoadedClass()
   {
     int i = classLoaderDepth();
     return i >= 0 ? getClassContext()[i] : null;
@@ -258,7 +283,7 @@ public class SecurityManager
    * <ul>
    * <li>All methods on the stack are from system classes</li>
    * <li>All methods on the stack up to the first "privileged" caller, as
-   *  created by {@link AccessController.doPrivileged(PrivilegedAction)},
+   *  created by {@link AccessController#doPrivileged(PrivilegedAction)},
    *  are from system classes</li>
    * <li>A check of <code>java.security.AllPermission</code> succeeds.</li>
    * </ul>
@@ -408,7 +433,7 @@ public class SecurityManager
   public void checkAccess(Thread thread)
   {
     if (thread.getThreadGroup() != null 
-       && thread.getThreadGroup().getParent() != null)
+       && thread.getThreadGroup().parent == null)
       checkPermission(new RuntimePermission("modifyThread"));
   }
 
@@ -431,7 +456,7 @@ public class SecurityManager
    * @throws SecurityException if permission is denied
    * @throws NullPointerException if g is null
    * @see Thread#Thread()
-   * @see ThreadGroup#ThreadGroup()
+   * @see ThreadGroup#ThreadGroup(String)
    * @see ThreadGroup#stop()
    * @see ThreadGroup#suspend()
    * @see ThreadGroup#resume()
@@ -441,7 +466,7 @@ public class SecurityManager
    */
   public void checkAccess(ThreadGroup g)
   {
-    if (g.getParent() != null)
+    if (g.parent == null)
       checkPermission(new RuntimePermission("modifyThreadGroup"));
   }
 
@@ -537,7 +562,7 @@ public class SecurityManager
    * @throws NullPointerException if filename is null
    * @see File
    * @see FileInputStream#FileInputStream(String)
-   * @see RandomAccessFile#RandomAccessFile(String)
+   * @see RandomAccessFile#RandomAccessFile(String, String)
    */
   public void checkRead(String filename)
   {
@@ -602,9 +627,9 @@ public class SecurityManager
    * @see File
    * @see File#canWrite()
    * @see File#mkdir()
-   * @see File#renameTo()
+   * @see File#renameTo(File)
    * @see FileOutputStream#FileOutputStream(String)
-   * @see RandomAccessFile#RandomAccessFile(String)
+   * @see RandomAccessFile#RandomAccessFile(String, String)
    */
   public void checkWrite(String filename)
   {
@@ -821,7 +846,7 @@ public class SecurityManager
    * @param window the window to create
    * @return true if there is permission to show the window without warning
    * @throws NullPointerException if window is null
-   * @see Window#Window(Frame)
+   * @see java.awt.Window#Window(java.awt.Frame)
    */
   public boolean checkTopLevelWindow(Object window)
   {
@@ -846,7 +871,7 @@ public class SecurityManager
    * an exception.
    *
    * @throws SecurityException if permission is denied
-   * @see Toolkit#getPrintJob(Frame, String, Properties)
+   * @see java.awt.Toolkit#getPrintJob(java.awt.Frame, String, Properties)
    * @since 1.1
    */
   public void checkPrintJobAccess()
@@ -862,7 +887,7 @@ public class SecurityManager
    * rather than throwing an exception.
    *
    * @throws SecurityException if permission is denied
-   * @see Toolkit#getSystemClipboard()
+   * @see java.awt.Toolkit#getSystemClipboard()
    * @since 1.1
    */
   public void checkSystemClipboardAccess()
@@ -878,7 +903,7 @@ public class SecurityManager
    * rather than throwing an exception.
    *
    * @throws SecurityException if permission is denied
-   * @see Toolkit#getSystemEventQueue()
+   * @see java.awt.Toolkit#getSystemEventQueue()
    * @since 1.1
    */
   public void checkAwtEventQueueAccess()
@@ -970,7 +995,7 @@ public class SecurityManager
    * @see Member#PUBLIC
    * @since 1.1
    */
-  public void checkMemberAccess(Class c, int memberType)
+  public void checkMemberAccess(Class<?> c, int memberType)
   {
     if (c == null)
       throw new NullPointerException();