From bfef420aefdd30ffb09f6ec39d113d3499b27c2b Mon Sep 17 00:00:00 2001 From: Brad Larson Date: Wed, 25 Jul 2012 13:01:19 -0500 Subject: [PATCH] Support /a/ for plugin REST APIs Without the /a/, users are unable to script REST API calls using tools such as curl, as the CurrentUser wasn't being provided. Also fix a minor bug when anonymous users tried to access /a/ URLs. We were throwing an exception when building up our error message. Change-Id: I5ce870960aa107001c4014fefcf914adc366cd8a Signed-off-by: Brad Larson --- .../java/com/google/gerrit/httpd/RestApiServlet.java | 11 +++++++---- .../google/gerrit/httpd/plugins/HttpPluginModule.java | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/RestApiServlet.java index be8ae328b2..a4217cf02e 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/RestApiServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/RestApiServlet.java @@ -102,10 +102,13 @@ public abstract class RestApiServlet extends HttpServlet { CapabilityControl ctl = user.getCapabilities(); if (!ctl.canPerform(rc.value()) && !ctl.canAdministrateServer()) { String msg = String.format( - "fatal: %s does not have \"%s\" capability.", - Objects.firstNonNull(user.getUserName(), - ((IdentifiedUser)user).getNameEmail()), - rc.value()); + "fatal: %s does not have \"%s\" capability.", + Objects.firstNonNull( + user.getUserName(), + user instanceof IdentifiedUser + ? ((IdentifiedUser) user).getNameEmail() + : user.toString()), + rc.value()); throw new RequireCapabilityException(msg); } } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/plugins/HttpPluginModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/plugins/HttpPluginModule.java index bb47b8b8e5..2bcaa30310 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/plugins/HttpPluginModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/plugins/HttpPluginModule.java @@ -28,6 +28,7 @@ public class HttpPluginModule extends ServletModule { protected void configureServlets() { bind(HttpPluginServlet.class); serve("/plugins/*").with(HttpPluginServlet.class); + serveRegex("^/(?:a/)?plugins/(.*)?$").with(HttpPluginServlet.class); bind(StartPluginListener.class) .annotatedWith(UniqueAnnotations.create())