private ICollection <string> GetCredentialsInUseLocations(CredentialsProfile credentials) { HashSet <string> inUseLocations = new HashSet <string>(); ICollection nodes = (base.AssociatedNode.FileGroup == null) ? ((IList)ServerTree.Instance.Nodes) : ((IList) new FileGroup[1] { base.AssociatedNode.FileGroup }); foreach (TabPage tabPage in base.TabPages) { ICredentialsTabPage credentialsTabPage = tabPage as ICredentialsTabPage; if (credentialsTabPage != null && credentialsTabPage.Credentials == credentials) { inUseLocations.Add("{0}.{1}".InvariantFormat(Text, tabPage.Text)); } } nodes.VisitNodes(delegate(RdcTreeNode node) { if (node is VirtualGroup) { return(NodeVisitorResult.NoRecurse); } if (node.LogonCredentials.DirectlyReferences(credentials)) { inUseLocations.Add("{0}.{1}".InvariantFormat(node.FullPath, "登录证书")); } if (node.GatewaySettings.DirectlyReferences(credentials)) { inUseLocations.Add("{0}.{1}".InvariantFormat(node.FullPath, "网关配置")); } return(NodeVisitorResult.Continue); }); return(inUseLocations); }
private void SaveProfileButton_Click(object sender, EventArgs e) { string qualifiedUserName = GetQualifiedUserName(UserNameTextBox.Text, DomainTextBox.Text); using (SaveCredentialsDialog saveCredentialsDialog = new SaveCredentialsDialog(_file, qualifiedUserName)) { if (saveCredentialsDialog.ShowDialog() == DialogResult.OK) { ProfileScope profileScope = saveCredentialsDialog.ProfileScope; CredentialsStore credentialsProfiles = Program.CredentialsProfiles; if (profileScope == ProfileScope.File) { credentialsProfiles = _file.CredentialsProfiles; } qualifiedUserName = saveCredentialsDialog.ProfileName; bool flag = !credentialsProfiles.Contains(qualifiedUserName); CredentialsProfile credentialsProfile2 = credentialsProfiles[qualifiedUserName] = new CredentialsProfile(qualifiedUserName, profileScope, UserNameTextBox.Text, PasswordTextBox.Text, DomainTextBox.Text); string qualifiedName = credentialsProfile2.QualifiedName; if (flag) { ProfileComboBox.AddItem(qualifiedName, credentialsProfile2); } else { ProfileComboBox.ReplaceItem(qualifiedName, credentialsProfile2); } ProfileComboBox.SelectedValue = credentialsProfile2; } } ProfileComboBox.Focus(); }
private void DeleteCredentials() { int selectedIndex = _credentialsListBox.SelectedIndex; if (selectedIndex == -1) { return; } CredentialsProfile credentialsProfile = _credentialsListBox.Items[selectedIndex] as CredentialsProfile; ICollection <string> credentialsInUseLocations = GetCredentialsInUseLocations(credentialsProfile); if (credentialsInUseLocations.Count > 0) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(credentialsProfile.ProfileName + " 在这些节点中正在使用:").AppendLine(); foreach (string item in credentialsInUseLocations) { stringBuilder.AppendLine(item); } stringBuilder.AppendLine().AppendLine("你确定你要删除它?"); if (FormTools.YesNoDialog(stringBuilder.ToString()) != DialogResult.Yes) { return; } } _credentialsStore.Remove(credentialsProfile.ProfileName); _credentialsListBox.Items.RemoveAt(selectedIndex); RevertDeletedCredentials(credentialsProfile); }
public static LogonSettingsDialog NewEditCredentialsDialog(CredentialsProfile credentials) { LogonSettingsDialog logonSettingsDialog = new LogonSettingsDialog("Edit Credentials", "Save"); int rowIndex = 0; int tabIndex = 0; logonSettingsDialog._logonCredentialsUI.AddControlsToParent(logonSettingsDialog, LogonCredentialsDialogOptions.None, ref rowIndex, ref tabIndex); logonSettingsDialog._logonCredentialsUI.EnableDisableControls(enable: true); logonSettingsDialog._logonCredentialsUI.InitFromCredentials(credentials); logonSettingsDialog.FinalizeLayout(rowIndex, tabIndex); return(logonSettingsDialog); }
public void ReadXml(XmlNode xmlNode, ProfileScope scope, RdcTreeNode node, ICollection <string> errors) { foreach (XmlNode childNode in xmlNode.ChildNodes) { LogonCredentials logonCredentials = new LogonCredentials("", "credentialsProfile"); logonCredentials.ReadXml(childNode, node, errors); ILogonCredentials logonCredentials2 = logonCredentials; CredentialsProfile credentialsProfile = new CredentialsProfile(logonCredentials2.ProfileName, scope, logonCredentials2.UserName, logonCredentials2.Password, logonCredentials2.Domain); this[logonCredentials2.ProfileName] = credentialsProfile; Encryption.DeferDecryption(credentialsProfile, node, credentialsProfile.QualifiedName); } }
private void AddButton_Click(object sender, EventArgs e) { using (AddCredentialsDialog addCredentialsDialog = new AddCredentialsDialog(base.AssociatedNode)) { if (addCredentialsDialog.ShowDialog() == DialogResult.OK) { CredentialsProfile credentialsProfile = new CredentialsProfile(addCredentialsDialog.ProfileName, addCredentialsDialog.ProfileScope, addCredentialsDialog.UserName, addCredentialsDialog.Password.Value, addCredentialsDialog.Domain); if (!_credentialsStore.Contains(credentialsProfile.ProfileName)) { _credentialsListBox.Items.Add(credentialsProfile); } _credentialsStore[credentialsProfile.ProfileName] = credentialsProfile; } } }
private void PopulateCredentialsProfilesWorker() { CredentialsProfile selectedValue = ProfileComboBox.SelectedValue; ProfileComboBox.ClearItems(); ProfileComboBox.AddItem("Custom", new CredentialsProfile("Custom", ProfileScope.Local, string.Empty, string.Empty, string.Empty)); ProfileComboBox.SelectedIndex = 0; PopulateComboFromStore(Program.CredentialsProfiles); _globalStoreChangeId = Program.CredentialsProfiles.ChangeId; if (_file != null) { PopulateComboFromStore(_file.CredentialsProfiles); _fileStoreChangeId = _file.CredentialsProfiles.ChangeId; } ProfileComboBox.SelectedValue = selectedValue; }
private void EditButton_Click(object sender, EventArgs e) { int selectedIndex = _credentialsListBox.SelectedIndex; if (selectedIndex != -1) { CredentialsProfile credentialsProfile = _credentialsListBox.Items[selectedIndex] as CredentialsProfile; using (LogonSettingsDialog logonSettingsDialog = LogonSettingsDialog.NewEditCredentialsDialog(credentialsProfile)) { if (logonSettingsDialog.ShowDialog() == DialogResult.OK) { PasswordSetting password = logonSettingsDialog.PasswordChanged ? logonSettingsDialog.Password : credentialsProfile.Password; credentialsProfile = new CredentialsProfile(credentialsProfile.ProfileName, credentialsProfile.ProfileScope, logonSettingsDialog.UserName, password, logonSettingsDialog.Domain); _credentialsStore[credentialsProfile.ProfileName] = credentialsProfile; _credentialsListBox.Items[selectedIndex] = credentialsProfile; } } } }
internal bool ResolveCredentials(LogonCredentials logonCredentials) { if (logonCredentials.ProfileName.Scope == ProfileScope.Local) { if (!LogonCredentials.IsCustomProfile(logonCredentials.ProfileName.Value)) { logonCredentials.ProfileName.Value = "Custom"; } return(true); } CredentialsProfile credentialsProfile = LookupCredentialsProfile(logonCredentials); if (credentialsProfile != null) { logonCredentials.UserName.Value = credentialsProfile.UserName; logonCredentials.Domain.Value = credentialsProfile.Domain; if (credentialsProfile.IsDecrypted) { logonCredentials.Password.SetPlainText(credentialsProfile.Password.Value); } return(true); } return(false); }
private void RevertDeletedCredentials(CredentialsProfile credentials) { ICollection nodes = (base.AssociatedNode.FileGroup == null) ? ((IList)ServerTree.Instance.Nodes) : ((IList) new FileGroup[1] { base.AssociatedNode.FileGroup }); nodes.VisitNodes(delegate(RdcTreeNode node) { if (node is VirtualGroup) { return(NodeVisitorResult.NoRecurse); } if (node.LogonCredentials.DirectlyReferences(credentials)) { node.LogonCredentials.ProfileName.Reset(); } if (node.GatewaySettings.DirectlyReferences(credentials)) { node.GatewaySettings.ProfileName.Reset(); } return(NodeVisitorResult.Continue); }); }
public bool TryGetValue(string name, out CredentialsProfile profile) { return(_profiles.TryGetValue(name, out profile)); }