]> WPIA git - gigi.git/blob - src/org/cacert/gigi/api/APIPoint.java
684729123a8ed4b9230cd6c4810a305d3756201e
[gigi.git] / src / org / cacert / gigi / api / APIPoint.java
1 package org.cacert.gigi.api;
2
3 import java.io.IOException;
4 import java.security.cert.X509Certificate;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.cacert.gigi.dbObjects.CertificateOwner;
10 import org.cacert.gigi.dbObjects.User;
11 import org.cacert.gigi.pages.LoginPage;
12
13 public abstract class APIPoint {
14
15     public void process(HttpServletRequest req, HttpServletResponse resp) throws IOException {
16         X509Certificate cert = LoginPage.getCertificateFromRequest(req);
17         if (cert == null) {
18             resp.sendError(403, "Error, cert authing required. No cert found.");
19             return;
20         }
21         String serial = LoginPage.extractSerialFormCert(cert);
22         CertificateOwner u = CertificateOwner.getByEnabledSerial(serial);
23         if (u == null) {
24             resp.sendError(403, "Error, cert authing required. Serial not found: " + serial);
25             return;
26         }
27
28         if ( !req.getMethod().equals("POST")) {
29             resp.sendError(500, "Error, POST required.");
30             return;
31         }
32         if (req.getQueryString() != null) {
33             resp.sendError(500, "Error, no query String allowed.");
34             return;
35         }
36         process(req, resp, u);
37     }
38
39     protected void process(HttpServletRequest req, HttpServletResponse resp, CertificateOwner u) throws IOException {
40         if (u instanceof User) {
41             process(req, resp, (User) u);
42         } else {
43             resp.sendError(500, "Error, requires a User certificate.");
44             return;
45         }
46     }
47
48     protected void process(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
49
50     }
51 }