]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Certificate.java
fix: several testcases to the new configuration/structure
[gigi.git] / src / org / cacert / gigi / dbObjects / Certificate.java
index 6882b8113018c4c41af40bf54f5844f176a9878b..ada9ca90f2f589e6e075423c9e2e606a398aa6af 100644 (file)
@@ -132,8 +132,10 @@ public class Certificate {
 
     private String dnString;
 
+    private CACertificate ca;
+
     public Certificate(User owner, HashMap<String, String> dn, String md, String csr, CSRType csrType, CertificateProfile profile, SubjectAlternateName... sans) throws GigiApiException {
-        if ( !owner.canIssue(profile)) {
+        if ( !profile.canBeIssuedBy(owner)) {
             throw new GigiApiException("You are not allowed to issue these certificates.");
         }
         this.owner = owner;
@@ -210,7 +212,7 @@ public class Certificate {
         if (id == 0) {
             return CertificateStatus.DRAFT;
         }
-        GigiPreparedStatement searcher = DatabaseConnection.getInstance().prepare("SELECT crt_name, created, revoked, serial FROM certs WHERE id=?");
+        GigiPreparedStatement searcher = DatabaseConnection.getInstance().prepare("SELECT crt_name, created, revoked, serial, caid FROM certs WHERE id=?");
         searcher.setInt(1, id);
         GigiResultSet rs = searcher.executeQuery();
         if ( !rs.next()) {
@@ -222,6 +224,7 @@ public class Certificate {
         if (rs.getTimestamp(2) == null) {
             return CertificateStatus.DRAFT;
         }
+        ca = CACertificate.getById(rs.getInt("caid"));
         if (rs.getTimestamp(2) != null && rs.getTimestamp(3) == null) {
             return CertificateStatus.ISSUED;
         }
@@ -293,6 +296,14 @@ public class Certificate {
 
     }
 
+    public CACertificate getParent() {
+        CertificateStatus status = getStatus();
+        if (status != CertificateStatus.REVOKED && status != CertificateStatus.ISSUED) {
+            throw new IllegalStateException(status + " is not wanted here.");
+        }
+        return ca;
+    }
+
     public X509Certificate cert() throws IOException, GeneralSecurityException {
         CertificateStatus status = getStatus();
         if (status != CertificateStatus.REVOKED && status != CertificateStatus.ISSUED) {