mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-13 06:43:16 +00:00
stub out sync, connect to server, print results
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.DirectoryServices;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -8,5 +10,71 @@ namespace Bit.Core.Utilities
|
||||
{
|
||||
public static class Sync
|
||||
{
|
||||
public static Task SyncGroupsAsync()
|
||||
{
|
||||
if(Services.SettingsService.Instance.Server == null)
|
||||
{
|
||||
throw new ApplicationException("No configuration for directory server.");
|
||||
}
|
||||
|
||||
if(!Services.AuthService.Instance.Authenticated)
|
||||
{
|
||||
throw new ApplicationException("Not authenticated.");
|
||||
}
|
||||
|
||||
var entry = Services.SettingsService.Instance.Server.GetDirectoryEntry();
|
||||
var searcher = new DirectorySearcher(entry);
|
||||
var result = searcher.FindAll();
|
||||
|
||||
PrintSearchResults(result);
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public static Task SyncUsersAsync()
|
||||
{
|
||||
if(Services.SettingsService.Instance.Server == null)
|
||||
{
|
||||
throw new ApplicationException("No configuration for directory server.");
|
||||
}
|
||||
|
||||
if(!Services.AuthService.Instance.Authenticated)
|
||||
{
|
||||
throw new ApplicationException("Not authenticated.");
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public static async Task SyncAllAsync()
|
||||
{
|
||||
await SyncGroupsAsync();
|
||||
await SyncUsersAsync();
|
||||
}
|
||||
|
||||
private static void PrintSearchResults(SearchResultCollection result)
|
||||
{
|
||||
foreach(SearchResult item in result)
|
||||
{
|
||||
Console.WriteLine(item.Path);
|
||||
|
||||
foreach(DictionaryEntry prop in item.Properties)
|
||||
{
|
||||
Console.Write(" " + prop.Key + ": ");
|
||||
|
||||
var vals = prop.Value as ResultPropertyValueCollection;
|
||||
for(int i = 0; i < vals.Count; i++)
|
||||
{
|
||||
Console.Write(vals[i]);
|
||||
if(i != vals.Count - 1)
|
||||
{
|
||||
Console.Write(" | ");
|
||||
}
|
||||
}
|
||||
|
||||
Console.Write("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user