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:
@@ -181,7 +181,7 @@ CapabilityInfo
|
|||||||
~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~
|
||||||
The `CapabilityInfo` entity contains information about a capability.
|
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
|
|Field Name |Description
|
||||||
|`kind` |`gerritcodereview#capability`
|
|`kind` |`gerritcodereview#capability`
|
||||||
@@ -195,7 +195,7 @@ TopMenuEntryInfo
|
|||||||
The `TopMenuEntryInfo` entity contains information about a top menu
|
The `TopMenuEntryInfo` entity contains information about a top menu
|
||||||
entry.
|
entry.
|
||||||
|
|
||||||
[options="header",width="50%",cols="1,5"]
|
[options="header",width="50%",cols="1,6"]
|
||||||
|=================================
|
|=================================
|
||||||
|Field Name |Description
|
|Field Name |Description
|
||||||
|`name` |Name of the top menu entry.
|
|`name` |Name of the top menu entry.
|
||||||
@@ -208,13 +208,14 @@ TopMenuItemInfo
|
|||||||
The `TopMenuItemInfo` entity contains information about a menu item in
|
The `TopMenuItemInfo` entity contains information about a menu item in
|
||||||
a top menu entry.
|
a top menu entry.
|
||||||
|
|
||||||
[options="header",width="50%",cols="1,5"]
|
[options="header",width="50%",cols="1,^1,5"]
|
||||||
|=================================
|
|========================
|
||||||
|Field Name |Description
|
|Field Name ||Description
|
||||||
|`url` |The URL of the menu item link.
|
|`url` ||The URL of the menu item link.
|
||||||
|`name` |The name of the menu item.
|
|`name` ||The name of the menu item.
|
||||||
|`target` |Target attribute of the menu item link.
|
|`target` ||Target attribute of the menu item link.
|
||||||
|=================================
|
|`id` |optional|The `id` attribute of the menu item link.
|
||||||
|
|========================
|
||||||
|
|
||||||
GERRIT
|
GERRIT
|
||||||
------
|
------
|
||||||
|
|||||||
@@ -38,15 +38,21 @@ public interface TopMenu {
|
|||||||
public final String url;
|
public final String url;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String target;
|
public final String target;
|
||||||
|
public final String id;
|
||||||
|
|
||||||
public MenuItem(String name, String url) {
|
public MenuItem(String name, String url) {
|
||||||
this(name, url, "_blank");
|
this(name, url, "_blank");
|
||||||
}
|
}
|
||||||
|
|
||||||
public MenuItem(String name, String url, String target) {
|
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.url = url;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
this.id = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -978,6 +978,9 @@ public class Gerrit implements EntryPoint {
|
|||||||
private static void addExtensionLink(final LinkMenuBar m, final TopMenuItem item) {
|
private static void addExtensionLink(final LinkMenuBar m, final TopMenuItem item) {
|
||||||
final Anchor atag = anchor(item.getName(), item.getUrl());
|
final Anchor atag = anchor(item.getName(), item.getUrl());
|
||||||
atag.setTarget(item.getTarget());
|
atag.setTarget(item.getTarget());
|
||||||
|
if (item.getId() != null) {
|
||||||
|
atag.getElement().setAttribute("id", item.getId());
|
||||||
|
}
|
||||||
m.add(atag);
|
m.add(atag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class TopMenuItem extends JavaScriptObject {
|
|||||||
public final native String getName() /*-{ return this.name; }-*/;
|
public final native String getName() /*-{ return this.name; }-*/;
|
||||||
public final native String getUrl() /*-{ return this.url; }-*/;
|
public final native String getUrl() /*-{ return this.url; }-*/;
|
||||||
public final native String getTarget() /*-{ return this.target; }-*/;
|
public final native String getTarget() /*-{ return this.target; }-*/;
|
||||||
|
public final native String getId() /*-{ return this.id; }-*/;
|
||||||
|
|
||||||
protected TopMenuItem() {
|
protected TopMenuItem() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ class HttpPluginServlet extends HttpServlet
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Logger log
|
private static final Logger log
|
||||||
= LoggerFactory.getLogger(HttpPluginServlet.class);
|
= 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 MimeUtilFileTypeRegistry mimeUtil;
|
||||||
private final Provider<String> webUrl;
|
private final Provider<String> webUrl;
|
||||||
@@ -91,6 +93,7 @@ class HttpPluginServlet extends HttpServlet
|
|||||||
|
|
||||||
private List<Plugin> pending = Lists.newArrayList();
|
private List<Plugin> pending = Lists.newArrayList();
|
||||||
private String base;
|
private String base;
|
||||||
|
private String authorizedBase;
|
||||||
private final ConcurrentMap<String, PluginHolder> plugins
|
private final ConcurrentMap<String, PluginHolder> plugins
|
||||||
= Maps.newConcurrentMap();
|
= Maps.newConcurrentMap();
|
||||||
|
|
||||||
@@ -129,7 +132,8 @@ class HttpPluginServlet extends HttpServlet
|
|||||||
super.init(config);
|
super.init(config);
|
||||||
|
|
||||||
String path = config.getServletContext().getContextPath();
|
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) {
|
for (Plugin plugin : pending) {
|
||||||
install(plugin);
|
install(plugin);
|
||||||
}
|
}
|
||||||
@@ -213,7 +217,8 @@ class HttpPluginServlet extends HttpServlet
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WrappedRequest wr = new WrappedRequest(req, base + name);
|
WrappedRequest wr = new WrappedRequest(req,
|
||||||
|
(isAuthorizedCall(req) ? authorizedBase : base) + name);
|
||||||
FilterChain chain = new FilterChain() {
|
FilterChain chain = new FilterChain() {
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest req, ServletResponse res)
|
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) {
|
private static boolean isApiCall(HttpServletRequest req, List<String> parts) {
|
||||||
String method = req.getMethod();
|
String method = req.getMethod();
|
||||||
int cnt = parts.size();
|
int cnt = parts.size();
|
||||||
|
|||||||
Reference in New Issue
Block a user