]> WPIA git - gigi.git/blob - src/club/wpia/gigi/api/RevokeCertificate.java
upd: rename package name and all references to it
[gigi.git] / src / club / wpia / gigi / api / RevokeCertificate.java
1 package club.wpia.gigi.api;
2
3 import java.io.IOException;
4
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
8 import club.wpia.gigi.dbObjects.Certificate;
9 import club.wpia.gigi.dbObjects.Job;
10 import club.wpia.gigi.dbObjects.User;
11 import club.wpia.gigi.dbObjects.Certificate.CertificateStatus;
12
13 public class RevokeCertificate extends APIPoint {
14
15     public static final String PATH = "/account/certs/revoke";
16
17     @Override
18     public void process(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
19
20         if ( !req.getMethod().equals("POST")) {
21             resp.sendError(500, "Error, POST required.");
22             return;
23         }
24
25         if (req.getQueryString() != null) {
26             resp.sendError(500, "Error, no query String allowed.");
27             return;
28         }
29
30         String tserial = req.getParameter("serial");
31         if (tserial == null) {
32             resp.sendError(500, "Error, no Serial found");
33             return;
34         }
35
36         Certificate c = Certificate.getBySerial(tserial);
37         if (c == null || c.getOwner() != u) {
38             resp.sendError(403, "Access Denied");
39             return;
40         }
41
42         Job job = c.revoke();
43         job.waitFor(60000);
44         if (c.getStatus() != CertificateStatus.REVOKED) {
45             resp.sendError(510, "Error, issuing timed out");
46             return;
47         }
48
49         resp.getWriter().println("OK");
50
51     }
52 }