Merge pull request #1055 from Frezzle/CP-17933

CP-17933: Add feature flag for proxy authentication
This commit is contained in:
Mihaela Stoica 2016-07-06 13:07:11 +01:00 committed by GitHub
commit 16ebd4c496
3 changed files with 81 additions and 24 deletions

View File

@ -80,6 +80,14 @@ namespace XenAdmin.Core
}
}
internal static bool ProxyAuthenticationEnabled
{
get
{
return ReadBool(PROXY_AUTHENTICATION_ENABLED, false);
}
}
public static SSLCertificateTypes AlwaysShowSSLCertificates
{
get
@ -402,6 +410,7 @@ namespace XenAdmin.Core
private const string HEALTH_CHECK_PRODUCT_KEY = "HealthCheckProductKey";
private const string HIDDEN_FEATURES = "HiddenFeatures";
private const string ADDITIONAL_FEATURES = "AdditionalFeatures";
private const string PROXY_AUTHENTICATION_ENABLED = "ProxyAuthenticationEnabled";
}
public enum SSLCertificateTypes { None, Changed, All }

View File

@ -51,8 +51,8 @@ namespace XenAdmin.Dialogs.OptionsPages
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private OptionsDialog optionsDialog;
// used for preventing the event handlers (mainly the SelectUseThisProxyServer function) from being called when loading the settings into the text/check boxes
private bool built = false;
// used for preventing the event handlers from doing anything when changing controls through code
private bool eventsDisabled = true;
public ConnectionOptionsPage()
{
@ -88,6 +88,9 @@ namespace XenAdmin.Dialogs.OptionsPages
ProxyAddressTextBox.Text = Properties.Settings.Default.ProxyAddress;
ProxyPortTextBox.Text = Properties.Settings.Default.ProxyPort.ToString();
BypassForServersCheckbox.Checked = Properties.Settings.Default.BypassProxyForServers;
if (Registry.ProxyAuthenticationEnabled)
{
AuthenticationCheckBox.Checked = Properties.Settings.Default.ProvideProxyAuthentication;
// checks for empty default username/password which starts out unencrypted
@ -95,68 +98,107 @@ namespace XenAdmin.Dialogs.OptionsPages
ProxyUsernameTextBox.Text = string.IsNullOrEmpty(protectedUsername) ? "" : EncryptionUtils.Unprotect(Properties.Settings.Default.ProxyUsername);
string protectedPassword = Properties.Settings.Default.ProxyPassword;
ProxyPasswordTextBox.Text = string.IsNullOrEmpty(protectedPassword) ? "" : EncryptionUtils.Unprotect(Properties.Settings.Default.ProxyPassword);
}
else
{
// hide controls
AuthenticationCheckBox.Visible = false;
ProxyUsernameLabel.Visible = false;
ProxyUsernameTextBox.Visible = false;
ProxyPasswordLabel.Visible = false;
ProxyPasswordTextBox.Visible = false;
}
ConnectionTimeoutNud.Value = Properties.Settings.Default.ConnectionTimeout / 1000;
built = true;
eventsDisabled = false;
}
private void UseProxyRadioButton_CheckedChanged(object sender, EventArgs e)
{
if (eventsDisabled)
return;
enableOK();
}
private void AuthenticationCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (eventsDisabled)
return;
eventsDisabled = true;
if (!AuthenticationCheckBox.Checked)
{
ProxyUsernameTextBox.Clear();
ProxyPasswordTextBox.Clear();
AuthenticationCheckBox.Checked = false; // have to redo this as the 2 Clears above cause the checkbox to recheck
}
SelectUseThisProxyServer();
eventsDisabled = false;
enableOK();
}
private void ProxyAddressTextBox_TextChanged(object sender, EventArgs e)
{
if (eventsDisabled)
return;
SelectUseThisProxyServer();
enableOK();
}
private void ProxyPortTextBox_TextChanged(object sender, EventArgs e)
{
if (eventsDisabled)
return;
SelectUseThisProxyServer();
enableOK();
}
private void ProxyUsernameTextBox_TextChanged(object sender, EventArgs e)
{
SelectUseThisProxyServer();
if (!AuthenticationCheckBox.Checked)
AuthenticationCheckBox.Checked = true;
if (eventsDisabled)
return;
SelectProvideCredentials();
enableOK();
}
private void ProxyPasswordTextBox_TextChanged(object sender, EventArgs e)
{
SelectUseThisProxyServer();
if (!AuthenticationCheckBox.Checked)
AuthenticationCheckBox.Checked = true;
if (eventsDisabled)
return;
SelectProvideCredentials();
enableOK();
}
private void BypassForServersCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (eventsDisabled)
return;
SelectUseThisProxyServer();
enableOK();
}
private void SelectUseThisProxyServer()
{
if (!UseProxyRadioButton.Checked && built)
UseProxyRadioButton.Checked = true;
}
private void SelectProvideCredentials()
{
AuthenticationCheckBox.Checked = true;
UseProxyRadioButton.Checked = true;
}
@ -223,8 +265,12 @@ namespace XenAdmin.Dialogs.OptionsPages
if (ProxyAddressTextBox.Text != Properties.Settings.Default.ProxyAddress && !string.IsNullOrEmpty(ProxyAddressTextBox.Text))
Properties.Settings.Default.ProxyAddress = ProxyAddressTextBox.Text;
if (Registry.ProxyAuthenticationEnabled)
{
Properties.Settings.Default.ProxyUsername = EncryptionUtils.Protect(ProxyUsernameTextBox.Text);
Properties.Settings.Default.ProxyPassword = EncryptionUtils.Protect(ProxyPasswordTextBox.Text);
Properties.Settings.Default.ProvideProxyAuthentication = AuthenticationCheckBox.Checked;
}
try
{
@ -240,9 +286,6 @@ namespace XenAdmin.Dialogs.OptionsPages
if (BypassForServersCheckbox.Checked != Properties.Settings.Default.BypassProxyForServers)
Properties.Settings.Default.BypassProxyForServers = BypassForServersCheckbox.Checked;
if (AuthenticationCheckBox.Checked != Properties.Settings.Default.ProvideProxyAuthentication)
Properties.Settings.Default.ProvideProxyAuthentication = AuthenticationCheckBox.Checked;
// timeout settings
int timeout = (int)ConnectionTimeoutNud.Value;
if (timeout * 1000 != Properties.Settings.Default.ConnectionTimeout)

View File

@ -985,6 +985,11 @@ namespace XenAdmin
public static void ReconfigureConnectionSettings()
{
if (!Registry.ProxyAuthenticationEnabled)
{
Properties.Settings.Default.ProvideProxyAuthentication = false;
Properties.Settings.Default.Save();
}
XenAPI.Session.Proxy = XenAdminConfigManager.Provider.GetProxyFromSettings(null);
}