mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
saving and loading default credential now works
This commit is contained in:
@@ -46,7 +46,6 @@ namespace mRemoteNG.Config.Settings
|
||||
SetPuttyPath();
|
||||
SetShowSystemTrayIcon();
|
||||
SetAutoSave();
|
||||
SetConDefaultPassword();
|
||||
LoadPanelsFromXml();
|
||||
LoadExternalAppsFromXml();
|
||||
SetAlwaysShowPanelTabs();
|
||||
@@ -62,12 +61,6 @@ namespace mRemoteNG.Config.Settings
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetConDefaultPassword()
|
||||
{
|
||||
var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
|
||||
mRemoteNG.Settings.Default.ConDefaultPassword = cryptographyProvider.Decrypt(mRemoteNG.Settings.Default.ConDefaultPassword, Runtime.EncryptionKey);
|
||||
}
|
||||
|
||||
private static void SetAlwaysShowPanelTabs()
|
||||
{
|
||||
if (mRemoteNG.Settings.Default.AlwaysShowPanelTabs)
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml;
|
||||
using mRemoteNG.App.Info;
|
||||
using mRemoteNG.Security.SymmetricEncryption;
|
||||
using mRemoteNG.Tools;
|
||||
using mRemoteNG.UI.Forms;
|
||||
using static mRemoteNG.App.Runtime;
|
||||
@@ -60,11 +59,6 @@ namespace mRemoteNG.Config.Settings
|
||||
mRemoteNG.Settings.Default.QuickyTBParentDock = with1.tsQuickConnect.Parent.Dock.ToString();
|
||||
}
|
||||
mRemoteNG.Settings.Default.QuickyTBVisible = with1.tsQuickConnect.Visible;
|
||||
|
||||
var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
|
||||
mRemoteNG.Settings.Default.ConDefaultPassword =
|
||||
cryptographyProvider.Encrypt(Convert.ToString(mRemoteNG.Settings.Default.ConDefaultPassword), EncryptionKey);
|
||||
|
||||
mRemoteNG.Settings.Default.Save();
|
||||
|
||||
SavePanelsToXML();
|
||||
|
||||
@@ -26,15 +26,14 @@ namespace mRemoteNG.Connection
|
||||
{
|
||||
var propertyFromSource = typeof(TSource).GetProperty(propertyNameMutator(property.Name));
|
||||
var valueFromSource = propertyFromSource.GetValue(sourceInstance, null);
|
||||
|
||||
var descriptor = TypeDescriptor.GetProperties(Instance)[property.Name];
|
||||
var converter = descriptor.Converter;
|
||||
if (converter != null && converter.CanConvertFrom(valueFromSource.GetType()))
|
||||
property.SetValue(Instance, converter.ConvertFrom(valueFromSource), null);
|
||||
else
|
||||
property.SetValue(Instance, valueFromSource, null);
|
||||
var typeConverter = TypeDescriptor.GetConverter(property.PropertyType);
|
||||
if (typeConverter.CanConvertFrom(valueFromSource.GetType()))
|
||||
property.SetValue(Instance, typeConverter.ConvertFrom(valueFromSource), null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Runtime.MessageCollector?.AddExceptionStackTrace($"Error loading default connectioninfo property {property.Name}", ex);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +47,9 @@ namespace mRemoteNG.Connection
|
||||
{
|
||||
var propertyFromDestination = typeof(TDestination).GetProperty(propertyNameMutator(property.Name));
|
||||
var localValue = property.GetValue(Instance, null);
|
||||
var convertedValue = Convert.ChangeType(localValue, propertyFromDestination.PropertyType);
|
||||
var typeConverter = TypeDescriptor.GetConverter(property.PropertyType);
|
||||
if (!typeConverter.CanConvertTo(propertyFromDestination.PropertyType)) continue;
|
||||
var convertedValue = typeConverter.ConvertTo(localValue, propertyFromDestination.PropertyType);
|
||||
propertyFromDestination.SetValue(destinationInstance, convertedValue, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
44
mRemoteV1/Credential/CredentialRecordTypeConverter.cs
Normal file
44
mRemoteV1/Credential/CredentialRecordTypeConverter.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using mRemoteNG.App;
|
||||
|
||||
|
||||
namespace mRemoteNG.Credential
|
||||
{
|
||||
public class CredentialRecordTypeConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(Guid) ||
|
||||
base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
return destinationType == typeof(Guid) ||
|
||||
destinationType == typeof(ICredentialRecord) ||
|
||||
base.CanConvertTo(context, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (value is ICredentialRecord && destinationType == typeof(Guid))
|
||||
return ((ICredentialRecord) value).Id;
|
||||
if (value is ICredentialRecord && destinationType == typeof(ICredentialRecord))
|
||||
return value;
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value is Guid)
|
||||
{
|
||||
var matchedCredentials = Runtime.CredentialManager.GetCredentialRecords().Where(record => record.Id.Equals(value)).ToArray();
|
||||
return matchedCredentials.Any() ? matchedCredentials.First() : null;
|
||||
}
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Security;
|
||||
|
||||
|
||||
namespace mRemoteNG.Credential
|
||||
{
|
||||
[TypeConverter(typeof(CredentialRecordTypeConverter))]
|
||||
public interface ICredentialRecord
|
||||
{
|
||||
Guid Id { get; }
|
||||
|
||||
48
mRemoteV1/Properties/Settings.Designer.cs
generated
48
mRemoteV1/Properties/Settings.Designer.cs
generated
@@ -455,42 +455,6 @@ namespace mRemoteNG {
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string ConDefaultUsername {
|
||||
get {
|
||||
return ((string)(this["ConDefaultUsername"]));
|
||||
}
|
||||
set {
|
||||
this["ConDefaultUsername"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string ConDefaultPassword {
|
||||
get {
|
||||
return ((string)(this["ConDefaultPassword"]));
|
||||
}
|
||||
set {
|
||||
this["ConDefaultPassword"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string ConDefaultDomain {
|
||||
get {
|
||||
return ((string)(this["ConDefaultDomain"]));
|
||||
}
|
||||
set {
|
||||
this["ConDefaultDomain"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("RDP")]
|
||||
@@ -2386,5 +2350,17 @@ namespace mRemoteNG {
|
||||
this["InhDefaultCredentialRecord"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("00000000-0000-0000-0000-000000000000")]
|
||||
public global::System.Guid ConDefaultCredentialRecord {
|
||||
get {
|
||||
return ((global::System.Guid)(this["ConDefaultCredentialRecord"]));
|
||||
}
|
||||
set {
|
||||
this["ConDefaultCredentialRecord"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,15 +110,6 @@
|
||||
<Setting Name="ConDefaultDescription" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="ConDefaultUsername" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="ConDefaultPassword" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="ConDefaultDomain" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="ConDefaultProtocol" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)">RDP</Value>
|
||||
</Setting>
|
||||
@@ -593,5 +584,8 @@
|
||||
<Setting Name="InhDefaultCredentialRecord" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
<Setting Name="ConDefaultCredentialRecord" Type="System.Guid" Scope="User">
|
||||
<Value Profile="(Default)">00000000-0000-0000-0000-000000000000</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -213,7 +213,7 @@ namespace mRemoteNG.UI.Forms
|
||||
}
|
||||
|
||||
LoadCredentials();
|
||||
|
||||
LoadDefaultConnectionCredentials();
|
||||
Runtime.LoadConnections();
|
||||
|
||||
Windows.TreePanel.Focus();
|
||||
@@ -1355,5 +1355,12 @@ namespace mRemoteNG.UI.Forms
|
||||
credentialSaver.Save(_credentialManager.GetCredentialRecords(), "tempEncryptionKey".ConvertToSecureString());
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, $"Saved credentials to file: {_credentialFilePath}", true);
|
||||
}
|
||||
|
||||
private void LoadDefaultConnectionCredentials()
|
||||
{
|
||||
var defaultCredId = Settings.Default.ConDefaultCredentialRecord;
|
||||
var matchedCredentials = Runtime.CredentialManager.GetCredentialRecords().Where(record => record.Id.Equals(defaultCredId)).ToArray();
|
||||
DefaultConnectionInfo.Instance.CredentialRecord = matchedCredentials.Any() ? matchedCredentials.First() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,15 +142,6 @@
|
||||
<setting name="ConDefaultDescription" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="ConDefaultUsername" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="ConDefaultPassword" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="ConDefaultDomain" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="ConDefaultProtocol" serializeAs="String">
|
||||
<value>RDP</value>
|
||||
</setting>
|
||||
@@ -613,6 +604,9 @@
|
||||
<setting name="InhDefaultCredentialRecord" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
<setting name="ConDefaultCredentialRecord" serializeAs="String">
|
||||
<value>00000000-0000-0000-0000-000000000000</value>
|
||||
</setting>
|
||||
</mRemoteNG.Settings>
|
||||
</userSettings>
|
||||
<applicationSettings>
|
||||
|
||||
@@ -207,6 +207,7 @@
|
||||
<Compile Include="Credential\CredentialRecord.cs" />
|
||||
<Compile Include="Credential\CredentialListBase.cs" />
|
||||
<Compile Include="Credential\CredentialRecordCatalog.cs" />
|
||||
<Compile Include="Credential\CredentialRecordTypeConverter.cs" />
|
||||
<Compile Include="Credential\ICredentialRecord.cs" />
|
||||
<Compile Include="Credential\ICredentialProviderCatalog.cs" />
|
||||
<Compile Include="Credential\ICredentialProvider.cs" />
|
||||
|
||||
Reference in New Issue
Block a user