Fix successful login redirection to keep parameters

Login screen accept a token to redirect to on successful login but
if the token contained parameters, they were dropped.

Encode/decode the token to fix this issue.

When a URL has a pound sign, it is included in the token as well.
This removes the hardcoded behaviour to include a pound sign in every
redirect URL. Will now be able to use login redirection for URLs with
no pound sign (e.g. GitWeb)

Change-Id: If8a74a74ce11f79389895e4d036b06a1e81abbe5
This commit is contained in:
Simon Lei
2014-06-04 10:40:20 -04:00
parent cdfbcbccf6
commit 71891446a5
8 changed files with 29 additions and 30 deletions

View File

@@ -336,7 +336,15 @@ public class Gerrit implements EntryPoint {
} else if (token.startsWith("/")) {
token = token.substring(1);
}
return selfRedirect("/login/" + token);
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));
}
public static String selfRedirect(String suffix) {