home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / security / Identity.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  4.9 KB  |  195 lines

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