1 package org.cacert.gigi.pages.admin.support;
3 import java.io.IOException;
4 import java.util.HashMap;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
11 import org.cacert.gigi.dbObjects.Certificate;
12 import org.cacert.gigi.dbObjects.Certificate.SubjectAlternateName;
13 import org.cacert.gigi.localisation.Language;
14 import org.cacert.gigi.output.ArrayIterable;
15 import org.cacert.gigi.output.template.Form;
16 import org.cacert.gigi.output.template.IterableDataset;
17 import org.cacert.gigi.output.template.SprintfCommand;
18 import org.cacert.gigi.pages.LoginPage;
19 import org.cacert.gigi.pages.Page;
20 import org.cacert.gigi.pages.account.certs.Certificates;
21 import org.cacert.gigi.util.AuthorizationContext;
23 public class FindCertPage extends Page {
25 public static final String PATH = "/support/find/certs";
27 public FindCertPage() {
28 super("Find Certificate");
32 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
33 new FindCertForm(req).output(resp.getWriter(), Page.getLanguage(req), new HashMap<String, Object>());
37 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
38 FindCertForm form = Form.getForm(req, FindCertForm.class);
39 if (form.submitProtected(resp.getWriter(), req)) {
40 final Certificate[] certs = form.getCerts();
41 if (certs.length == 1) {
42 resp.sendRedirect(Certificates.SUPPORT_PATH + "/" + certs[0].getSerial());
44 HashMap<String, Object> vars = new HashMap<String, Object>();
45 Language l = LoginPage.getLanguage(req);
46 if (certs.length >= 100) {
47 vars.put("limit", l.getTranslation("100 or more entries available, only the first 100 are displayed."));
49 vars.put("limit", SprintfCommand.createSimple("{0} entries found", certs.length));
51 vars.put("certtable", new ArrayIterable<Certificate>(certs) {
54 public void apply(Certificate t, Language l, Map<String, Object> vars) {
55 vars.put("id", t.getId());
56 vars.put("serial", t.getSerial());
58 final List<SubjectAlternateName> san = t.getSANs();
59 vars.put("san", new IterableDataset() {
64 public boolean next(Language l, Map<String, Object> vars) {
65 if (j == san.size()) {
68 vars.put("entry", san.get(j).getName() + (j < san.size() - 1 ? ", " : ""));
76 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
82 public boolean isPermitted(AuthorizationContext ac) {
83 return ac != null && ac.canSupport();