1 package club.wpia.gigi.api;
3 import java.io.IOException;
4 import java.security.cert.X509Certificate;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
9 import club.wpia.gigi.dbObjects.Certificate;
10 import club.wpia.gigi.dbObjects.CertificateOwner;
11 import club.wpia.gigi.dbObjects.User;
12 import club.wpia.gigi.pages.LoginPage;
14 public abstract class APIPoint {
16 public void process(HttpServletRequest req, HttpServletResponse resp) throws IOException {
17 X509Certificate cert = LoginPage.getCertificateFromRequest(req);
19 resp.sendError(403, "Error, cert authing required. No cert found.");
22 String serial = LoginPage.extractSerialFormCert(cert);
23 Certificate clientCert = Certificate.getBySerial(serial);
24 CertificateOwner u = CertificateOwner.getByEnabledSerial(serial);
25 if (u == null || clientCert == null) {
26 resp.sendError(403, "Error, cert authing required. Serial not found: " + serial);
29 if (req.getMethod().equals("GET")) {
30 if (u instanceof User) {
31 processGet(req, resp, (User) u);
34 resp.sendError(500, "Error, requires a User certificate.");
39 if ( !req.getMethod().equals("POST")) {
40 resp.sendError(500, "Error, POST required.");
43 if (req.getQueryString() != null) {
44 resp.sendError(500, "Error, no query String allowed.");
47 process(req, resp, u, clientCert);
50 protected void process(HttpServletRequest req, HttpServletResponse resp, CertificateOwner u, Certificate clientCert) throws IOException {
51 process(req, resp, u);
54 protected void process(HttpServletRequest req, HttpServletResponse resp, CertificateOwner u) throws IOException {
55 if (u instanceof User) {
56 process(req, resp, (User) u);
58 resp.sendError(500, "Error, requires a User certificate.");
63 protected void process(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
64 resp.sendError(500, "Error, Post not allowed.");
67 protected void processGet(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
68 resp.sendError(500, "Error, Get not allowed.");