]> WPIA git - gigi.git/blob - src/org/cacert/gigi/api/CATSResolve.java
fix: restrict access to CATS-API even more
[gigi.git] / src / org / cacert / gigi / api / CATSResolve.java
1 package org.cacert.gigi.api;
2
3 import java.io.IOException;
4
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
8 import org.cacert.gigi.dbObjects.Certificate;
9 import org.cacert.gigi.dbObjects.CertificateOwner;
10 import org.cacert.gigi.dbObjects.User;
11
12 public class CATSResolve extends CATSRestrictedApi {
13
14     public static final String PATH = "/cats/resolve";
15
16     @Override
17     public void processAuthenticated(HttpServletRequest req, HttpServletResponse resp) throws IOException {
18         String target = req.getParameter("serial");
19         if (target == null) {
20             resp.sendError(500, "Error, requires a serial parameter");
21             return;
22         }
23         target = target.toLowerCase();
24         Certificate clientCert = Certificate.getBySerial(target);
25         if (clientCert == null) {
26             resp.sendError(500, "Error, requires valid serial");
27             return;
28         }
29         CertificateOwner o = CertificateOwner.getByEnabledSerial(target);
30         if ( !(o instanceof User)) {
31             resp.sendError(500, "Error, requires valid serial");
32             return;
33         }
34         resp.setContentType("text/plain; charset=UTF-8");
35         resp.getWriter().print(o.getId());
36     }
37 }