Merge branch 'stable-2.8'

* stable-2.8:
  Make plugin servlet's context path authorization aware
  Support 'id' attribute for menu items contributed by plugins
This commit is contained in:
Shawn Pearce
2013-11-06 12:50:39 -08:00
5 changed files with 32 additions and 11 deletions

View File

@@ -181,7 +181,7 @@ CapabilityInfo
~~~~~~~~~~~~~~
The `CapabilityInfo` entity contains information about a capability.
[options="header",width="50%",cols="1,5"]
[options="header",width="50%",cols="1,6"]
|=================================
|Field Name |Description
|`kind` |`gerritcodereview#capability`
@@ -195,7 +195,7 @@ TopMenuEntryInfo
The `TopMenuEntryInfo` entity contains information about a top menu
entry.
[options="header",width="50%",cols="1,5"]
[options="header",width="50%",cols="1,6"]
|=================================
|Field Name |Description
|`name` |Name of the top menu entry.
@@ -208,13 +208,14 @@ TopMenuItemInfo
The `TopMenuItemInfo` entity contains information about a menu item in
a top menu entry.
[options="header",width="50%",cols="1,5"]
|=================================
|Field Name |Description
|`url` |The URL of the menu item link.
|`name` |The name of the menu item.
|`target` |Target attribute of the menu item link.
|=================================
[options="header",width="50%",cols="1,^1,5"]
|========================
|Field Name ||Description
|`url` ||The URL of the menu item link.
|`name` ||The name of the menu item.
|`target` ||Target attribute of the menu item link.
|`id` |optional|The `id` attribute of the menu item link.
|========================
GERRIT
------

View File

@@ -38,15 +38,21 @@ public interface TopMenu {
public final String url;
public final String name;
public final String target;
public final String id;
public MenuItem(String name, String url) {
this(name, url, "_blank");
}
public MenuItem(String name, String url, String target) {
this(name, url, target, null);
}
public MenuItem(String name, String url, String target, String id) {
this.url = url;
this.name = name;
this.target = target;
this.id = id;
}
}

View File

@@ -978,6 +978,9 @@ public class Gerrit implements EntryPoint {
private static void addExtensionLink(final LinkMenuBar m, final TopMenuItem item) {
final Anchor atag = anchor(item.getName(), item.getUrl());
atag.setTarget(item.getTarget());
if (item.getId() != null) {
atag.getElement().setAttribute("id", item.getId());
}
m.add(atag);
}
}

View File

@@ -20,6 +20,7 @@ public class TopMenuItem extends JavaScriptObject {
public final native String getName() /*-{ return this.name; }-*/;
public final native String getUrl() /*-{ return this.url; }-*/;
public final native String getTarget() /*-{ return this.target; }-*/;
public final native String getId() /*-{ return this.id; }-*/;
protected TopMenuItem() {
}

View File

@@ -81,6 +81,8 @@ class HttpPluginServlet extends HttpServlet
private static final long serialVersionUID = 1L;
private static final Logger log
= LoggerFactory.getLogger(HttpPluginServlet.class);
private static final String PLUGINS_PREFIX = "/plugins/";
private static final String AUTHORIZED_PREFIX = "/a" + PLUGINS_PREFIX;
private final MimeUtilFileTypeRegistry mimeUtil;
private final Provider<String> webUrl;
@@ -91,6 +93,7 @@ class HttpPluginServlet extends HttpServlet
private List<Plugin> pending = Lists.newArrayList();
private String base;
private String authorizedBase;
private final ConcurrentMap<String, PluginHolder> plugins
= Maps.newConcurrentMap();
@@ -129,7 +132,8 @@ class HttpPluginServlet extends HttpServlet
super.init(config);
String path = config.getServletContext().getContextPath();
base = Strings.nullToEmpty(path) + "/plugins/";
base = Strings.nullToEmpty(path) + PLUGINS_PREFIX;
authorizedBase = Strings.nullToEmpty(path) + AUTHORIZED_PREFIX;
for (Plugin plugin : pending) {
install(plugin);
}
@@ -213,7 +217,8 @@ class HttpPluginServlet extends HttpServlet
return;
}
WrappedRequest wr = new WrappedRequest(req, base + name);
WrappedRequest wr = new WrappedRequest(req,
(isAuthorizedCall(req) ? authorizedBase : base) + name);
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest req, ServletResponse res)
@@ -228,6 +233,11 @@ class HttpPluginServlet extends HttpServlet
}
}
private boolean isAuthorizedCall(HttpServletRequest req) {
return !Strings.isNullOrEmpty(req.getServletPath())
&& req.getServletPath().startsWith(AUTHORIZED_PREFIX);
}
private static boolean isApiCall(HttpServletRequest req, List<String> parts) {
String method = req.getMethod();
int cnt = parts.size();