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