home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Internet / Java / networking / security / example / PasswordSecurityManager.class (.txt) < prev    next >
Encoding:
Java Class File  |  1978-03-06  |  1.4 KB  |  54 lines

  1. import java.io.DataInputStream;
  2. import java.io.FileDescriptor;
  3. import java.io.IOException;
  4.  
  5. class PasswordSecurityManager extends SecurityManager {
  6.    private String password;
  7.  
  8.    PasswordSecurityManager(String var1) {
  9.       this.password = var1;
  10.    }
  11.  
  12.    private boolean accessOK() {
  13.       DataInputStream var1 = new DataInputStream(System.in);
  14.       System.out.println("What's the secret password?");
  15.  
  16.       try {
  17.          String var2 = var1.readLine();
  18.          return var2.equals(this.password);
  19.       } catch (IOException var3) {
  20.          return false;
  21.       }
  22.    }
  23.  
  24.    public void checkRead(FileDescriptor var1) {
  25.       if (!this.accessOK()) {
  26.          throw new SecurityException("Not a Chance!");
  27.       }
  28.    }
  29.  
  30.    public void checkRead(String var1) {
  31.       if (!this.accessOK()) {
  32.          throw new SecurityException("No Way!");
  33.       }
  34.    }
  35.  
  36.    public void checkRead(String var1, Object var2) {
  37.       if (!this.accessOK()) {
  38.          throw new SecurityException("Forget It!");
  39.       }
  40.    }
  41.  
  42.    public void checkWrite(FileDescriptor var1) {
  43.       if (!this.accessOK()) {
  44.          throw new SecurityException("Not!");
  45.       }
  46.    }
  47.  
  48.    public void checkWrite(String var1) {
  49.       if (!this.accessOK()) {
  50.          throw new SecurityException("Not Even!");
  51.       }
  52.    }
  53. }
  54.