mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
we can now load the cred repo list
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using mRemoteNG.Config.DataProviders;
|
||||
using mRemoteNG.Config.Serializers.CredentialProviderSerializer;
|
||||
using mRemoteNG.Credential;
|
||||
|
||||
namespace mRemoteNG.Config
|
||||
|
||||
@@ -4,14 +4,14 @@ using System.Xml.Linq;
|
||||
using mRemoteNG.Credential;
|
||||
using mRemoteNG.Credential.Repositories;
|
||||
|
||||
namespace mRemoteNG.Config
|
||||
namespace mRemoteNG.Config.Serializers.CredentialProviderSerializer
|
||||
{
|
||||
public class CredentialRepositoryListDeserializer
|
||||
{
|
||||
public IEnumerable<ICredentialRepository> Deserialize(string xml)
|
||||
{
|
||||
var xdoc = XDocument.Parse(xml);
|
||||
var repoEntries = xdoc.Descendants("Repository");
|
||||
var repoEntries = xdoc.Descendants("CredentialRepository");
|
||||
return repoEntries.Select(CredentialRepositoryFactory.Build);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,18 @@ namespace mRemoteNG.Credential
|
||||
{
|
||||
public class CredentialRepositoryConfig : ICredentialRepositoryConfig
|
||||
{
|
||||
public Guid Id { get; } = Guid.NewGuid();
|
||||
public string TypeName { get; }
|
||||
public Guid Id { get; }
|
||||
public string TypeName { get; set; } = "";
|
||||
public string Source { get; set; } = "";
|
||||
public SecureString Key { get; set; } = new SecureString();
|
||||
|
||||
public CredentialRepositoryConfig(string typeName)
|
||||
public CredentialRepositoryConfig() : this(Guid.NewGuid())
|
||||
{
|
||||
TypeName = typeName;
|
||||
}
|
||||
|
||||
public CredentialRepositoryConfig(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,21 @@ namespace mRemoteNG.Credential.Repositories
|
||||
{
|
||||
public static ICredentialRepository Build(XElement repositoryXElement)
|
||||
{
|
||||
if (repositoryXElement.Name.LocalName == "")
|
||||
var typeName = repositoryXElement.Attribute("TypeName")?.Value;
|
||||
if (typeName == "Xml")
|
||||
return BuildXmlRepository(repositoryXElement);
|
||||
throw new Exception("Could not build repository for the specified type");
|
||||
}
|
||||
|
||||
private static ICredentialRepository BuildXmlRepository(XElement repositoryXElement)
|
||||
{
|
||||
var config = new CredentialRepositoryConfig(repositoryXElement.Name.LocalName)
|
||||
var stringId = repositoryXElement.Attribute("Id")?.Value;
|
||||
Guid id;
|
||||
Guid.TryParse(stringId, out id);
|
||||
if (id.Equals(Guid.Empty)) id = Guid.NewGuid();
|
||||
var config = new CredentialRepositoryConfig(id)
|
||||
{
|
||||
TypeName = repositoryXElement.Attribute("TypeName")?.Value,
|
||||
Source = repositoryXElement.Attribute("Source")?.Value
|
||||
};
|
||||
var dataProvider = new FileDataProvider("");
|
||||
|
||||
@@ -9,6 +9,6 @@ namespace mRemoteNG.UI.Forms.CredentialManagerPages.CredentialRepositorySelector
|
||||
{
|
||||
public string Text { get; set; } = "KeePass";
|
||||
public Image Image { get; } = Resources.keepass_32x32;
|
||||
public ICredentialRepositoryConfig Config { get; } = new CredentialRepositoryConfig("KeePass");
|
||||
public ICredentialRepositoryConfig Config { get; } = new CredentialRepositoryConfig {TypeName = "KeePass"};
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,6 @@ namespace mRemoteNG.UI.Forms.CredentialManagerPages.CredentialRepositorySelector
|
||||
{
|
||||
public string Text { get; set; } = "XML";
|
||||
public Image Image { get; } = Resources.xml;
|
||||
public ICredentialRepositoryConfig Config { get; } = new CredentialRepositoryConfig("XML");
|
||||
public ICredentialRepositoryConfig Config { get; } = new CredentialRepositoryConfig {TypeName = "Xml"};
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using mRemoteNG.App.Initialization;
|
||||
using mRemoteNG.Config;
|
||||
using mRemoteNG.Config.DataProviders;
|
||||
using mRemoteNG.Config.Putty;
|
||||
using mRemoteNG.Config.Serializers.CredentialProviderSerializer;
|
||||
using mRemoteNG.Config.Settings;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Credential;
|
||||
@@ -137,7 +138,7 @@ namespace mRemoteNG.UI.Forms
|
||||
|
||||
Startup.Instance.InitializeProgram(messageCollector);
|
||||
|
||||
var repoFilePath = "";
|
||||
var repoFilePath = @"C:\Users\David\Documents\Repositories\mRemoteNG\mRemoteV1\bin\Debug Portable\credentialRepositories.xml";
|
||||
var credRepoListLoader = new CredentialRepositoryListLoader(new FileDataProvider(repoFilePath), new CredentialRepositoryListDeserializer());
|
||||
foreach (var repository in credRepoListLoader.Load())
|
||||
Runtime.CredentialProviderCatalog.AddProvider(repository);
|
||||
|
||||
Reference in New Issue
Block a user