1 package org.cacert.gigi.pages.admin.support;
3 import java.io.PrintWriter;
6 import javax.servlet.http.HttpServletRequest;
8 import org.cacert.gigi.GigiApiException;
9 import org.cacert.gigi.dbObjects.Certificate;
10 import org.cacert.gigi.dbObjects.Certificate.SANType;
11 import org.cacert.gigi.localisation.Language;
12 import org.cacert.gigi.output.template.Form;
13 import org.cacert.gigi.output.template.SprintfCommand;
14 import org.cacert.gigi.output.template.Template;
16 public class FindCertForm extends Form {
18 public static class FindResult extends SuccessMessageResult {
20 private final Certificate[] certs;
22 public FindResult(Certificate[] certs) {
27 public Certificate[] getCerts() {
32 private static final Template t = new Template(FindCertForm.class.getResource("FindCertForm.templ"));
34 private final String SERIAL = "serial";
36 private String certType = SERIAL;
38 public Certificate certs[];
40 public FindCertForm(HttpServletRequest hsr) {
45 public SubmissionResult submit(HttpServletRequest req) throws GigiApiException {
46 this.certType = req.getParameter("certType");
47 String request = req.getParameter("cert").trim();
49 if ( !SERIAL.equals(certType) && !SANType.EMAIL.getOpensslName().equals(certType) && !SANType.DNS.getOpensslName().equals(certType)) {
50 throw new GigiApiException("Invalid search type.");
53 if (SERIAL.equals(certType)) {
54 certs = Certificate.findBySerialPattern(request);
55 if (certs.length <= 0) {
56 throw new GigiApiException(SprintfCommand.createSimple("No certificate found matching serial number {0}", request));
60 if (SANType.EMAIL.getOpensslName().equals(certType) || SANType.DNS.getOpensslName().equals(certType)) {
61 SANType stype = SANType.valueOf(certType.toUpperCase());
62 certs = Certificate.findBySANPattern(request, stype);
63 if (certs.length <= 0) {
64 throw new GigiApiException(SprintfCommand.createSimple("No certificate found matching {0}", request));
67 return new FindCertForm.FindResult(getCerts());
71 protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
72 vars.put("serial", !SERIAL.equals(certType) ? "" : "checked");
73 vars.put("email", !SANType.EMAIL.getOpensslName().equals(certType) ? "" : "checked");
74 vars.put("dns", !SANType.DNS.getOpensslName().equals(certType) ? "" : "checked");
76 t.output(out, l, vars);
79 public Certificate[] getCerts() {