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 <bklarson@gmail.com>
This commit is contained in:
Brad Larson
2012-07-25 13:01:19 -05:00
committed by Shawn O. Pearce
parent 86d22c2276
commit bfef420aef
2 changed files with 8 additions and 4 deletions

View File

@@ -103,8 +103,11 @@ public abstract class RestApiServlet extends HttpServlet {
if (!ctl.canPerform(rc.value()) && !ctl.canAdministrateServer()) { if (!ctl.canPerform(rc.value()) && !ctl.canAdministrateServer()) {
String msg = String.format( String msg = String.format(
"fatal: %s does not have \"%s\" capability.", "fatal: %s does not have \"%s\" capability.",
Objects.firstNonNull(user.getUserName(), Objects.firstNonNull(
((IdentifiedUser)user).getNameEmail()), user.getUserName(),
user instanceof IdentifiedUser
? ((IdentifiedUser) user).getNameEmail()
: user.toString()),
rc.value()); rc.value());
throw new RequireCapabilityException(msg); throw new RequireCapabilityException(msg);
} }

View File

@@ -28,6 +28,7 @@ public class HttpPluginModule extends ServletModule {
protected void configureServlets() { protected void configureServlets() {
bind(HttpPluginServlet.class); bind(HttpPluginServlet.class);
serve("/plugins/*").with(HttpPluginServlet.class); serve("/plugins/*").with(HttpPluginServlet.class);
serveRegex("^/(?:a/)?plugins/(.*)?$").with(HttpPluginServlet.class);
bind(StartPluginListener.class) bind(StartPluginListener.class)
.annotatedWith(UniqueAnnotations.create()) .annotatedWith(UniqueAnnotations.create())