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

@ -294,6 +294,13 @@ Text displayed in the loginUrl link. Only used if `auth.loginUrl` is set.
+
If not set, the "Sign In" text is used.
[[auth.registerPageUrl]]auth.registerPageUrl::
+
URL of the registration page when a new user logs in the first time
to Gerrit. Used only when `auth.type` is set to `HTTP`.
+
If not set, the standard Gerrit registration page `/#/register/` is displayed.
[[auth.logoutUrl]]auth.logoutUrl::
+
URL to redirect a browser to after the end-user has clicked on the

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());

View File

@ -38,6 +38,7 @@ public class AuthConfig {
private final String httpHeader;
private final String httpDisplaynameHeader;
private final String httpEmailHeader;
private final String registerPageUrl;
private final boolean trustContainerAuth;
private final boolean enableRunAs;
private final boolean userNameToLowerCase;
@ -64,6 +65,7 @@ public class AuthConfig {
httpEmailHeader = cfg.getString("auth", null, "httpemailheader");
loginUrl = cfg.getString("auth", null, "loginurl");
logoutUrl = cfg.getString("auth", null, "logouturl");
registerPageUrl = cfg.getString("auth", null, "registerPageUrl");
openIdSsoUrl = cfg.getString("auth", null, "openidssourl");
openIdDomains = Arrays.asList(cfg.getStringList("auth", null, "openIdDomain"));
trustedOpenIDs = toPatterns(cfg, "trustedOpenID");
@ -271,4 +273,8 @@ public class AuthConfig {
}
return false;
}
public String getRegisterPageUrl() {
return registerPageUrl;
}
}