View Javadoc
1 package jsdsi; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import jsdsi.sexp.Sexp; 7 import jsdsi.sexp.SexpList; 8 import jsdsi.sexp.SexpUtil; 9 10 /*** 11 * A SPKI authorization certificate: conveys a permission (the Tag) from 12 * the issuer to the subject. If the propagate flag is set, the subject 13 * can further delegate the permission. 14 * 15 * @see Cert 16 * 17 * @author Sameer Ajmani 18 * @author Sean Radford 19 * @version $Revision: 1.5.2.1 $ $Date 20 */ 21 public class AuthCert extends Cert { 22 23 private static final long serialVersionUID = -5588350360041330506L; 24 25 /*** 26 * The authorization of this <code>AuthCert</code>. 27 */ 28 private transient final Auth auth; 29 30 /*** 31 * Creates a new <code>AuthCert</code> from a given principal, subject, 32 * validity, display-string, comment, tag, and delegation bit. 33 * 34 * @param i principal of this <code>AuthCert</code>. 35 * @param s subject of this <code>AuthCert</code>. 36 * @param v validity of this <code>AuthCert</code>. 37 * @param d display-string of this <code>AuthCert</code>. 38 * @param c comment of this <code>AuthCert</code>. 39 * @param t tag of this <code>AuthCert</code>. 40 * @param p delegation bit of this <code>AuthCert</code>. 41 */ 42 public AuthCert( 43 Principal i, 44 Subject s, 45 Validity v, 46 String d, 47 String c, 48 Tag t, 49 boolean p) { 50 super(i, s, v, d, c); 51 assert(t != null) : "null tag"; 52 auth = new Auth(t, p); 53 } 54 55 /*** 56 * @return the tag of this <code>AuthCert</code>. 57 */ 58 public Tag getTag() { 59 return auth.getTag(); 60 } 61 62 /*** 63 * @return the delegation bit of this <code>AuthCert</code>. 64 */ 65 public boolean getPropagate() { 66 return auth.getPropagate(); 67 } 68 69 Auth getAuth() { 70 return auth; 71 } 72 73 /*** 74 * @see java.lang.Object#equals(Object) 75 */ 76 public boolean equals(Object o) { 77 if (o instanceof AuthCert) { 78 AuthCert a = (AuthCert) o; 79 return auth.equals(a.auth) && super.equals(o); 80 } 81 return false; 82 } 83 84 /*** 85 * @return true iff this is at least as strong as c 86 */ 87 public boolean implies(Cert c) { 88 return (c instanceof AuthCert) 89 && auth.implies(((AuthCert)c).auth) 90 && super.implies(c); 91 } 92 93 /*** 94 * @see java.lang.Object#hashCode() 95 */ 96 public int hashCode() { 97 return auth.hashCode() ^ super.hashCode(); 98 } 99 100 /*** 101 * Returns an <code>SexpList</code> that represents this 102 * <code>AuthCert</code>. 103 * 104 * @return an <code>SexpList</code> that represents this 105 * <code>AuthCert</code>. 106 */ 107 public SexpList toSexp() { 108 List l = new ArrayList(7); 109 110 // display-hint 111 String display = this.getDisplay(); 112 if (display != null && !display.equals("")) { 113 l.add( SexpUtil.toSexpDisplayHint(display) ); 114 } 115 116 // issuer block 117 Sexp[] is = new Sexp[1]; 118 is[0] = getIssuer().toSexp(); 119 l.add(SexpUtil.toSexp("issuer", is)); 120 121 // subject block 122 Sexp[] ss = new Sexp[1]; 123 // FIXME: can we eliminate these downcasts? 124 if (getSubject() instanceof Name) { 125 // tell name about issuer 126 ss[0] = ((Name) getSubject()).toSexp(getIssuer()); 127 } else if (getSubject() instanceof Threshold) { 128 // tell nested names about issuer 129 ss[0] = ((Threshold) getSubject()).toSexp(getIssuer()); 130 } else { 131 ss[0] = getSubject().toSexp(); 132 } 133 l.add(SexpUtil.toSexp("subject", ss)); 134 135 // auth block 136 if (getPropagate()) { 137 l.add(SexpUtil.toSexpList("propagate")); 138 } 139 l.add(getTag().toSexp()); 140 141 if (getValidity() != null) { 142 l.add(getValidity().toSexp()); 143 } 144 if (getComment() != null) { 145 l.add(SexpUtil.toSexpComment(getComment())); 146 } 147 return SexpUtil.toSexp("cert", l); 148 } 149 }

This page was automatically generated by Maven