Customized registration page when auth.type=HTTP

Introduction of a new auth.registerPageUrl in
gerrit.config to specify a custom registration
page when a new user logs in the first time
to Gerrit.

If not set, the standard Gerrit registration page
`/#/register/` is displayed.

Needed when SSO with a 3rd party authentication
system (e.g. GitHub) is required and the initial
migration of the user profile (e.g. SSH Keys)
would require custom user interactions.

Change-Id: Iad0941e97c0fa749027f12f17f584eb2bd6de07b
This commit is contained in:
Luca Milanesio
2013-08-15 18:56:42 +01:00
parent 627a250c72
commit 111e0b7934
3 changed files with 27 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.server.account.AccountException;
import com.google.gerrit.server.account.AccountManager;
import com.google.gerrit.server.account.AuthRequest;
import com.google.gerrit.server.account.AuthResult;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gwtexpui.server.CacheHeaders;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -59,16 +60,19 @@ class HttpLoginServlet extends HttpServlet {
private final CanonicalWebUrl urlProvider;
private final AccountManager accountManager;
private final HttpAuthFilter authFilter;
private final AuthConfig authConfig;
@Inject
HttpLoginServlet(final Provider<WebSession> webSession,
final CanonicalWebUrl urlProvider,
final AccountManager accountManager,
final HttpAuthFilter authFilter) {
final HttpAuthFilter authFilter,
final AuthConfig authConfig) {
this.webSession = webSession;
this.urlProvider = urlProvider;
this.accountManager = accountManager;
this.authFilter = authFilter;
this.authConfig = authConfig;
}
@Override
@@ -122,12 +126,16 @@ class HttpLoginServlet extends HttpServlet {
}
final StringBuilder rdr = new StringBuilder();
rdr.append(urlProvider.get(req));
rdr.append('#');
if (arsp.isNew() && !token.startsWith(PageLinks.REGISTER + "/")) {
rdr.append(PageLinks.REGISTER);
if (arsp.isNew() && authConfig.getRegisterPageUrl() != null) {
rdr.append(authConfig.getRegisterPageUrl());
} else {
rdr.append(urlProvider.get(req));
rdr.append('#');
if (arsp.isNew() && !token.startsWith(PageLinks.REGISTER + "/")) {
rdr.append(PageLinks.REGISTER);
}
rdr.append(token);
}
rdr.append(token);
webSession.get().login(arsp, true /* persistent cookie */);
rsp.sendRedirect(rdr.toString());