Expose all auth config params that are needed by client over REST

The Gerrit Client needs to know about some authentication
configuration parameters of the server in order to render the UI and
enable/disable certain functionality. Some of them are already
provided via the /config/server/info REST endpoint. Add the other auth
parameters to this REST endpoint and adapt the Gerrit Client to
retrieve these parameters via REST. Remove these parameters from the
config that is embedded in the host page data as they are no longer
read from this data structure.

Change-Id: Ia7dc5ea8654b6e63eb577dc3d9ada07ce8d90113
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2015-05-08 10:59:01 +02:00
committed by David Pursehouse
parent f94d06bc25
commit 5a8c9e9649
12 changed files with 165 additions and 157 deletions

View File

@@ -27,6 +27,7 @@ import com.google.gerrit.client.api.ApiGlue;
import com.google.gerrit.client.api.PluginLoader;
import com.google.gerrit.client.changes.ChangeConstants;
import com.google.gerrit.client.changes.ChangeListScreen;
import com.google.gerrit.client.config.AuthInfo;
import com.google.gerrit.client.config.ConfigServerApi;
import com.google.gerrit.client.config.ServerInfo;
import com.google.gerrit.client.extensions.TopMenu;
@@ -623,8 +624,8 @@ public class Gerrit implements EntryPoint {
menuBars = new HashMap<>();
final boolean signedIn = isSignedIn();
final GerritConfig cfg = getConfig();
boolean signedIn = isSignedIn();
AuthInfo authInfo = info().auth();
LinkMenuBar m;
m = new LinkMenuBar();
@@ -718,9 +719,9 @@ public class Gerrit implements EntryPoint {
}
if (signedIn) {
whoAmI(!info().auth().isClientSslCertLdap());
whoAmI(!authInfo.isClientSslCertLdap());
} else {
switch (info().auth().authType()) {
switch (authInfo.authType()) {
case CLIENT_SSL_CERT_LDAP:
break;
@@ -763,18 +764,22 @@ public class Gerrit implements EntryPoint {
case HTTP:
case HTTP_LDAP:
if (cfg.getLoginUrl() != null) {
final String signinText = cfg.getLoginText() == null ? C.menuSignIn() : cfg.getLoginText();
menuRight.add(anchor(signinText, cfg.getLoginUrl()));
if (authInfo.loginUrl() != null) {
String signinText = authInfo.loginText() == null
? C.menuSignIn()
: authInfo.loginText();
menuRight.add(anchor(signinText, authInfo.loginUrl()));
}
break;
case LDAP:
case LDAP_BIND:
case CUSTOM_EXTENSION:
if (cfg.getRegisterUrl() != null) {
final String registerText = cfg.getRegisterText() == null ? C.menuRegister() : cfg.getRegisterText();
menuRight.add(anchor(registerText, cfg.getRegisterUrl()));
if (authInfo.registerUrl() != null) {
String registerText = authInfo.registerText() == null
? C.menuRegister()
: authInfo.registerText();
menuRight.add(anchor(registerText, authInfo.registerUrl()));
}
menuRight.addItem(C.menuSignIn(), new Command() {
@Override

View File

@@ -50,8 +50,8 @@ public class UserPopupPanel extends PluginSafePopupPanel {
userEmail.setText(account.email());
}
if (showSettingsLink) {
if (Gerrit.getConfig().getSwitchAccountUrl() != null) {
switchAccount.setHref(Gerrit.getConfig().getSwitchAccountUrl());
if (Gerrit.info().auth().switchAccountUrl() != null) {
switchAccount.setHref(Gerrit.info().auth().switchAccountUrl());
} else if (Gerrit.info().auth().isDev()
|| Gerrit.info().auth().isOpenId()) {
switchAccount.setHref(Gerrit.selfRedirect("/login/"));

View File

@@ -101,7 +101,7 @@ class ContactPanelShort extends Composite {
int row = 0;
if (!Gerrit.info().auth().canEdit(FieldName.USER_NAME)
&& Gerrit.getConfig().siteHasUsernames()) {
&& Gerrit.info().auth().siteHasUsernames()) {
infoPlainText.resizeRows(infoPlainText.getRowCount() + 1);
row(infoPlainText, row++, Util.C.userName(), new UsernameField());
}
@@ -109,12 +109,12 @@ class ContactPanelShort extends Composite {
if (!canEditFullName()) {
FlowPanel nameLine = new FlowPanel();
nameLine.add(nameTxt);
if (Gerrit.getConfig().getEditFullNameUrl() != null) {
if (Gerrit.info().auth().editFullNameUrl() != null) {
Button edit = new Button(Util.C.linkEditFullName());
edit.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.open(Gerrit.getConfig().getEditFullNameUrl(), "_blank", null);
Window.open(Gerrit.info().auth().editFullNameUrl(), "_blank", null);
}
});
nameLine.add(edit);

View File

@@ -40,7 +40,7 @@ public class MyPasswordScreen extends SettingsScreen {
protected void onInitUI() {
super.onInitUI();
String url = Gerrit.getConfig().getHttpPasswordUrl();
String url = Gerrit.info().auth().httpPasswordUrl();
if (url != null) {
Anchor link = new Anchor();
link.setText(Util.C.linkObtainPassword());

View File

@@ -61,13 +61,13 @@ public class MyProfileScreen extends SettingsScreen {
fieldIdx = 1;
}
info = new Grid((Gerrit.getConfig().siteHasUsernames() ? 1 : 0) + 4, 2);
info = new Grid((Gerrit.info().auth().siteHasUsernames() ? 1 : 0) + 4, 2);
info.setStyleName(Gerrit.RESOURCES.css().infoBlock());
info.addStyleName(Gerrit.RESOURCES.css().accountInfoBlock());
h.add(info);
int row = 0;
if (Gerrit.getConfig().siteHasUsernames()) {
if (Gerrit.info().auth().siteHasUsernames()) {
infoRow(row++, Util.C.userName());
}
infoRow(row++, Util.C.fullName());
@@ -110,7 +110,7 @@ public class MyProfileScreen extends SettingsScreen {
});
int row = 0;
if (Gerrit.getConfig().siteHasUsernames()) {
if (Gerrit.info().auth().siteHasUsernames()) {
info.setWidget(row++, fieldIdx, new UsernameField());
}
info.setText(row++, fieldIdx, account.getFullName());

View File

@@ -29,7 +29,7 @@ public abstract class SettingsScreen extends MenuScreen {
if (Gerrit.getConfig().getSshdAddress() != null) {
link(Util.C.tabSshKeys(), PageLinks.SETTINGS_SSHKEYS);
}
if (Gerrit.getConfig().isHttpPasswordSettingsEnabled()) {
if (Gerrit.info().auth().isHttpPasswordSettingsEnabled()) {
link(Util.C.tabHttpAccess(), PageLinks.SETTINGS_HTTP_PASSWORD);
}
link(Util.C.tabWebIdentities(), PageLinks.SETTINGS_WEBIDENT);

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.client.config;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
@@ -28,6 +29,9 @@ public class AuthInfo extends JavaScriptObject {
return AuthType.valueOf(authTypeRaw());
}
public final boolean isLdap() {
return authType() == AuthType.LDAP || authType() == AuthType.LDAP_BIND;
}
public final boolean isOpenId() {
return authType() == AuthType.OPENID;
}
@@ -44,6 +48,10 @@ public class AuthInfo extends JavaScriptObject {
return authType() == AuthType.CLIENT_SSL_CERT_LDAP;
}
public final boolean isCustomExtension() {
return authType() == AuthType.CUSTOM_EXTENSION;
}
public final boolean canEdit(Account.FieldName f) {
return editableAccountFields().contains(f);
}
@@ -56,8 +64,32 @@ public class AuthInfo extends JavaScriptObject {
return fields;
}
public final boolean siteHasUsernames() {
if (isCustomExtension()
&& httpPasswordUrl() != null
&& !canEdit(FieldName.USER_NAME)) {
return false;
}
return true;
}
public final boolean isHttpPasswordSettingsEnabled() {
if (isLdap() && isGitBasicAuth()) {
return false;
}
return true;
}
public final native boolean useContributorAgreements()
/*-{ return this.use_contributor_agreements || false; }-*/;
public final native String loginUrl() /*-{ return this.login_url; }-*/;
public final native String loginText() /*-{ return this.login_text; }-*/;
public final native String switchAccountUrl() /*-{ return this.switch_account_url; }-*/;
public final native String registerUrl() /*-{ return this.register_url; }-*/;
public final native String registerText() /*-{ return this.register_text; }-*/;
public final native String editFullNameUrl() /*-{ return this.edit_full_name_url; }-*/;
public final native String httpPasswordUrl() /*-{ return this.http_password_url; }-*/;
public final native boolean isGitBasicAuth() /*-{ return this.is_git_basic_auth || false; }-*/;
private final native String authTypeRaw() /*-{ return this.auth_type; }-*/;
private final native JsArrayString _editableAccountFields()
/*-{ return this.editable_account_fields; }-*/;