1 package org.cacert.gigi.pages.admin.support;
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.security.GeneralSecurityException;
9 import javax.servlet.http.HttpServletRequest;
11 import org.cacert.gigi.GigiApiException;
12 import org.cacert.gigi.dbObjects.Certificate;
13 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
14 import org.cacert.gigi.dbObjects.CertificateProfile;
15 import org.cacert.gigi.dbObjects.SupportedUser;
16 import org.cacert.gigi.localisation.Language;
17 import org.cacert.gigi.output.template.Form;
18 import org.cacert.gigi.output.template.IterableDataset;
19 import org.cacert.gigi.output.template.Template;
21 public class SupportRevokeCertificatesForm extends Form {
23 private static Template t;
25 private SupportedUser user;
27 t = new Template(SupportRevokeCertificatesForm.class.getResource("SupportRevokeCertificatesForm.templ"));
30 public SupportRevokeCertificatesForm(HttpServletRequest hsr, SupportedUser user) {
36 public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
37 if (user.getTicket() != null) {
38 user.revokeAllCertificates();
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() {
53 public boolean next(Language l, Map<String, Object> vars) {
54 if (typeIndex > profiles.length - 1) {
60 long lastExpire = Long.MIN_VALUE;
61 for (int i = 0; i < certs.length; i++) {
63 if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) {
67 if (certs[i].getStatus() == CertificateStatus.DRAFT) {
70 if (certs[i].getStatus() == CertificateStatus.REVOKED) {
74 certs[i].cert().checkValidity();
75 lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime());
77 } catch (GeneralSecurityException | IOException e) {
81 vars.put("total", total);
82 vars.put("profile", profiles[typeIndex].getVisibleName());
83 vars.put("valid", valid);
84 vars.put("exp", total - valid);
85 vars.put("rev", revoked);
86 if (lastExpire == Long.MIN_VALUE) {
87 vars.put("lastdate", "-");
89 vars.put("lastdate", new Date(lastExpire));
95 t.output(out, l, vars);