1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-17 16:53:25 +00:00

refactoring entry and path usage

This commit is contained in:
Kyle Spearrin
2017-05-18 08:29:06 -04:00
parent 5fe45f0524
commit badee2d49c
3 changed files with 62 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Bit.Core.Services;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.DirectoryServices;
@@ -15,20 +16,44 @@ namespace Bit.Core.Models
public string Path { get; set; }
public string Username { get; set; }
public EncryptedData Password { get; set; }
[JsonIgnore]
public string ServerPath => $"LDAP://{Address}:{Port}/{Path}";
public Enums.DirectoryType Type { get; set; } = Enums.DirectoryType.ActiveDirectory;
public DirectoryEntry GetDirectoryEntry()
public DirectoryEntry GetUserDirectoryEntry()
{
return GetPathedDirectoryEntry(SettingsService.Instance.Sync.Ldap.UserPath);
}
public DirectoryEntry GetGroupDirectoryEntry()
{
return GetPathedDirectoryEntry(SettingsService.Instance.Sync.Ldap.GroupPath);
}
public DirectoryEntry GetPathedDirectoryEntry(string pathPrefix = null)
{
var path = Path;
if(!string.IsNullOrWhiteSpace(pathPrefix))
{
path = string.Concat(pathPrefix, ",", path);
}
return GetDirectoryEntry(path);
}
public DirectoryEntry GetDirectoryEntry(string path = null)
{
if(Password == null && string.IsNullOrWhiteSpace(Username))
{
return new DirectoryEntry(ServerPath);
return new DirectoryEntry(ServerPath(path));
}
else
{
return new DirectoryEntry(ServerPath, Username, Password.DecryptToString(), AuthenticationTypes.None);
return new DirectoryEntry(ServerPath(path), Username, Password.DecryptToString(), AuthenticationTypes.None);
}
}
private string ServerPath(string path)
{
return $"LDAP://{Address}:{Port}/{path}";
}
}
}