]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.java
ADD: SE certificate revoke
[gigi.git] / src / org / cacert / gigi / pages / admin / support / SupportRevokeCertificatesForm.java
1 package org.cacert.gigi.pages.admin.support;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.security.GeneralSecurityException;
6 import java.util.Date;
7 import java.util.Map;
8
9 import javax.servlet.http.HttpServletRequest;
10
11 import org.cacert.gigi.GigiApiException;
12 import org.cacert.gigi.dbObjects.Certificate;
13 import org.cacert.gigi.dbObjects.CertificateProfile;
14 import org.cacert.gigi.dbObjects.SupportedUser;
15 import org.cacert.gigi.localisation.Language;
16 import org.cacert.gigi.output.DateSelector;
17 import org.cacert.gigi.output.template.Form;
18 import org.cacert.gigi.output.template.IterableDataset;
19 import org.cacert.gigi.output.template.Template;
20
21 public class SupportRevokeCertificatesForm extends Form {
22
23     private static Template t;
24
25     private SupportedUser user;
26     static {
27         t = new Template(SupportRevokeCertificatesForm.class.getResource("SupportRevokeCertificatesForm.templ"));
28     }
29
30     public SupportRevokeCertificatesForm(HttpServletRequest hsr, SupportedUser user) {
31         super(hsr);
32         this.user = user;
33     }
34
35     @Override
36     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
37         if (user.getTicket() != null) {
38             user.revokeAllCertificates();
39             return true;
40         }
41         return false;
42     }
43
44     @Override
45     protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
46         final Certificate[] certs = user.getCertificates(true);
47         final CertificateProfile[] profiles = CertificateProfile.getAll();
48         vars.put("types", new IterableDataset() {
49
50             int typeIndex = 0;
51
52             @Override
53             public boolean next(Language l, Map<String, Object> vars) {
54                 if (typeIndex > profiles.length - 1) {
55                     return false;
56                 }
57                 int valid = 0;
58                 int total = 0;
59                 long lastExpire = Long.MIN_VALUE;
60                 for (int i = 0; i < certs.length; i++) {
61                     try {
62                         if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) {
63                             continue;
64                         }
65                         total++;
66                         certs[i].cert().checkValidity();
67                         lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime());
68                         valid++;
69                     } catch (GeneralSecurityException | IOException e) {
70                         continue;
71                     }
72                 }
73                 vars.put("total", total);
74                 vars.put("profile", profiles[typeIndex].getVisibleName());
75                 vars.put("valid", valid);
76                 vars.put("exp", total - valid);
77                 vars.put("rev", "TODO");
78                 if (lastExpire == Long.MIN_VALUE) {
79                     vars.put("lastdate", "-");
80                 } else {
81                     vars.put("lastdate", DateSelector.getDateFormat().format(new Date(lastExpire)));
82                 }
83                 typeIndex++;
84                 return true;
85             }
86         });
87         t.output(out, l, vars);
88     }
89
90 }