home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 31 / SUPERCDa.iso / Inet / HotJava / hjava.exe / Windows / resource / jre / lib / rt.jar / java / rmi / RMISecurityManager.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-11  |  5.8 KB  |  254 lines

  1. package java.rmi;
  2.  
  3. import java.io.FileDescriptor;
  4. import java.net.InetAddress;
  5. import java.net.URL;
  6. import java.net.UnknownHostException;
  7. import java.rmi.server.RMIClassLoader;
  8. import java.security.Security;
  9.  
  10. public class RMISecurityManager extends SecurityManager {
  11.    public RMISecurityManager() {
  12.       Security.getProviders();
  13.    }
  14.  
  15.    private boolean inLoadedClass() {
  16.       return ((SecurityManager)this).inClassLoader();
  17.    }
  18.  
  19.    public Object getSecurityContext() {
  20.       return RMIClassLoader.getSecurityContext(((SecurityManager)this).currentClassLoader());
  21.    }
  22.  
  23.    public synchronized void checkCreateClassLoader() {
  24.       if (this.inLoadedClass()) {
  25.          throw new RMISecurityException("classloader");
  26.       }
  27.    }
  28.  
  29.    public synchronized void checkAccess(Thread var1) {
  30.       if (this.inLoadedClass() && ((SecurityManager)this).classLoaderDepth() == 3) {
  31.          throw new RMISecurityException("thread");
  32.       }
  33.    }
  34.  
  35.    public synchronized void checkAccess(ThreadGroup var1) {
  36.       if (this.inLoadedClass() && ((SecurityManager)this).classLoaderDepth() == 4) {
  37.          throw new RMISecurityException("threadgroup");
  38.       }
  39.    }
  40.  
  41.    public synchronized void checkExit(int var1) {
  42.       if (this.inLoadedClass()) {
  43.          throw new RMISecurityException("exit", String.valueOf(var1));
  44.       }
  45.    }
  46.  
  47.    public synchronized void checkExec(String var1) {
  48.       if (this.inLoadedClass()) {
  49.          throw new RMISecurityException("exec", var1);
  50.       }
  51.    }
  52.  
  53.    public synchronized void checkLink(String var1) {
  54.       switch (((SecurityManager)this).classLoaderDepth()) {
  55.          case 2:
  56.          case 3:
  57.             throw new RMISecurityException("link", var1);
  58.          default:
  59.       }
  60.    }
  61.  
  62.    public synchronized void checkPropertiesAccess() {
  63.       if (((SecurityManager)this).classLoaderDepth() == 2) {
  64.          throw new RMISecurityException("properties");
  65.       }
  66.    }
  67.  
  68.    public synchronized void checkPropertyAccess(String var1) {
  69.       if (((SecurityManager)this).classLoaderDepth() == 2 && !"true".equalsIgnoreCase(System.getProperty(var1 + ".rmi"))) {
  70.          throw new RMISecurityException("properties");
  71.       }
  72.    }
  73.  
  74.    public synchronized void checkRead(String var1) {
  75.       if (this.inLoadedClass()) {
  76.          throw new RMISecurityException("file.read", var1);
  77.       }
  78.    }
  79.  
  80.    public void checkRead(String var1, Object var2) {
  81.       if (this.inLoadedClass()) {
  82.          throw new RMISecurityException("file.read", var1);
  83.       }
  84.    }
  85.  
  86.    public synchronized void checkWrite(String var1) {
  87.       if (this.inLoadedClass()) {
  88.          throw new RMISecurityException("file.write", var1);
  89.       }
  90.    }
  91.  
  92.    public void checkDelete(String var1) {
  93.       if (this.inLoadedClass()) {
  94.          throw new RMISecurityException("file.delete", var1);
  95.       }
  96.    }
  97.  
  98.    public synchronized void checkRead(FileDescriptor var1) {
  99.       if (this.inLoadedClass() && !((SecurityManager)this).inClass("java.net.SocketInputStream") || !var1.valid()) {
  100.          throw new RMISecurityException("fd.read");
  101.       }
  102.    }
  103.  
  104.    public synchronized void checkWrite(FileDescriptor var1) {
  105.       if (this.inLoadedClass() && !((SecurityManager)this).inClass("java.net.SocketOutputStream") || !var1.valid()) {
  106.          throw new RMISecurityException("fd.write");
  107.       }
  108.    }
  109.  
  110.    public synchronized void checkListen(int var1) {
  111.       if (this.inLoadedClass() && var1 != 0 && (var1 < 1024 || var1 > 65535)) {
  112.          throw new RMISecurityException("socket.listen", String.valueOf(var1));
  113.       }
  114.    }
  115.  
  116.    public synchronized void checkAccept(String var1, int var2) {
  117.       if (this.inLoadedClass()) {
  118.          throw new RMISecurityException("socket.accept", var1 + ":" + var2);
  119.       }
  120.    }
  121.  
  122.    public void checkMulticast(InetAddress var1) {
  123.       if (this.inLoadedClass()) {
  124.          throw new RMISecurityException("checkmulticast");
  125.       }
  126.    }
  127.  
  128.    public void checkMulticast(InetAddress var1, byte var2) {
  129.       if (this.inLoadedClass()) {
  130.          throw new RMISecurityException("checkmulticast");
  131.       }
  132.    }
  133.  
  134.    public synchronized void checkConnect(String var1, int var2) {
  135.       if (this.inLoadedClass()) {
  136.          int var3 = ((SecurityManager)this).classDepth("sun.rmi.transport.tcp.TCPChannel");
  137.          if (var3 <= 1) {
  138.             Object var4 = this.getSecurityContext();
  139.             if (var4 != null && var4 instanceof URL) {
  140.                this.checkConnect(((URL)var4).getHost(), var1);
  141.             } else {
  142.                throw new RMISecurityException("checkConnect", "To " + var1 + ":" + var2);
  143.             }
  144.          }
  145.       }
  146.    }
  147.  
  148.    private synchronized void checkConnect(String var1, String var2) {
  149.       try {
  150.          super.inCheck = true;
  151.          if (var1.equals(var2)) {
  152.             try {
  153.                InetAddress var13 = InetAddress.getByName(var2);
  154.                return;
  155.             } catch (UnknownHostException var10) {
  156.                throw new RMISecurityException("checkConnect", "To " + var2);
  157.             }
  158.          }
  159.  
  160.          try {
  161.             InetAddress var5 = InetAddress.getByName(var2);
  162.             InetAddress var6 = InetAddress.getByName(var1);
  163.             if (!var6.equals(var5)) {
  164.                throw new RMISecurityException("checkConnect", "To " + var2);
  165.             }
  166.          } catch (UnknownHostException var11) {
  167.             throw new RMISecurityException("checkConnect", "To " + var2);
  168.          }
  169.       } finally {
  170.          super.inCheck = false;
  171.       }
  172.  
  173.    }
  174.  
  175.    public void checkConnect(String var1, int var2, Object var3) {
  176.       this.checkConnect(var1, var2);
  177.       if (var3 != null) {
  178.          if (var3 instanceof URL) {
  179.             this.checkConnect(((URL)var3).getHost(), var1);
  180.          } else {
  181.             throw new RMISecurityException("checkConnect (unknown context)", "To " + var1);
  182.          }
  183.       }
  184.    }
  185.  
  186.    public synchronized boolean checkTopLevelWindow(Object var1) {
  187.       return !this.inLoadedClass();
  188.    }
  189.  
  190.    public synchronized void checkPackageAccess(String var1) {
  191.       if (this.inLoadedClass()) {
  192.          for(int var2 = var1.indexOf(46); var2 > 0; var2 = var1.indexOf(46, var2 + 1)) {
  193.             String var3 = var1.substring(0, var2);
  194.             if (Boolean.getBoolean("package.restrict.access." + var3)) {
  195.                throw new RMISecurityException("checkpackageaccess", var1);
  196.             }
  197.          }
  198.  
  199.       }
  200.    }
  201.  
  202.    public synchronized void checkPackageDefinition(String var1) {
  203.       if (this.inLoadedClass()) {
  204.          for(int var2 = var1.indexOf(46); var2 > 0; var2 = var1.indexOf(46, var2 + 1)) {
  205.             String var3 = var1.substring(0, var2);
  206.             if (Boolean.getBoolean("package.restrict.definition." + var3)) {
  207.                throw new RMISecurityException("checkpackagedefinition", var1);
  208.             }
  209.          }
  210.  
  211.       }
  212.    }
  213.  
  214.    public synchronized void checkSetFactory() {
  215.       if (this.inLoadedClass()) {
  216.          throw new RMISecurityException("cannotsetfactory");
  217.       }
  218.    }
  219.  
  220.    public void checkPrintJobAccess() {
  221.       if (this.inLoadedClass()) {
  222.          throw new RMISecurityException("getPrintJob");
  223.       }
  224.    }
  225.  
  226.    public void checkSystemClipboardAccess() {
  227.       if (this.inLoadedClass()) {
  228.          throw new RMISecurityException("checksystemclipboardaccess");
  229.       }
  230.    }
  231.  
  232.    public void checkAwtEventQueueAccess() {
  233.       if (this.inLoadedClass()) {
  234.          throw new RMISecurityException("checkawteventqueueaccess");
  235.       }
  236.    }
  237.  
  238.    public void checkMemberAccess(Class var1, int var2) {
  239.       if (var2 != 0) {
  240.          ClassLoader var3 = ((SecurityManager)this).currentClassLoader();
  241.          if (var3 != null && var3 != var1.getClassLoader()) {
  242.             throw new RMISecurityException("checkmemberaccess");
  243.          }
  244.       }
  245.  
  246.    }
  247.  
  248.    public void checkSecurityAccess(String var1) {
  249.       if (this.inLoadedClass()) {
  250.          throw new RMISecurityException("checksecurityaccess", var1);
  251.       }
  252.    }
  253. }
  254.