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.CertificateProfile;
14 import org.cacert.gigi.dbObjects.SupportedUser;
15 import org.cacert.gigi.localisation.Language;
16 import org.cacert.gigi.output.template.Form;
17 import org.cacert.gigi.output.template.IterableDataset;
18 import org.cacert.gigi.output.template.Template;
20 public class SupportRevokeCertificatesForm extends Form {
22 private static Template t;
24 private SupportedUser user;
26 t = new Template(SupportRevokeCertificatesForm.class.getResource("SupportRevokeCertificatesForm.templ"));
29 public SupportRevokeCertificatesForm(HttpServletRequest hsr, SupportedUser user) {
35 public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
36 if (user.getTicket() != null) {
37 user.revokeAllCertificates();
44 protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
45 final Certificate[] certs = user.getCertificates(true);
46 final CertificateProfile[] profiles = CertificateProfile.getAll();
47 vars.put("types", new IterableDataset() {
52 public boolean next(Language l, Map<String, Object> vars) {
53 if (typeIndex > profiles.length - 1) {
58 long lastExpire = Long.MIN_VALUE;
59 for (int i = 0; i < certs.length; i++) {
61 if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) {
65 certs[i].cert().checkValidity();
66 lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime());
68 } catch (GeneralSecurityException | IOException e) {
72 vars.put("total", total);
73 vars.put("profile", profiles[typeIndex].getVisibleName());
74 vars.put("valid", valid);
75 vars.put("exp", total - valid);
76 vars.put("rev", "TODO");
77 if (lastExpire == Long.MIN_VALUE) {
78 vars.put("lastdate", "-");
80 vars.put("lastdate", new Date(lastExpire));
86 t.output(out, l, vars);