Make the magic "Become" mode for development a normal LoginType
This simplifies cases in the client code, making the magic become mode behave like other types of login routines. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -351,43 +351,39 @@ public class Gerrit implements EntryPoint {
|
|||||||
if (signedIn) {
|
if (signedIn) {
|
||||||
whoAmI();
|
whoAmI();
|
||||||
addLink(menuRight, C.menuSettings(), Link.SETTINGS);
|
addLink(menuRight, C.menuSettings(), Link.SETTINGS);
|
||||||
boolean signout = false;
|
|
||||||
switch (Common.getGerritConfig().getLoginType()) {
|
switch (Common.getGerritConfig().getLoginType()) {
|
||||||
case HTTP:
|
case HTTP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPENID:
|
case OPENID:
|
||||||
default:
|
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
|
||||||
signout = true;
|
menuRight.addItem(C.menuSignOut(), new Command() {
|
||||||
|
public void execute() {
|
||||||
|
doSignOut();
|
||||||
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (signout || !GWT.isScript()) {
|
|
||||||
menuRight.addItem(C.menuSignOut(), new Command() {
|
|
||||||
public void execute() {
|
|
||||||
doSignOut();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
switch (Common.getGerritConfig().getLoginType()) {
|
switch (Common.getGerritConfig().getLoginType()) {
|
||||||
case HTTP:
|
case HTTP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPENID:
|
case OPENID:
|
||||||
default:
|
|
||||||
menuRight.addItem(C.menuSignIn(), new Command() {
|
menuRight.addItem(C.menuSignIn(), new Command() {
|
||||||
public void execute() {
|
public void execute() {
|
||||||
doSignIn();
|
doSignIn();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (!GWT.isScript()) {
|
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
|
||||||
menuRight.addItem("Become", new Command() {
|
menuRight.addItem("Become", new Command() {
|
||||||
public void execute() {
|
public void execute() {
|
||||||
Window.Location.assign(GWT.getHostPageBaseURL() + "become");
|
Window.Location.assign(GWT.getHostPageBaseURL() + "become");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
package com.google.gerrit.client.data;
|
package com.google.gerrit.client.data;
|
||||||
|
|
||||||
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
||||||
import com.google.gerrit.client.reviewdb.SystemConfig;
|
import com.google.gerrit.client.reviewdb.LoginType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -30,7 +30,7 @@ public class GerritConfig implements Cloneable {
|
|||||||
protected boolean useContributorAgreements;
|
protected boolean useContributorAgreements;
|
||||||
protected boolean useContactInfo;
|
protected boolean useContactInfo;
|
||||||
protected boolean allowRegisterNewEmail;
|
protected boolean allowRegisterNewEmail;
|
||||||
protected SystemConfig.LoginType loginType;
|
protected LoginType loginType;
|
||||||
protected boolean useRepoDownload;
|
protected boolean useRepoDownload;
|
||||||
protected String gitDaemonUrl;
|
protected String gitDaemonUrl;
|
||||||
protected String sshdAddress;
|
protected String sshdAddress;
|
||||||
@@ -47,11 +47,11 @@ public class GerritConfig implements Cloneable {
|
|||||||
canonicalUrl = u;
|
canonicalUrl = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SystemConfig.LoginType getLoginType() {
|
public LoginType getLoginType() {
|
||||||
return loginType;
|
return loginType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginType(final SystemConfig.LoginType t) {
|
public void setLoginType(final LoginType t) {
|
||||||
loginType = t;
|
loginType = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (C) 2009 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.client.reviewdb;
|
||||||
|
|
||||||
|
public enum LoginType {
|
||||||
|
/** Login relies upon the OpenID standard: {@link "http://openid.net/"} */
|
||||||
|
OPENID,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Login relies upon the container/web server security.
|
||||||
|
* <p>
|
||||||
|
* The container or web server must populate an HTTP header with the some
|
||||||
|
* user token. Gerrit will implicitly trust the value of this header to
|
||||||
|
* supply the unique identity.
|
||||||
|
*/
|
||||||
|
HTTP,
|
||||||
|
|
||||||
|
/** Development mode to enable becoming anyone you want. */
|
||||||
|
DEVELOPMENT_BECOME_ANY_ACCOUNT;
|
||||||
|
}
|
||||||
@@ -42,20 +42,6 @@ public final class SystemConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum LoginType {
|
|
||||||
/** Login relies upon the OpenID standard: {@link "http://openid.net/"} */
|
|
||||||
OPENID,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Login relies upon the container/web server security.
|
|
||||||
* <p>
|
|
||||||
* The container or web server must populate an HTTP header with the some
|
|
||||||
* user token. Gerrit will implicitly trust the value of this header to
|
|
||||||
* supply the unique identity.
|
|
||||||
*/
|
|
||||||
HTTP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Construct a new, unconfigured instance. */
|
/** Construct a new, unconfigured instance. */
|
||||||
public static SystemConfig create() {
|
public static SystemConfig create() {
|
||||||
final SystemConfig r = new SystemConfig();
|
final SystemConfig r = new SystemConfig();
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.config;
|
package com.google.gerrit.server.config;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.reviewdb.LoginType;
|
||||||
import com.google.gerrit.client.reviewdb.SystemConfig;
|
import com.google.gerrit.client.reviewdb.SystemConfig;
|
||||||
import com.google.gerrit.client.reviewdb.SystemConfig.LoginType;
|
|
||||||
import com.google.gwtjsonrpc.server.SignedToken;
|
import com.google.gwtjsonrpc.server.SignedToken;
|
||||||
import com.google.gwtjsonrpc.server.XsrfException;
|
import com.google.gwtjsonrpc.server.XsrfException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -64,6 +64,9 @@ public class AuthConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static LoginType toType(final Config cfg) {
|
private static LoginType toType(final Config cfg) {
|
||||||
|
if (isBecomeAnyoneEnabled()) {
|
||||||
|
return LoginType.DEVELOPMENT_BECOME_ANY_ACCOUNT;
|
||||||
|
}
|
||||||
String type = cfg.getString("auth", null, "type");
|
String type = cfg.getString("auth", null, "type");
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return LoginType.OPENID;
|
return LoginType.OPENID;
|
||||||
@@ -76,6 +79,15 @@ public class AuthConfig {
|
|||||||
throw new IllegalStateException("Unsupported auth.type: " + type);
|
throw new IllegalStateException("Unsupported auth.type: " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isBecomeAnyoneEnabled() {
|
||||||
|
try {
|
||||||
|
String s = "com.google.gerrit.server.http.BecomeAnyAccountLoginServlet";
|
||||||
|
return Boolean.getBoolean(s);
|
||||||
|
} catch (SecurityException se) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Type of user authentication used by this Gerrit server. */
|
/** Type of user authentication used by this Gerrit server. */
|
||||||
public LoginType getLoginType() {
|
public LoginType getLoginType() {
|
||||||
return loginType;
|
return loginType;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.google.gerrit.server.config;
|
package com.google.gerrit.server.config;
|
||||||
|
|
||||||
import com.google.gerrit.client.reviewdb.SystemConfig.LoginType;
|
import com.google.gerrit.client.reviewdb.LoginType;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ package com.google.gerrit.server.http;
|
|||||||
|
|
||||||
import com.google.gerrit.client.reviewdb.Account;
|
import com.google.gerrit.client.reviewdb.Account;
|
||||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||||
|
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||||
|
import com.google.gerrit.server.config.Nullable;
|
||||||
import com.google.gwtorm.client.OrmException;
|
import com.google.gwtorm.client.OrmException;
|
||||||
import com.google.gwtorm.client.SchemaFactory;
|
import com.google.gwtorm.client.SchemaFactory;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -34,24 +36,17 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@Singleton
|
@Singleton
|
||||||
public class BecomeAnyAccountLoginServlet extends HttpServlet {
|
public class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||||
static boolean isAllowed() {
|
|
||||||
try {
|
|
||||||
return Boolean.getBoolean(BecomeAnyAccountLoginServlet.class.getName());
|
|
||||||
} catch (SecurityException se) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final boolean allowed;
|
|
||||||
private final SchemaFactory<ReviewDb> schema;
|
private final SchemaFactory<ReviewDb> schema;
|
||||||
private final Provider<GerritCall> callFactory;
|
private final Provider<GerritCall> callFactory;
|
||||||
|
private final Provider<String> urlProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BecomeAnyAccountLoginServlet(final Provider<GerritCall> cf,
|
BecomeAnyAccountLoginServlet(final Provider<GerritCall> cf,
|
||||||
final SchemaFactory<ReviewDb> sf) {
|
final SchemaFactory<ReviewDb> sf,
|
||||||
|
final @CanonicalWebUrl @Nullable Provider<String> up) {
|
||||||
callFactory = cf;
|
callFactory = cf;
|
||||||
schema = sf;
|
schema = sf;
|
||||||
allowed = isAllowed();
|
urlProvider = up;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,11 +58,6 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
|
|||||||
@Override
|
@Override
|
||||||
protected void doPost(final HttpServletRequest req,
|
protected void doPost(final HttpServletRequest req,
|
||||||
final HttpServletResponse rsp) throws IOException {
|
final HttpServletResponse rsp) throws IOException {
|
||||||
if (!allowed) {
|
|
||||||
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<Account> accounts;
|
final List<Account> accounts;
|
||||||
if (req.getParameter("ssh_user_name") != null) {
|
if (req.getParameter("ssh_user_name") != null) {
|
||||||
accounts = bySshUserName(rsp, req.getParameter("ssh_user_name"));
|
accounts = bySshUserName(rsp, req.getParameter("ssh_user_name"));
|
||||||
@@ -97,11 +87,10 @@ public class BecomeAnyAccountLoginServlet extends HttpServlet {
|
|||||||
|
|
||||||
if (accounts.size() == 1) {
|
if (accounts.size() == 1) {
|
||||||
final Account account = accounts.get(0);
|
final Account account = accounts.get(0);
|
||||||
callFactory.get().setAccount(account.getId(), false);
|
final GerritCall call = callFactory.get();
|
||||||
|
call.noCache();
|
||||||
final StringBuffer url = req.getRequestURL();
|
call.setAccount(account.getId(), false);
|
||||||
url.setLength(url.lastIndexOf("/")); // drop 'become'
|
rsp.sendRedirect(urlProvider.get());
|
||||||
rsp.sendRedirect(url.toString());
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
|
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.http;
|
|||||||
import static com.google.inject.Stage.PRODUCTION;
|
import static com.google.inject.Stage.PRODUCTION;
|
||||||
|
|
||||||
import com.google.gerrit.client.reviewdb.Account;
|
import com.google.gerrit.client.reviewdb.Account;
|
||||||
import com.google.gerrit.client.reviewdb.SystemConfig.LoginType;
|
|
||||||
import com.google.gerrit.client.rpc.Common;
|
import com.google.gerrit.client.rpc.Common;
|
||||||
import com.google.gerrit.client.rpc.Common.CurrentAccountImpl;
|
import com.google.gerrit.client.rpc.Common.CurrentAccountImpl;
|
||||||
import com.google.gerrit.git.PushAllProjectsOp;
|
import com.google.gerrit.git.PushAllProjectsOp;
|
||||||
@@ -123,15 +122,19 @@ public class GerritServletConfig extends GuiceServletContextListener {
|
|||||||
final List<Module> modules = new ArrayList<Module>();
|
final List<Module> modules = new ArrayList<Module>();
|
||||||
modules.add(new WebModule(sshInfo));
|
modules.add(new WebModule(sshInfo));
|
||||||
|
|
||||||
if (BecomeAnyAccountLoginServlet.isAllowed()) {
|
switch (auth.getLoginType()) {
|
||||||
modules.add(new ServletModule() {
|
case OPENID:
|
||||||
@Override
|
modules.add(new OpenIdModule());
|
||||||
protected void configureServlets() {
|
break;
|
||||||
serve("/become").with(BecomeAnyAccountLoginServlet.class);
|
|
||||||
}
|
case DEVELOPMENT_BECOME_ANY_ACCOUNT:
|
||||||
});
|
modules.add(new ServletModule() {
|
||||||
} else if (auth.getLoginType() == LoginType.OPENID) {
|
@Override
|
||||||
modules.add(new OpenIdModule());
|
protected void configureServlets() {
|
||||||
|
serve("/become").with(BecomeAnyAccountLoginServlet.class);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sysInjector.createChildInjector(modules);
|
return sysInjector.createChildInjector(modules);
|
||||||
|
|||||||
Reference in New Issue
Block a user