diff --git a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/AgentCertRequestServlet.java b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/AgentCertRequestServlet.java index 1acff8cee43..77fc1b70c8a 100644 --- a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/AgentCertRequestServlet.java +++ b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/AgentCertRequestServlet.java @@ -68,7 +68,7 @@ public class AgentCertRequestServlet extends CAServlet { private static final long serialVersionUID = 1L; private static Logger logger = LoggerFactory.getLogger(AgentCertRequestServlet.class); - @WebAction(method = HttpMethod.GET, paths = {"/"}) + @WebAction(method = HttpMethod.GET, paths = {""}) public void listRequests(HttpServletRequest request, HttpServletResponse response) throws Exception { PrintWriter out = response.getWriter(); int maxTime = request.getParameter("maxTime") == null ? @@ -88,7 +88,7 @@ public void listRequests(HttpServletRequest request, HttpServletResponse respons throw new PKIException(message, e); } } - @WebAction(method = HttpMethod.GET, paths = {"/{}"}) + @WebAction(method = HttpMethod.GET, paths = {"{}"}) public void reviewRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { RequestId id; try { @@ -111,8 +111,8 @@ public void reviewRequest(HttpServletRequest request, HttpServletResponse respon } @WebAction(method = HttpMethod.POST, paths = { - "/{}/approve", "/{}/reject", "/{}/cancel", - "/{}/update", "/{}/validate", "/{}/unassign", "/{}/assign"}) + "{}/approve", "{}/reject", "{}/cancel", + "{}/update", "{}/validate", "{}/unassign", "{}/assign"}) public void postRequestOperation(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("AgentCertRequestServlet.postRequestOperation(): session: {}", session.getId()); diff --git a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/AgentCertServlet.java b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/AgentCertServlet.java index 26ebfdf548a..f93d95a5e85 100644 --- a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/AgentCertServlet.java +++ b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/AgentCertServlet.java @@ -78,7 +78,7 @@ public class AgentCertServlet extends CAServlet{ private static final long serialVersionUID = 1L; private static Logger logger = LoggerFactory.getLogger(AgentCertServlet.class); - @WebAction(method = HttpMethod.GET, paths = { "/{}"}) + @WebAction(method = HttpMethod.GET, paths = { "{}"}) public void reviewCert(HttpServletRequest request, HttpServletResponse response) throws Exception { CertId id; try { @@ -100,21 +100,21 @@ public void reviewCert(HttpServletRequest request, HttpServletResponse response) } } - @WebAction(method = HttpMethod.POST, paths = { "/{}/revoke-ca"}) + @WebAction(method = HttpMethod.POST, paths = { "{}/revoke-ca"}) public void revokeCACert(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("AgentCertRequestServlet.revokeCACert(): session: {}", session.getId()); revoke(request, response, true); } - @WebAction(method = HttpMethod.POST, paths = { "/{}/revoke"}) + @WebAction(method = HttpMethod.POST, paths = { "{}/revoke"}) public void revokeCert(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("AgentCertRequestServlet.revokeCert(): session: {}", session.getId()); revoke(request, response, false); } - @WebAction(method = HttpMethod.POST, paths = { "/{}/unrevoke"}) + @WebAction(method = HttpMethod.POST, paths = { "{}/unrevoke"}) public void unrevokeCert(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("AgentCertRequestServlet.unrevokeCert(): session: {}", session.getId()); diff --git a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CAInfoServlet.java b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CAInfoServlet.java index 8b7809b9e2f..f3d51b42ca5 100644 --- a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CAInfoServlet.java +++ b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CAInfoServlet.java @@ -29,7 +29,7 @@ public class CAInfoServlet extends CAServlet { private static final long serialVersionUID = 1L; private static Logger logger = LoggerFactory.getLogger(CAInfoServlet.class); - @WebAction(method = HttpMethod.GET, paths = {"/"}) + @WebAction(method = HttpMethod.GET, paths = {""}) public void getInfo(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("CAInfoServlet.get(): session: {}", session.getId()); diff --git a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CertRequestServlet.java b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CertRequestServlet.java index 6fe062791ce..a2e67028ccd 100644 --- a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CertRequestServlet.java +++ b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CertRequestServlet.java @@ -68,7 +68,7 @@ public class CertRequestServlet extends CAServlet { private static final long serialVersionUID = 1L; private static Logger logger = LoggerFactory.getLogger(CertRequestServlet.class); - @WebAction(method = HttpMethod.GET, paths = {"/{}"}) + @WebAction(method = HttpMethod.GET, paths = {"{}"}) public void get(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("CertRequestServlet.get(): session: {}", session.getId()); @@ -93,7 +93,7 @@ public void get(HttpServletRequest request, HttpServletResponse response) throws out.println(info.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = {"/profiles/{}"}) + @WebAction(method = HttpMethod.GET, paths = {"profiles/{}"}) public void getEnrollmentTemplate(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); @@ -105,7 +105,7 @@ public void getEnrollmentTemplate(HttpServletRequest request, HttpServletRespons out.println(req.toJSON()); } - @WebAction(method = HttpMethod.POST, paths = {"/"}) + @WebAction(method = HttpMethod.POST, paths = {""}) public void enrollCert(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("CertServlet.enrollCert(): session: {}", session.getId()); diff --git a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CertServlet.java b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CertServlet.java index fb4dba4e074..fb70dd36698 100644 --- a/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CertServlet.java +++ b/base/ca/src/main/java/org/dogtagpki/server/ca/rest/v2/CertServlet.java @@ -67,7 +67,7 @@ public class CertServlet extends CAServlet { private static final long serialVersionUID = 1L; private static Logger logger = LoggerFactory.getLogger(CertServlet.class); - @WebAction(method = HttpMethod.GET, paths = { "/"}) + @WebAction(method = HttpMethod.GET, paths = {""}) public void listCerts(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("CertServlet.listCerts(): session: {}", session.getId()); @@ -84,7 +84,7 @@ public void listCerts(HttpServletRequest request, HttpServletResponse response) out.println(infos.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = { "/{}"}) + @WebAction(method = HttpMethod.GET, paths = {"{}"}) public void getCert(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("CertServlet.getCert(): session: {}", session.getId()); @@ -107,7 +107,7 @@ public void getCert(HttpServletRequest request, HttpServletResponse response) th } } - @WebAction(method = HttpMethod.POST, paths = { "/search"}) + @WebAction(method = HttpMethod.POST, paths = {"search"}) public void searchCerts(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("CertServlet.searchCerts(): session: {}", session.getId()); diff --git a/base/server/src/main/java/com/netscape/certsrv/base/WebAction.java b/base/server/src/main/java/com/netscape/certsrv/base/WebAction.java index 90299c3f786..a1d62d0aa2a 100644 --- a/base/server/src/main/java/com/netscape/certsrv/base/WebAction.java +++ b/base/server/src/main/java/com/netscape/certsrv/base/WebAction.java @@ -1,3 +1,8 @@ +// +// Copyright Red Hat, Inc. +// +// SPDX-License-Identifier: GPL-2.0-or-later +// package com.netscape.certsrv.base; import static java.lang.annotation.ElementType.METHOD; @@ -8,6 +13,17 @@ import org.dogtagpki.server.rest.v2.PKIServlet; +/** + * Implement basic routing for REST APIs + * + * If a servlet extends PKIServlet this annotation can specify the method to use for handle a + * specific REST API. It has two parameter associating the HTTP operation and the path to be + * handled by this method. The paths are relative and inside the servlet context. + * + * + * @see PKIServlet + * @author Marco Fargetta {@literal } + */ @Target(METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface WebAction { diff --git a/base/server/src/main/java/org/dogtagpki/server/rest/v2/AccountServlet.java b/base/server/src/main/java/org/dogtagpki/server/rest/v2/AccountServlet.java index 43fb92c64a8..62844e1e2d8 100644 --- a/base/server/src/main/java/org/dogtagpki/server/rest/v2/AccountServlet.java +++ b/base/server/src/main/java/org/dogtagpki/server/rest/v2/AccountServlet.java @@ -27,7 +27,7 @@ public class AccountServlet extends PKIServlet { private static final long serialVersionUID = 1L; public static final Logger logger = LoggerFactory.getLogger(AccountServlet.class); - @WebAction(method = HttpMethod.GET, paths = {"/login"}) + @WebAction(method = HttpMethod.GET, paths = {"login"}) public void login(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.info("AccountServlet: Creating session {}", session.getId()); @@ -36,7 +36,7 @@ public void login(HttpServletRequest request, HttpServletResponse response) thro PrintWriter out = response.getWriter(); out.println(account.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = {"/logout"}) + @WebAction(method = HttpMethod.GET, paths = {"logout"}) public void logout(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(false); if (session != null) { diff --git a/base/server/src/main/java/org/dogtagpki/server/rest/v2/JobServlet.java b/base/server/src/main/java/org/dogtagpki/server/rest/v2/JobServlet.java index b27dd34ba2c..e89a6e5768a 100644 --- a/base/server/src/main/java/org/dogtagpki/server/rest/v2/JobServlet.java +++ b/base/server/src/main/java/org/dogtagpki/server/rest/v2/JobServlet.java @@ -28,7 +28,7 @@ public class JobServlet extends PKIServlet { private static final long serialVersionUID = 1L; public static final Logger logger = LoggerFactory.getLogger(JobServlet.class); - @WebAction(method = HttpMethod.GET, paths = {"/"}) + @WebAction(method = HttpMethod.GET, paths = {""}) public void getJobs(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("JobServlet.getJobs(): session: {}", session.getId()); @@ -38,7 +38,7 @@ public void getJobs(HttpServletRequest request, HttpServletResponse response) th out.println(jobs.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = {"/{}"}) + @WebAction(method = HttpMethod.GET, paths = {"{}"}) public void getJob(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("JobServlet.getJob(): session: {}", session.getId()); @@ -50,7 +50,7 @@ public void getJob(HttpServletRequest request, HttpServletResponse response) thr out.println(job.toJSON()); } - @WebAction(method = HttpMethod.POST, paths = {"/{}/start"}) + @WebAction(method = HttpMethod.POST, paths = {"{}/start"}) public void postJobStart(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("JobServlet.postJobStart(): session: {}", session.getId()); diff --git a/base/server/src/main/java/org/dogtagpki/server/rest/v2/PKIServlet.java b/base/server/src/main/java/org/dogtagpki/server/rest/v2/PKIServlet.java index 06c399b60c1..433ab54cd32 100644 --- a/base/server/src/main/java/org/dogtagpki/server/rest/v2/PKIServlet.java +++ b/base/server/src/main/java/org/dogtagpki/server/rest/v2/PKIServlet.java @@ -44,6 +44,10 @@ /** * Implement the basic class to handle REST APIs + * + * API are routed to method in subclasses implementing specific actions annotated with WebAction + * + * @see WebAction * @author Marco Fargetta {@literal } */ public abstract class PKIServlet extends HttpServlet { @@ -178,9 +182,9 @@ private void doOperation(HttpMethod method, HttpServletRequest request, HttpServ public Method getActionMethod(HttpMethod met, String path) { final String reqMethod; if (path == null) { - reqMethod = met.toString() + ":/"; + reqMethod = met.toString() + ":"; } else { - reqMethod = met.toString() + ":" + path; + reqMethod = met.toString() + ":" + (path.startsWith("/") ? path.substring(1) : path); } String keyPath = webActions.keySet().stream(). filter( key -> { @@ -193,7 +197,12 @@ public Method getActionMethod(HttpMethod met, String path) { } public String getAllowedMethods(String path) { - final String matchingPath = path == null ? "/" : path; + final String matchingPath; + if (path == null) { + matchingPath = ""; + } else { + matchingPath = path.startsWith("/") ? path.substring(1) : path; + } List keyPaths = webActions.keySet().stream(). filter( key -> { String keyRegex = key.substring(key.indexOf(":") + 1); diff --git a/base/server/src/main/java/org/dogtagpki/server/rest/v2/SelfTestServlet.java b/base/server/src/main/java/org/dogtagpki/server/rest/v2/SelfTestServlet.java index 0943aa16dea..7442beb07d7 100644 --- a/base/server/src/main/java/org/dogtagpki/server/rest/v2/SelfTestServlet.java +++ b/base/server/src/main/java/org/dogtagpki/server/rest/v2/SelfTestServlet.java @@ -30,7 +30,7 @@ public class SelfTestServlet extends PKIServlet { private static final long serialVersionUID = 1L; public static final Logger logger = LoggerFactory.getLogger(SelfTestServlet.class); - @WebAction(method = HttpMethod.GET, paths = {"/"}) + @WebAction(method = HttpMethod.GET, paths = {""}) public void findTests(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("SelfTestServlet.findTests(): session: {}", session.getId()); @@ -44,7 +44,7 @@ public void findTests(HttpServletRequest request, HttpServletResponse response) out.println(tests.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = {"/{}"}) + @WebAction(method = HttpMethod.GET, paths = {"{}"}) public void getTest(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("SelfTestServlet.getTest(): session: {}", session.getId()); @@ -56,7 +56,7 @@ public void getTest(HttpServletRequest request, HttpServletResponse response) th out.println(test.toJSON()); } - @WebAction(method = HttpMethod.POST, paths = {"/"}) + @WebAction(method = HttpMethod.POST, paths = {""}) public void executeTests(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("SelfTestServlet.executeTests(): session: {}", session.getId()); @@ -66,7 +66,7 @@ public void executeTests(HttpServletRequest request, HttpServletResponse respons response.setStatus(HttpServletResponse.SC_NO_CONTENT); } - @WebAction(method = HttpMethod.POST, paths = {"/run"}) + @WebAction(method = HttpMethod.POST, paths = {"run"}) public void runTests(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("SelfTestServlet.runTests(): session: {}", session.getId()); @@ -77,7 +77,7 @@ public void runTests(HttpServletRequest request, HttpServletResponse response) t } - @WebAction(method = HttpMethod.POST, paths = {"/{}/run"}) + @WebAction(method = HttpMethod.POST, paths = {"{}/run"}) public void runTest(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("SelfTestServlet.runTest(): session: {}", session.getId()); diff --git a/base/server/src/main/java/org/dogtagpki/server/rest/v2/UserServlet.java b/base/server/src/main/java/org/dogtagpki/server/rest/v2/UserServlet.java index 8ef6d6202dc..652cecfd860 100644 --- a/base/server/src/main/java/org/dogtagpki/server/rest/v2/UserServlet.java +++ b/base/server/src/main/java/org/dogtagpki/server/rest/v2/UserServlet.java @@ -35,7 +35,7 @@ public class UserServlet extends PKIServlet { private static final long serialVersionUID = 1L; public static final Logger logger = LoggerFactory.getLogger(UserServlet.class); - @WebAction(method = HttpMethod.GET, paths = { "/"}) + @WebAction(method = HttpMethod.GET, paths = { ""}) public void findUsers(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.findUsers(): session: {}", session.getId()); @@ -49,7 +49,7 @@ public void findUsers(HttpServletRequest request, HttpServletResponse response) out.println(users.toJSON()); } - @WebAction(method = HttpMethod.POST, paths = { "/"}) + @WebAction(method = HttpMethod.POST, paths = { ""}) public void addUser(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.addUser(): session: {}", session.getId()); @@ -66,7 +66,7 @@ public void addUser(HttpServletRequest request, HttpServletResponse response) th out.println(user.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = { "/{}"}) + @WebAction(method = HttpMethod.GET, paths = { "{}"}) public void getUser(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.getUser(): session: {}", session.getId()); @@ -79,7 +79,7 @@ public void getUser(HttpServletRequest request, HttpServletResponse response) th } - @WebAction(method = HttpMethod.PATCH, paths = { "/{}"}) + @WebAction(method = HttpMethod.PATCH, paths = { "{}"}) public void modifyUser(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.modifyUser(): session: {}", session.getId()); @@ -93,7 +93,7 @@ public void modifyUser(HttpServletRequest request, HttpServletResponse response) out.println(user.toJSON()); } - @WebAction(method = HttpMethod.DELETE, paths = { "/{}"}) + @WebAction(method = HttpMethod.DELETE, paths = { "{}"}) public void removeUser(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.removeUser(): session: {}", session.getId()); @@ -104,7 +104,7 @@ public void removeUser(HttpServletRequest request, HttpServletResponse response) response.setStatus(HttpServletResponse.SC_NO_CONTENT); } - @WebAction(method = HttpMethod.GET, paths = { "/{}/certs"}) + @WebAction(method = HttpMethod.GET, paths = { "{}/certs"}) public void findUserCerts(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.findUserCerts(): session: {}", session.getId()); @@ -119,7 +119,7 @@ public void findUserCerts(HttpServletRequest request, HttpServletResponse respon out.println(userCerts.toJSON()); } - @WebAction(method = HttpMethod.POST, paths = { "/{}/certs"}) + @WebAction(method = HttpMethod.POST, paths = { "{}/certs"}) public void addUserCert(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.addUserCert(): session: {}", session.getId()); @@ -141,7 +141,7 @@ public void addUserCert(HttpServletRequest request, HttpServletResponse response out.println(userCertData.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = { "/{}/certs/{}"}) + @WebAction(method = HttpMethod.GET, paths = { "{}/certs/{}"}) public void getUserCert(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.getUserCert(): session: {}", session.getId()); @@ -154,7 +154,7 @@ public void getUserCert(HttpServletRequest request, HttpServletResponse response out.println(userCert.toJSON()); } - @WebAction(method = HttpMethod.DELETE, paths = { "/{}/certs/{}"}) + @WebAction(method = HttpMethod.DELETE, paths = { "{}/certs/{}"}) public void removeUserCert(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.removeUserCert(): session: {}", session.getId()); @@ -166,7 +166,7 @@ public void removeUserCert(HttpServletRequest request, HttpServletResponse respo response.setStatus(HttpServletResponse.SC_NO_CONTENT); } - @WebAction(method = HttpMethod.GET, paths = { "/{}/memberships"}) + @WebAction(method = HttpMethod.GET, paths = { "{}/memberships"}) public void findUserMemberships(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.findUserMemberships(): session: {}", session.getId()); @@ -182,7 +182,7 @@ public void findUserMemberships(HttpServletRequest request, HttpServletResponse out.println(userMemberships.toJSON()); } - @WebAction(method = HttpMethod.POST, paths = { "/{}/memberships"}) + @WebAction(method = HttpMethod.POST, paths = { "{}/memberships"}) public void addUserMembership(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.addUserMembership(): session: {}", session.getId()); @@ -200,7 +200,7 @@ public void addUserMembership(HttpServletRequest request, HttpServletResponse re out.println(userMembership.toJSON()); } - @WebAction(method = HttpMethod.DELETE, paths = { "/{}/memberships/{}"}) + @WebAction(method = HttpMethod.DELETE, paths = { "{}/memberships/{}"}) public void removeUserMembership(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("UserServlet.removeUserMembership(): session: {}", session.getId()); diff --git a/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/ACLFilter.java b/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/ACLFilter.java index 078aa16be71..4fe00c8f7ca 100644 --- a/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/ACLFilter.java +++ b/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/ACLFilter.java @@ -64,9 +64,9 @@ * * ACLMap: * - * key= POST:/token value=token.add - * key= PUT:/token/{} value=token.modify - * key= DELETE:/token/{} value=token.delete + * key= POST:token value=token.add + * key= PUT:token/{} value=token.modify + * key= DELETE:token/{} value=token.delete */ public abstract class ACLFilter extends HttpFilter { @@ -89,7 +89,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha if(request instanceof HttpServletRequest req && response instanceof HttpServletResponse resp) { method = req.getMethod(); - path = req.getPathInfo() != null ? req.getPathInfo() : "/"; + path = req.getPathInfo() != null ? req.getPathInfo().substring(1) : ""; final String aclSearch = method + ":" + path; if (aclMap!=null) { Optional aclKey = aclMap.keySet().stream(). diff --git a/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/AccountACL.java b/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/AccountACL.java index b0b30892786..a172940ec9f 100644 --- a/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/AccountACL.java +++ b/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/AccountACL.java @@ -12,8 +12,8 @@ public class AccountACL extends ACLFilter { public void init() throws ServletException { setAcl("account.login"); Map aclMap = new HashMap<>(); - aclMap.put("GET:/login", "account.login"); - aclMap.put("GET:/logout", "account.logout"); + aclMap.put("GET:login", "account.login"); + aclMap.put("GET:logout", "account.logout"); setAclMap(aclMap); } } diff --git a/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/SelfTestACL.java b/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/SelfTestACL.java index fc617338dbc..0954456ebb1 100644 --- a/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/SelfTestACL.java +++ b/base/server/src/main/java/org/dogtagpki/server/rest/v2/filters/SelfTestACL.java @@ -15,9 +15,9 @@ public class SelfTestACL extends ACLFilter { public void init() throws ServletException { setAcl(READ); Map aclMap = new HashMap<>(); - aclMap.put("POST:/", EXECUTE); - aclMap.put("POST:/run", EXECUTE); - aclMap.put("POST:/{}/run", EXECUTE); + aclMap.put("POST:", EXECUTE); + aclMap.put("POST:run", EXECUTE); + aclMap.put("POST:{}/run", EXECUTE); setAclMap(aclMap); } diff --git a/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/ActivityServlet.java b/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/ActivityServlet.java index 509b741401a..6f5bca06285 100644 --- a/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/ActivityServlet.java +++ b/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/ActivityServlet.java @@ -42,7 +42,7 @@ public class ActivityServlet extends TPSServlet { private static final long serialVersionUID = 1L; private static final Logger logger = LoggerFactory.getLogger(ActivityServlet.class); - @WebAction(method = HttpMethod.GET, paths = { "/"}) + @WebAction(method = HttpMethod.GET, paths = {""}) public void findActivities(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.debug("ActivityServlet.findActivities(): session: {}", session.getId()); @@ -66,7 +66,7 @@ public void findActivities(HttpServletRequest request, HttpServletResponse respo out.println(activities.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = { "/{}"}) + @WebAction(method = HttpMethod.GET, paths = {"{}"}) public void getActivity(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = "ActivityServlet.getActivity:"; HttpSession session = request.getSession(); diff --git a/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/TPSAccountServlet.java b/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/TPSAccountServlet.java index e4c435c6067..6e20be9b839 100644 --- a/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/TPSAccountServlet.java +++ b/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/TPSAccountServlet.java @@ -29,7 +29,7 @@ public class TPSAccountServlet extends TPSServlet { private static final long serialVersionUID = 1L; public static final Logger logger = LoggerFactory.getLogger(TPSAccountServlet.class); - @WebAction(method = HttpMethod.GET, paths = { "/login"}) + @WebAction(method = HttpMethod.GET, paths = { "login"}) public void login(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); logger.info("AccountServlet: Creating session {}", session.getId()); @@ -37,7 +37,7 @@ public void login(HttpServletRequest request, HttpServletResponse response) thro PrintWriter out = response.getWriter(); out.println(account.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = { "/logout"}) + @WebAction(method = HttpMethod.GET, paths = { "logout"}) public void logout(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(false); if (session != null) { diff --git a/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/TokenServlet.java b/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/TokenServlet.java index fa9684ad2b7..5b1ff101cc4 100644 --- a/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/TokenServlet.java +++ b/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/TokenServlet.java @@ -62,7 +62,7 @@ public class TokenServlet extends TPSServlet { private static final long serialVersionUID = 1L; private static final Logger logger = LoggerFactory.getLogger(TokenServlet.class); - @WebAction(method = HttpMethod.GET, paths = { "/"}) + @WebAction(method = HttpMethod.GET, paths = {""}) public void findTokens(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = "TokenServlet.findTokens:"; TPSSubsystem subsystem = getTPSSubsystem(); @@ -103,7 +103,7 @@ public void findTokens(HttpServletRequest request, HttpServletResponse response) out.println(tokens.toJSON()); } - @WebAction(method = HttpMethod.GET, paths = { "/{}"}) + @WebAction(method = HttpMethod.GET, paths = {"{}"}) public void getToken(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = "TokenServlet.getToken:"; TPSSubsystem subsystem = getTPSSubsystem(); @@ -145,7 +145,7 @@ public void getToken(HttpServletRequest request, HttpServletResponse response) t throw new UnauthorizedException(method + " Token record restricted"); } - @WebAction(method = HttpMethod.POST, paths = { "/"}) + @WebAction(method = HttpMethod.POST, paths = {""}) public void addToken(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = "TokenServlet.changeTokenStatus:"; PrintWriter out = response.getWriter(); @@ -164,7 +164,7 @@ public void addToken(HttpServletRequest request, HttpServletResponse response) t out.println(token.toJSON()); } - @WebAction(method = HttpMethod.POST, paths = { "/{}"}) + @WebAction(method = HttpMethod.POST, paths = {"{}"}) public void changeTokenStatus(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = "TokenServlet.changeTokenStatus:"; PrintWriter out = response.getWriter(); @@ -180,7 +180,7 @@ public void changeTokenStatus(HttpServletRequest request, HttpServletResponse re } - @WebAction(method = HttpMethod.PUT, paths = { "/{}"}) + @WebAction(method = HttpMethod.PUT, paths = {"{}"}) public void replaceToken(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = "TokenServlet.put:"; PrintWriter out = response.getWriter(); @@ -196,7 +196,7 @@ public void replaceToken(HttpServletRequest request, HttpServletResponse respons out.println(token.toJSON()); } - @WebAction(method = HttpMethod.PATCH, paths = { "/{}"}) + @WebAction(method = HttpMethod.PATCH, paths = {"{}"}) public void modifyToken(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = "TokenServlet.patch:"; PrintWriter out = response.getWriter(); @@ -213,7 +213,7 @@ public void modifyToken(HttpServletRequest request, HttpServletResponse response out.println(token.toJSON()); } - @WebAction(method = HttpMethod.DELETE, paths = { "/{}"}) + @WebAction(method = HttpMethod.DELETE, paths = {"{}"}) public void removeToken(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = "TokenServlet.delete:"; diff --git a/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/filters/TokenACL.java b/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/filters/TokenACL.java index 21ccd8b987f..5cf54ff371b 100644 --- a/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/filters/TokenACL.java +++ b/base/tps/src/main/java/org/dogtagpki/server/tps/rest/v2/filters/TokenACL.java @@ -19,11 +19,11 @@ public class TokenACL extends ACLFilter { public void init() throws ServletException { setAcl("tokens.read"); Map aclMap = new HashMap<>(); - aclMap.put("POST:/", ADD); - aclMap.put("PUT:/{}", MODIFY); - aclMap.put("PATCH:/{}", MODIFY); - aclMap.put("POST:/{}", MODIFY); - aclMap.put("DELETE:/{}", REMOVE); + aclMap.put("POST:", ADD); + aclMap.put("PUT:{}", MODIFY); + aclMap.put("PATCH:{}", MODIFY); + aclMap.put("POST:{}", MODIFY); + aclMap.put("DELETE:{}", REMOVE); setAclMap(aclMap); }