1 package club.wpia.gigi.api;
3 import java.io.IOException;
4 import java.math.BigInteger;
5 import java.security.cert.X509Certificate;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
10 import club.wpia.gigi.dbObjects.Certificate;
11 import club.wpia.gigi.dbObjects.CertificateOwner;
12 import club.wpia.gigi.dbObjects.User;
13 import club.wpia.gigi.pages.LoginPage;
15 public abstract class APIPoint {
17 public void process(HttpServletRequest req, HttpServletResponse resp) throws IOException {
18 X509Certificate cert = LoginPage.getCertificateFromRequest(req);
20 resp.sendError(403, "Error, cert authing required. No cert found.");
23 BigInteger serial = LoginPage.extractSerialFormCert(cert);
24 Certificate clientCert = Certificate.getBySerial(serial);
25 CertificateOwner u = CertificateOwner.getByEnabledSerial(serial);
26 if (u == null || clientCert == null) {
27 resp.sendError(403, "Error, cert authing required. Serial not found: " + serial);
30 if (req.getMethod().equals("GET")) {
31 if (u instanceof User) {
32 processGet(req, resp, (User) u);
35 resp.sendError(500, "Error, requires a User certificate.");
40 if ( !req.getMethod().equals("POST")) {
41 resp.sendError(500, "Error, POST required.");
44 if (req.getQueryString() != null) {
45 resp.sendError(500, "Error, no query String allowed.");
48 process(req, resp, u, clientCert);
51 protected void process(HttpServletRequest req, HttpServletResponse resp, CertificateOwner u, Certificate clientCert) throws IOException {
52 process(req, resp, u);
55 protected void process(HttpServletRequest req, HttpServletResponse resp, CertificateOwner u) throws IOException {
56 if (u instanceof User) {
57 process(req, resp, (User) u);
59 resp.sendError(500, "Error, requires a User certificate.");
64 protected void process(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
65 resp.sendError(500, "Error, Post not allowed.");
68 protected void processGet(HttpServletRequest req, HttpServletResponse resp, User u) throws IOException {
69 resp.sendError(500, "Error, Get not allowed.");