Merge "Fix login redirect for non default (root) context" into stable-2.10

This commit is contained in:
Edwin Kempin 2014-11-05 14:33:20 +00:00 committed by Gerrit Code Review
commit 449eb895c5
3 changed files with 10 additions and 15 deletions

View File

@ -337,14 +337,7 @@ public class Gerrit implements EntryPoint {
token = token.substring(1);
}
UrlBuilder builder = new UrlBuilder();
builder.setProtocol(Location.getProtocol());
builder.setHost(Location.getHost());
String port = Location.getPort();
if (port != null && !port.isEmpty()) {
builder.setPort(Integer.parseInt(port));
}
return builder.buildString() + ("/login/" + URL.encodePathSegment("#/" + token));
return selfRedirect("login/") + URL.encodePathSegment("#/" + token);
}
public static String selfRedirect(String suffix) {

View File

@ -16,8 +16,6 @@ package com.google.gerrit.httpd.auth.become;
import static com.google.gerrit.reviewdb.client.AccountExternalId.SCHEME_USERNAME;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.httpd.HtmlDomUtil;
@ -122,9 +120,8 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
if (res != null) {
webSession.get().login(res, false);
final StringBuilder rdr = new StringBuilder();
rdr.append(Objects.firstNonNull(
Strings.emptyToNull(req.getContextPath()),
"/"));
rdr.append(req.getContextPath());
rdr.append("/");
if (IS_DEV && req.getParameter("gwt.codesvr") != null) {
if (rdr.indexOf("?") < 0) {
rdr.append("?");

View File

@ -409,8 +409,13 @@ class GitWebServlet extends HttpServlet {
}
private static String getLoginRedirectUrl(HttpServletRequest req) {
String loginUrl = req.getContextPath() + "/login/";
String token = req.getRequestURI().substring(1);
String contextPath = req.getContextPath();
String loginUrl = contextPath + "/login/";
String token = req.getRequestURI();
if (!contextPath.isEmpty()) {
token = token.substring(contextPath.length());
}
String queryString = req.getQueryString();
if (queryString != null && !queryString.isEmpty()) {
token = token.concat("?" + queryString);