home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / security / Identity.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.2 KB  |  204 lines

  1. package java.security;
  2.  
  3. import java.io.Serializable;
  4. import java.util.Arrays;
  5. import java.util.Enumeration;
  6. import java.util.Vector;
  7.  
  8. public abstract class Identity implements Principal, Serializable {
  9.    private static final long serialVersionUID = 3609922007826600659L;
  10.    private String name;
  11.    private PublicKey publicKey;
  12.    String info;
  13.    IdentityScope scope;
  14.    Vector certificates;
  15.  
  16.    protected Identity() {
  17.       this("restoring...");
  18.    }
  19.  
  20.    public Identity(String var1, IdentityScope var2) throws KeyManagementException {
  21.       this(var1);
  22.       if (var2 != null) {
  23.          var2.addIdentity(this);
  24.       }
  25.  
  26.       this.scope = var2;
  27.    }
  28.  
  29.    public Identity(String var1) {
  30.       this.info = "No further information available.";
  31.       this.name = var1;
  32.    }
  33.  
  34.    public final String getName() {
  35.       return this.name;
  36.    }
  37.  
  38.    public final IdentityScope getScope() {
  39.       return this.scope;
  40.    }
  41.  
  42.    public PublicKey getPublicKey() {
  43.       return this.publicKey;
  44.    }
  45.  
  46.    public void setPublicKey(PublicKey var1) throws KeyManagementException {
  47.       check("setIdentityPublicKey");
  48.       this.publicKey = var1;
  49.       this.certificates = new Vector();
  50.    }
  51.  
  52.    public void setInfo(String var1) {
  53.       check("setIdentityInfo");
  54.       this.info = var1;
  55.    }
  56.  
  57.    public String getInfo() {
  58.       return this.info;
  59.    }
  60.  
  61.    public void addCertificate(Certificate var1) throws KeyManagementException {
  62.       check("addIdentityCertificate");
  63.       if (this.certificates == null) {
  64.          this.certificates = new Vector();
  65.       }
  66.  
  67.       if (this.publicKey != null) {
  68.          if (!this.keyEquals(this.publicKey, var1.getPublicKey())) {
  69.             throw new KeyManagementException("public key different from cert public key");
  70.          }
  71.       } else {
  72.          this.publicKey = var1.getPublicKey();
  73.       }
  74.  
  75.       this.certificates.addElement(var1);
  76.    }
  77.  
  78.    private boolean keyEquals(Key var1, Key var2) {
  79.       String var3 = var1.getFormat();
  80.       String var4 = var2.getFormat();
  81.       if (var3 == null ^ var4 == null) {
  82.          return false;
  83.       } else {
  84.          return var3 != null && var4 != null && !var3.equalsIgnoreCase(var4) ? false : Arrays.equals(var1.getEncoded(), var2.getEncoded());
  85.       }
  86.    }
  87.  
  88.    public void removeCertificate(Certificate var1) throws KeyManagementException {
  89.       check("removeIdentityCertificate");
  90.       if (this.certificates != null) {
  91.          this.certificates.removeElement(var1);
  92.       }
  93.  
  94.    }
  95.  
  96.    public Certificate[] certificates() {
  97.       if (this.certificates == null) {
  98.          return new Certificate[0];
  99.       } else {
  100.          int var1 = this.certificates.size();
  101.          Certificate[] var2 = new Certificate[var1];
  102.          this.certificates.copyInto(var2);
  103.          return var2;
  104.       }
  105.    }
  106.  
  107.    public final boolean equals(Object var1) {
  108.       if (var1 == this) {
  109.          return true;
  110.       } else if (var1 instanceof Identity) {
  111.          Identity var2 = (Identity)var1;
  112.          return this.fullName().equals(var2.fullName()) ? true : this.identityEquals(var2);
  113.       } else {
  114.          return false;
  115.       }
  116.    }
  117.  
  118.    protected boolean identityEquals(Identity var1) {
  119.       if (!this.name.equalsIgnoreCase(var1.name)) {
  120.          return false;
  121.       } else if (this.publicKey == null ^ var1.publicKey == null) {
  122.          return false;
  123.       } else {
  124.          return this.publicKey == null || var1.publicKey == null || this.publicKey.equals(var1.publicKey);
  125.       }
  126.    }
  127.  
  128.    String fullName() {
  129.       String var1 = this.name;
  130.       if (this.scope != null) {
  131.          var1 = var1 + "." + this.scope.getName();
  132.       }
  133.  
  134.       return var1;
  135.    }
  136.  
  137.    public String toString() {
  138.       check("printIdentity");
  139.       String var1 = this.name;
  140.       if (this.scope != null) {
  141.          var1 = var1 + "[" + this.scope.getName() + "]";
  142.       }
  143.  
  144.       return var1;
  145.    }
  146.  
  147.    public String toString(boolean var1) {
  148.       String var2 = this.toString();
  149.       if (var1) {
  150.          var2 = var2 + "\n";
  151.          var2 = var2 + this.printKeys();
  152.          var2 = var2 + "\n" + this.printCertificates();
  153.          if (this.info != null) {
  154.             var2 = var2 + "\n\t" + this.info;
  155.          } else {
  156.             var2 = var2 + "\n\tno additional information available.";
  157.          }
  158.       }
  159.  
  160.       return var2;
  161.    }
  162.  
  163.    String printKeys() {
  164.       String var1 = "";
  165.       if (this.publicKey != null) {
  166.          var1 = "\tpublic key initialized";
  167.       } else {
  168.          var1 = "\tno public key";
  169.       }
  170.  
  171.       return var1;
  172.    }
  173.  
  174.    String printCertificates() {
  175.       String var1 = "";
  176.       if (this.certificates == null) {
  177.          return "\tno certificates";
  178.       } else {
  179.          var1 = var1 + "\tcertificates: \n";
  180.          Enumeration var2 = this.certificates.elements();
  181.  
  182.          Certificate var4;
  183.          for(int var3 = 1; var2.hasMoreElements(); var1 = var1 + "\t\t\tfrom : " + var4.getGuarantor() + "\n") {
  184.             var4 = (Certificate)var2.nextElement();
  185.             var1 = var1 + "\tcertificate " + var3++ + "\tfor  : " + var4.getPrincipal() + "\n";
  186.          }
  187.  
  188.          return var1;
  189.       }
  190.    }
  191.  
  192.    public int hashCode() {
  193.       return this.name.hashCode();
  194.    }
  195.  
  196.    private static void check(String var0) {
  197.       SecurityManager var1 = System.getSecurityManager();
  198.       if (var1 != null) {
  199.          var1.checkSecurityAccess(var0);
  200.       }
  201.  
  202.    }
  203. }
  204.