Merge "Add Switch Account link to the current user popdown"
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 3c35054..339b0c0 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -335,7 +335,17 @@
 +
 Target for the "Obtain Password" link.  Used only when `auth.type` is
 `LDAP`, `LDAP_BIND` or `CUSTOM_EXTENSION`.
+
+[[auth.switchAccountUrl]]auth.switchAccountUrl::
 +
+URL to switch user identities and login as a different account than
+the currently active account.  This is disabled by default except when
+`auth.type` is `OPENID` and `DEVELOPMENT_BECOME_ANY_ACCOUNT`.  If set
+the "Switch Account" link is displayed next to "Sign Out".
++
+When `auth.type` does not normally enable this URL administrators may
+set this to `login/` or `$canonicalWebUrl/login`, allowing users to
+begin a new web session.
 
 [[auth.cookiePath]]auth.cookiePath::
 +
diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java
index 324f00b..f85e333 100644
--- a/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java
+++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java
@@ -28,6 +28,7 @@
   protected String registerText;
   protected String loginUrl;
   protected String loginText;
+  protected String switchAccountUrl;
   protected String httpPasswordUrl;
   protected String reportBugUrl;
   protected boolean gitBasicAuth;
@@ -75,6 +76,14 @@
     registerUrl = u;
   }
 
+  public String getSwitchAccountUrl() {
+    return switchAccountUrl;
+  }
+
+  public void setSwitchAccountUrl(String u) {
+    switchAccountUrl = u;
+  }
+
   public String getRegisterText() {
     return registerText;
   }
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.java
index 683f058..fb72085 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.java
@@ -18,9 +18,7 @@
 
 public interface GerritConstants extends Constants {
   String menuSignIn();
-  String menuSignOut();
   String menuRegister();
-  String menuSettings();
   String reportBug();
 
   String signInDialogTitle();
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.properties
index defc7e4..6f3dca5 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.properties
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GerritConstants.properties
@@ -1,7 +1,5 @@
 menuSignIn = Sign In
-menuSignOut = Sign Out
 menuRegister = Register
-menuSettings = Settings
 reportBug = Report Bug
 
 signInDialogTitle = Code Review - Sign In
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/UserPopupPanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/UserPopupPanel.java
index d5bbd17..90348db 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/UserPopupPanel.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/UserPopupPanel.java
@@ -16,11 +16,12 @@
 
 import com.google.gerrit.client.account.AccountInfo;
 import com.google.gerrit.client.ui.InlineHyperlink;
+import com.google.gerrit.reviewdb.client.AuthType;
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.AnchorElement;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.user.client.ui.Anchor;
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.Widget;
 import com.google.gwtexpui.user.client.PluginSafePopupPanel;
@@ -33,7 +34,8 @@
   @UiField Label userName;
   @UiField Label userEmail;
   @UiField Element userLinks;
-  @UiField Anchor logout;
+  @UiField AnchorElement switchAccount;
+  @UiField AnchorElement logout;
   @UiField InlineHyperlink settings;
 
   public UserPopupPanel(AccountInfo account, boolean canLogOut,
@@ -49,11 +51,22 @@
       userEmail.setText(account.email());
     }
     if (showSettingsLink) {
+      if (Gerrit.getConfig().getSwitchAccountUrl() != null) {
+        switchAccount.setHref(Gerrit.getConfig().getSwitchAccountUrl());
+      } else if (Gerrit.getConfig().getAuthType() == AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT
+          || Gerrit.getConfig().getAuthType() == AuthType.OPENID) {
+        switchAccount.setHref(Gerrit.selfRedirect("/login/"));
+      } else {
+        switchAccount.removeFromParent();
+        switchAccount = null;
+      }
       if (canLogOut) {
         logout.setHref(Gerrit.selfRedirect("/logout"));
       } else {
-        logout.setVisible(false);
+        logout.removeFromParent();
+        logout = null;
       }
+
     } else {
       settings.removeFromParent();
       settings = null;
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/UserPopupPanel.ui.xml b/gerrit-gwtui/src/main/java/com/google/gerrit/client/UserPopupPanel.ui.xml
index 4a4f4ca..cd51485 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/UserPopupPanel.ui.xml
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/UserPopupPanel.ui.xml
@@ -19,8 +19,6 @@
   xmlns:g='urn:import:com.google.gwt.user.client.ui'
   xmlns:gerrit='urn:import:com.google.gerrit.client'
   xmlns:u='urn:import:com.google.gerrit.client.ui'>
-  <ui:with field='constants' type='com.google.gerrit.client.GerritConstants'/>
-
   <ui:style>
     .panel {
       padding: 8px;
@@ -36,16 +34,20 @@
     .userName {
       font-weight: bold;
     }
-    .userLinks {
-      min-width: 175px;
-    }
     .email {
       padding-bottom: 6px;
     }
-    .logout {
-      padding-left: 16px;
+    .userLinks {
+      min-width: 250px;
+    }
+    .userLinksRight {
       float: right;
     }
+    .switchAccount {
+      border-right: 1px solid black;
+      padding-right: 0.5em;
+      margin-right: 0.5em;
+    }
   </ui:style>
 
   <g:HTMLPanel styleName='{style.panel}'>
@@ -59,9 +61,10 @@
       <u:InlineHyperlink ui:field='settings' targetHistoryToken='/settings/'>
         <ui:msg>Settings</ui:msg>
       </u:InlineHyperlink>
-      <g:Anchor ui:field='logout' styleName="{style.logout}">
-        <ui:text from='{constants.menuSignOut}' />
-      </g:Anchor>
+      <span class='{style.userLinksRight}'>
+        <a ui:field='switchAccount' class='{style.switchAccount}'><ui:msg>Switch Account</ui:msg></a
+        ><a ui:field='logout'><ui:msg>Sign Out</ui:msg></a>
+      </span>
     </div>
   </g:HTMLPanel>
 </ui:UiBinder>
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
index 208d282..677a615 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java
@@ -106,6 +106,7 @@
       case OPENID_SSO:
         break;
     }
+    config.setSwitchAccountUrl(cfg.getString("auth", null, "switchAccountUrl"));
     config.setUseContributorAgreements(cfg.getBoolean("auth",
         "contributoragreements", false));
     config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));