mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-15 07:43:27 +00:00
sync config and sync result
This commit is contained in:
@@ -42,9 +42,10 @@ namespace Bit.Console
|
|||||||
Con.WriteLine("1. Log in to bitwarden");
|
Con.WriteLine("1. Log in to bitwarden");
|
||||||
Con.WriteLine("2. Log out");
|
Con.WriteLine("2. Log out");
|
||||||
Con.WriteLine("3. Configure directory connection");
|
Con.WriteLine("3. Configure directory connection");
|
||||||
Con.WriteLine("4. Sync directory");
|
Con.WriteLine("4. Configure sync");
|
||||||
Con.WriteLine("5. Start/stop background service");
|
Con.WriteLine("5. Sync directory");
|
||||||
Con.WriteLine("6. Exit");
|
Con.WriteLine("6. Start/stop background service");
|
||||||
|
Con.WriteLine("7. Exit");
|
||||||
Con.WriteLine();
|
Con.WriteLine();
|
||||||
Con.Write("What would you like to do? ");
|
Con.Write("What would you like to do? ");
|
||||||
selection = Con.ReadLine();
|
selection = Con.ReadLine();
|
||||||
@@ -64,11 +65,16 @@ namespace Bit.Console
|
|||||||
await LogOutAsync();
|
await LogOutAsync();
|
||||||
break;
|
break;
|
||||||
case "3":
|
case "3":
|
||||||
case "dir":
|
case "cdir":
|
||||||
case "directory":
|
case "configdirectory":
|
||||||
await DirectoryAsync();
|
await ConfigDirectoryAsync();
|
||||||
break;
|
break;
|
||||||
case "4":
|
case "4":
|
||||||
|
case "csync":
|
||||||
|
case "configsync":
|
||||||
|
await ConfigSyncAsync();
|
||||||
|
break;
|
||||||
|
case "5":
|
||||||
case "sync":
|
case "sync":
|
||||||
await SyncAsync();
|
await SyncAsync();
|
||||||
break;
|
break;
|
||||||
@@ -165,7 +171,7 @@ namespace Bit.Console
|
|||||||
Con.WriteLine("Two-step login is enabled on this account. Please enter your verification code.");
|
Con.WriteLine("Two-step login is enabled on this account. Please enter your verification code.");
|
||||||
Con.Write("Verification code: ");
|
Con.Write("Verification code: ");
|
||||||
token = Con.ReadLine().Trim();
|
token = Con.ReadLine().Trim();
|
||||||
result = await Core.Services.AuthService.Instance.LogInTwoFactorWithHashAsync(token, email,
|
result = await Core.Services.AuthService.Instance.LogInTwoFactorWithHashAsync(token, email,
|
||||||
result.MasterPasswordHash);
|
result.MasterPasswordHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +246,7 @@ namespace Bit.Console
|
|||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Task DirectoryAsync()
|
private static Task ConfigDirectoryAsync()
|
||||||
{
|
{
|
||||||
var config = new ServerConfiguration();
|
var config = new ServerConfiguration();
|
||||||
|
|
||||||
@@ -271,16 +277,6 @@ namespace Bit.Console
|
|||||||
{
|
{
|
||||||
config.Password = new EncryptedData(parameters["p"]);
|
config.Password = new EncryptedData(parameters["p"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parameters.ContainsKey("gf"))
|
|
||||||
{
|
|
||||||
config.GroupFilter = parameters["gf"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(parameters.ContainsKey("uf"))
|
|
||||||
{
|
|
||||||
config.UserFilter = parameters["uf"];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -305,7 +301,76 @@ namespace Bit.Console
|
|||||||
config.Password = new EncryptedData(input);
|
config.Password = new EncryptedData(input);
|
||||||
input = null;
|
input = null;
|
||||||
}
|
}
|
||||||
Con.WriteLine();
|
|
||||||
|
input = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Con.WriteLine();
|
||||||
|
Con.WriteLine();
|
||||||
|
if(string.IsNullOrWhiteSpace(config.Address))
|
||||||
|
{
|
||||||
|
Con.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Con.WriteLine("Invalid input parameters.");
|
||||||
|
Con.ResetColor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Core.Services.SettingsService.Instance.Server = config;
|
||||||
|
Con.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Con.WriteLine("Saved directory server configuration.");
|
||||||
|
Con.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Task ConfigSyncAsync()
|
||||||
|
{
|
||||||
|
var config = new SyncConfiguration();
|
||||||
|
|
||||||
|
if(_usingArgs)
|
||||||
|
{
|
||||||
|
var parameters = ParseParameters();
|
||||||
|
|
||||||
|
config.SyncGroups = parameters.ContainsKey("g");
|
||||||
|
if(parameters.ContainsKey("gf"))
|
||||||
|
{
|
||||||
|
config.GroupFilter = parameters["gf"];
|
||||||
|
}
|
||||||
|
if(parameters.ContainsKey("gn"))
|
||||||
|
{
|
||||||
|
config.GroupNameAttribute = parameters["gn"];
|
||||||
|
}
|
||||||
|
|
||||||
|
config.SyncGroups = parameters.ContainsKey("u");
|
||||||
|
if(parameters.ContainsKey("uf"))
|
||||||
|
{
|
||||||
|
config.UserFilter = parameters["uf"];
|
||||||
|
}
|
||||||
|
if(parameters.ContainsKey("ue"))
|
||||||
|
{
|
||||||
|
config.UserEmailAttribute = parameters["ue"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parameters.ContainsKey("m"))
|
||||||
|
{
|
||||||
|
config.MemberAttribute = parameters["m"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parameters.ContainsKey("c"))
|
||||||
|
{
|
||||||
|
config.CreationDateAttribute = parameters["c"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parameters.ContainsKey("r"))
|
||||||
|
{
|
||||||
|
config.RevisionDateAttribute = parameters["r"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string input;
|
||||||
|
|
||||||
Con.Write("Sync groups? [y]: ");
|
Con.Write("Sync groups? [y]: ");
|
||||||
input = Con.ReadLine().Trim().ToLower();
|
input = Con.ReadLine().Trim().ToLower();
|
||||||
config.SyncGroups = input == "y" || input == "yes" || string.IsNullOrWhiteSpace(input);
|
config.SyncGroups = input == "y" || input == "yes" || string.IsNullOrWhiteSpace(input);
|
||||||
@@ -343,24 +408,34 @@ namespace Bit.Console
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Con.Write("Member Of Attribute [{0}]: ", config.MemberAttribute);
|
||||||
|
input = Con.ReadLine().Trim();
|
||||||
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
config.MemberAttribute = input;
|
||||||
|
}
|
||||||
|
Con.Write("Creation Attribute [{0}]: ", config.CreationDateAttribute);
|
||||||
|
input = Con.ReadLine().Trim();
|
||||||
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
config.CreationDateAttribute = input;
|
||||||
|
}
|
||||||
|
Con.Write("Changed Attribute [{0}]: ", config.RevisionDateAttribute);
|
||||||
|
input = Con.ReadLine().Trim();
|
||||||
|
if(!string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
config.RevisionDateAttribute = input;
|
||||||
|
}
|
||||||
|
|
||||||
input = null;
|
input = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Con.WriteLine();
|
Con.WriteLine();
|
||||||
Con.WriteLine();
|
Con.WriteLine();
|
||||||
if(string.IsNullOrWhiteSpace(config.Address))
|
Core.Services.SettingsService.Instance.Sync = config;
|
||||||
{
|
Con.ForegroundColor = ConsoleColor.Green;
|
||||||
Con.ForegroundColor = ConsoleColor.Red;
|
Con.WriteLine("Saved sync configuration.");
|
||||||
Con.WriteLine("Invalid input parameters.");
|
Con.ResetColor();
|
||||||
Con.ResetColor();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Core.Services.SettingsService.Instance.Server = config;
|
|
||||||
Con.ForegroundColor = ConsoleColor.Green;
|
|
||||||
Con.WriteLine("Saved directory server configuration.");
|
|
||||||
Con.ResetColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
@@ -378,10 +453,21 @@ namespace Bit.Console
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Con.WriteLine("Syncing...");
|
Con.WriteLine("Syncing...");
|
||||||
await Sync.SyncAllAsync();
|
var result = await Sync.SyncAllAsync();
|
||||||
Con.ForegroundColor = ConsoleColor.Green;
|
|
||||||
Con.WriteLine("Syncing complete.");
|
if(result.Success)
|
||||||
Con.ResetColor();
|
{
|
||||||
|
Con.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Con.WriteLine("Syncing complete ({0} users, {1} groups).", result.UserCount, result.GroupCount);
|
||||||
|
Con.ResetColor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Con.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Con.WriteLine("Syncing failed.");
|
||||||
|
Con.WriteLine(result.ErrorMessage);
|
||||||
|
Con.ResetColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,10 +57,12 @@
|
|||||||
<Compile Include="Models\ImportRequest.cs" />
|
<Compile Include="Models\ImportRequest.cs" />
|
||||||
<Compile Include="Models\Organization.cs" />
|
<Compile Include="Models\Organization.cs" />
|
||||||
<Compile Include="Models\ProfileOrganizationResponse.cs" />
|
<Compile Include="Models\ProfileOrganizationResponse.cs" />
|
||||||
|
<Compile Include="Models\SyncConfiguration.cs" />
|
||||||
<Compile Include="Models\ServerConfiguration.cs" />
|
<Compile Include="Models\ServerConfiguration.cs" />
|
||||||
<Compile Include="Models\LoginResult.cs" />
|
<Compile Include="Models\LoginResult.cs" />
|
||||||
<Compile Include="Models\ErrorResponse.cs" />
|
<Compile Include="Models\ErrorResponse.cs" />
|
||||||
<Compile Include="Models\EncryptedData.cs" />
|
<Compile Include="Models\EncryptedData.cs" />
|
||||||
|
<Compile Include="Models\SyncResult.cs" />
|
||||||
<Compile Include="Models\TokenRequest.cs" />
|
<Compile Include="Models\TokenRequest.cs" />
|
||||||
<Compile Include="Models\ProfileResponse.cs" />
|
<Compile Include="Models\ProfileResponse.cs" />
|
||||||
<Compile Include="Models\TokenResponse.cs" />
|
<Compile Include="Models\TokenResponse.cs" />
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ namespace Bit.Core.Models
|
|||||||
{
|
{
|
||||||
public class Organization
|
public class Organization
|
||||||
{
|
{
|
||||||
|
public Organization() { }
|
||||||
|
|
||||||
public Organization(ProfileOrganizationResponseModel org)
|
public Organization(ProfileOrganizationResponseModel org)
|
||||||
{
|
{
|
||||||
Name = org.Name;
|
Name = org.Name;
|
||||||
|
|||||||
@@ -17,19 +17,7 @@ namespace Bit.Core.Models
|
|||||||
public EncryptedData Password { get; set; }
|
public EncryptedData Password { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string ServerPath => $"LDAP://{Address}:{Port}/{Path}";
|
public string ServerPath => $"LDAP://{Address}:{Port}/{Path}";
|
||||||
public string GroupFilter { get; set; } = "(&(objectClass=group))";
|
|
||||||
public string UserFilter { get; set; } = "(&(objectClass=person))";
|
|
||||||
public bool SyncGroups { get; set; } = true;
|
|
||||||
public bool SyncUsers { get; set; } = true;
|
|
||||||
public string Type { get; set; } = "Active Directory";
|
public string Type { get; set; } = "Active Directory";
|
||||||
public string MemberAttribute { get; set; } = "memberOf";
|
|
||||||
public string GroupNameAttribute { get; set; } = "name";
|
|
||||||
public string UserEmailAttribute { get; set; } = "mail";
|
|
||||||
public bool EmailPrefixSuffix { get; set; } = false;
|
|
||||||
public string UserEmailPrefixAttribute { get; set; } = "sAMAccountName";
|
|
||||||
public string UserEmailSuffix { get; set; } = "@companyname.com";
|
|
||||||
public string CreationDateAttribute { get; set; } = "whenCreated";
|
|
||||||
public string RevisionDateAttribute { get; set; } = "whenChanged";
|
|
||||||
|
|
||||||
public DirectoryEntry GetDirectoryEntry()
|
public DirectoryEntry GetDirectoryEntry()
|
||||||
{
|
{
|
||||||
|
|||||||
26
src/Core/Models/SyncConfiguration.cs
Normal file
26
src/Core/Models/SyncConfiguration.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.DirectoryServices;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models
|
||||||
|
{
|
||||||
|
public class SyncConfiguration
|
||||||
|
{
|
||||||
|
public string GroupFilter { get; set; } = "(&(objectClass=group))";
|
||||||
|
public string UserFilter { get; set; } = "(&(objectClass=person))";
|
||||||
|
public bool SyncGroups { get; set; } = true;
|
||||||
|
public bool SyncUsers { get; set; } = true;
|
||||||
|
public string MemberAttribute { get; set; } = "memberOf";
|
||||||
|
public string GroupNameAttribute { get; set; } = "name";
|
||||||
|
public string UserEmailAttribute { get; set; } = "mail";
|
||||||
|
public bool EmailPrefixSuffix { get; set; } = false;
|
||||||
|
public string UserEmailPrefixAttribute { get; set; } = "sAMAccountName";
|
||||||
|
public string UserEmailSuffix { get; set; } = "@companyname.com";
|
||||||
|
public string CreationDateAttribute { get; set; } = "whenCreated";
|
||||||
|
public string RevisionDateAttribute { get; set; } = "whenChanged";
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/Core/Models/SyncResult.cs
Normal file
16
src/Core/Models/SyncResult.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models
|
||||||
|
{
|
||||||
|
public class SyncResult
|
||||||
|
{
|
||||||
|
public bool Success { get; set; }
|
||||||
|
public string ErrorMessage { get; set; }
|
||||||
|
public int GroupCount { get; set; }
|
||||||
|
public int UserCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -98,7 +98,7 @@ namespace Bit.Core.Services
|
|||||||
var requestMessage = new HttpRequestMessage
|
var requestMessage = new HttpRequestMessage
|
||||||
{
|
{
|
||||||
Method = HttpMethod.Post,
|
Method = HttpMethod.Post,
|
||||||
RequestUri = new Uri(ApiClient.BaseAddress, "import"), // TODO: org id
|
RequestUri = new Uri(ApiClient.BaseAddress, $"organizations/{SettingsService.Instance.Organization.Id}/import"),
|
||||||
Content = new StringContent(stringContent, Encoding.UTF8, "application/json"),
|
Content = new StringContent(stringContent, Encoding.UTF8, "application/json"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -153,6 +153,19 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SyncConfiguration Sync
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Settings.Sync;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Settings.Sync = value;
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class SettingsModel
|
public class SettingsModel
|
||||||
{
|
{
|
||||||
public string ApiBaseUrl { get; set; }
|
public string ApiBaseUrl { get; set; }
|
||||||
@@ -160,6 +173,7 @@ namespace Bit.Core.Services
|
|||||||
public EncryptedData AccessToken { get; set; }
|
public EncryptedData AccessToken { get; set; }
|
||||||
public EncryptedData RefreshToken { get; set; }
|
public EncryptedData RefreshToken { get; set; }
|
||||||
public ServerConfiguration Server { get; set; }
|
public ServerConfiguration Server { get; set; }
|
||||||
|
public SyncConfiguration Sync { get; set; }
|
||||||
public Organization Organization { get; set; }
|
public Organization Organization { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,43 @@ namespace Bit.Core.Utilities
|
|||||||
{
|
{
|
||||||
public static class Sync
|
public static class Sync
|
||||||
{
|
{
|
||||||
public static async Task SyncAllAsync()
|
public static async Task<SyncResult> SyncAllAsync()
|
||||||
{
|
{
|
||||||
|
if(!AuthService.Instance.Authenticated || !AuthService.Instance.OrganizationSet)
|
||||||
|
{
|
||||||
|
return new SyncResult
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
ErrorMessage = "Not logged in or have an org set."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SettingsService.Instance.Server == null)
|
||||||
|
{
|
||||||
|
return new SyncResult
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
ErrorMessage = "No configuration for directory server."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SettingsService.Instance.Sync == null)
|
||||||
|
{
|
||||||
|
return new SyncResult
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
ErrorMessage = "No configuration for sync."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
List<GroupEntry> groups = null;
|
List<GroupEntry> groups = null;
|
||||||
if(SettingsService.Instance.Server.SyncGroups)
|
if(SettingsService.Instance.Sync.SyncGroups)
|
||||||
{
|
{
|
||||||
groups = await GetGroupsAsync();
|
groups = await GetGroupsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UserEntry> users = null;
|
List<UserEntry> users = null;
|
||||||
if(SettingsService.Instance.Server.SyncUsers)
|
if(SettingsService.Instance.Sync.SyncUsers)
|
||||||
{
|
{
|
||||||
users = await GetUsersAsync();
|
users = await GetUsersAsync();
|
||||||
}
|
}
|
||||||
@@ -28,12 +55,29 @@ namespace Bit.Core.Utilities
|
|||||||
FlattenGroupsToUsers(groups, null, groups, users);
|
FlattenGroupsToUsers(groups, null, groups, users);
|
||||||
|
|
||||||
var request = new ImportRequest(groups, users);
|
var request = new ImportRequest(groups, users);
|
||||||
await ApiService.Instance.PostImportAsync(request);
|
var response = await ApiService.Instance.PostImportAsync(request);
|
||||||
|
if(response.Succeeded)
|
||||||
|
{
|
||||||
|
return new SyncResult
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
GroupCount = groups.Count,
|
||||||
|
UserCount = users.Count
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new SyncResult
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
ErrorMessage = response.Errors.FirstOrDefault()?.Message
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Task<List<GroupEntry>> GetGroupsAsync()
|
private static Task<List<GroupEntry>> GetGroupsAsync()
|
||||||
{
|
{
|
||||||
if(!SettingsService.Instance.Server.SyncGroups)
|
if(!SettingsService.Instance.Sync.SyncGroups)
|
||||||
{
|
{
|
||||||
throw new ApplicationException("Not configured to sync groups.");
|
throw new ApplicationException("Not configured to sync groups.");
|
||||||
}
|
}
|
||||||
@@ -43,14 +87,19 @@ namespace Bit.Core.Utilities
|
|||||||
throw new ApplicationException("No configuration for directory server.");
|
throw new ApplicationException("No configuration for directory server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SettingsService.Instance.Sync == null)
|
||||||
|
{
|
||||||
|
throw new ApplicationException("No configuration for sync.");
|
||||||
|
}
|
||||||
|
|
||||||
if(!AuthService.Instance.Authenticated)
|
if(!AuthService.Instance.Authenticated)
|
||||||
{
|
{
|
||||||
throw new ApplicationException("Not authenticated.");
|
throw new ApplicationException("Not authenticated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var entry = SettingsService.Instance.Server.GetDirectoryEntry();
|
var entry = SettingsService.Instance.Server.GetDirectoryEntry();
|
||||||
var filter = string.IsNullOrWhiteSpace(SettingsService.Instance.Server.GroupFilter) ? null :
|
var filter = string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.GroupFilter) ? null :
|
||||||
SettingsService.Instance.Server.GroupFilter;
|
SettingsService.Instance.Sync.GroupFilter;
|
||||||
var searcher = new DirectorySearcher(entry, filter);
|
var searcher = new DirectorySearcher(entry, filter);
|
||||||
var result = searcher.FindAll();
|
var result = searcher.FindAll();
|
||||||
|
|
||||||
@@ -68,10 +117,10 @@ namespace Bit.Core.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
if(item.Properties.Contains(SettingsService.Instance.Server.GroupNameAttribute) &&
|
if(item.Properties.Contains(SettingsService.Instance.Sync.GroupNameAttribute) &&
|
||||||
item.Properties[SettingsService.Instance.Server.GroupNameAttribute].Count > 0)
|
item.Properties[SettingsService.Instance.Sync.GroupNameAttribute].Count > 0)
|
||||||
{
|
{
|
||||||
group.Name = item.Properties[SettingsService.Instance.Server.GroupNameAttribute][0].ToString();
|
group.Name = item.Properties[SettingsService.Instance.Sync.GroupNameAttribute][0].ToString();
|
||||||
}
|
}
|
||||||
else if(item.Properties.Contains("cn") && item.Properties["cn"].Count > 0)
|
else if(item.Properties.Contains("cn") && item.Properties["cn"].Count > 0)
|
||||||
{
|
{
|
||||||
@@ -83,14 +132,14 @@ namespace Bit.Core.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dates
|
// Dates
|
||||||
group.CreationDate = ParseDate(item.Properties, SettingsService.Instance.Server.CreationDateAttribute);
|
group.CreationDate = ParseDate(item.Properties, SettingsService.Instance.Sync.CreationDateAttribute);
|
||||||
group.RevisionDate = ParseDate(item.Properties, SettingsService.Instance.Server.RevisionDateAttribute);
|
group.RevisionDate = ParseDate(item.Properties, SettingsService.Instance.Sync.RevisionDateAttribute);
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
if(item.Properties.Contains(SettingsService.Instance.Server.MemberAttribute) &&
|
if(item.Properties.Contains(SettingsService.Instance.Sync.MemberAttribute) &&
|
||||||
item.Properties[SettingsService.Instance.Server.MemberAttribute].Count > 0)
|
item.Properties[SettingsService.Instance.Sync.MemberAttribute].Count > 0)
|
||||||
{
|
{
|
||||||
foreach(var member in item.Properties[SettingsService.Instance.Server.MemberAttribute])
|
foreach(var member in item.Properties[SettingsService.Instance.Sync.MemberAttribute])
|
||||||
{
|
{
|
||||||
var memberDn = member.ToString();
|
var memberDn = member.ToString();
|
||||||
if(!group.Members.Contains(memberDn))
|
if(!group.Members.Contains(memberDn))
|
||||||
@@ -108,7 +157,7 @@ namespace Bit.Core.Utilities
|
|||||||
|
|
||||||
private static Task<List<UserEntry>> GetUsersAsync()
|
private static Task<List<UserEntry>> GetUsersAsync()
|
||||||
{
|
{
|
||||||
if(!SettingsService.Instance.Server.SyncUsers)
|
if(!SettingsService.Instance.Sync.SyncUsers)
|
||||||
{
|
{
|
||||||
throw new ApplicationException("Not configured to sync users.");
|
throw new ApplicationException("Not configured to sync users.");
|
||||||
}
|
}
|
||||||
@@ -118,14 +167,19 @@ namespace Bit.Core.Utilities
|
|||||||
throw new ApplicationException("No configuration for directory server.");
|
throw new ApplicationException("No configuration for directory server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SettingsService.Instance.Sync == null)
|
||||||
|
{
|
||||||
|
throw new ApplicationException("No configuration for sync.");
|
||||||
|
}
|
||||||
|
|
||||||
if(!AuthService.Instance.Authenticated)
|
if(!AuthService.Instance.Authenticated)
|
||||||
{
|
{
|
||||||
throw new ApplicationException("Not authenticated.");
|
throw new ApplicationException("Not authenticated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var entry = SettingsService.Instance.Server.GetDirectoryEntry();
|
var entry = SettingsService.Instance.Server.GetDirectoryEntry();
|
||||||
var filter = string.IsNullOrWhiteSpace(SettingsService.Instance.Server.UserFilter) ? null :
|
var filter = string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.UserFilter) ? null :
|
||||||
SettingsService.Instance.Server.UserFilter;
|
SettingsService.Instance.Sync.UserFilter;
|
||||||
var searcher = new DirectorySearcher(entry, filter);
|
var searcher = new DirectorySearcher(entry, filter);
|
||||||
var result = searcher.FindAll();
|
var result = searcher.FindAll();
|
||||||
|
|
||||||
@@ -143,19 +197,19 @@ namespace Bit.Core.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Email
|
// Email
|
||||||
if(SettingsService.Instance.Server.EmailPrefixSuffix &&
|
if(SettingsService.Instance.Sync.EmailPrefixSuffix &&
|
||||||
item.Properties.Contains(SettingsService.Instance.Server.UserEmailPrefixAttribute) &&
|
item.Properties.Contains(SettingsService.Instance.Sync.UserEmailPrefixAttribute) &&
|
||||||
item.Properties[SettingsService.Instance.Server.UserEmailPrefixAttribute].Count > 0 &&
|
item.Properties[SettingsService.Instance.Sync.UserEmailPrefixAttribute].Count > 0 &&
|
||||||
!string.IsNullOrWhiteSpace(SettingsService.Instance.Server.UserEmailSuffix))
|
!string.IsNullOrWhiteSpace(SettingsService.Instance.Sync.UserEmailSuffix))
|
||||||
{
|
{
|
||||||
user.Email = string.Concat(
|
user.Email = string.Concat(
|
||||||
item.Properties[SettingsService.Instance.Server.UserEmailPrefixAttribute][0].ToString(),
|
item.Properties[SettingsService.Instance.Sync.UserEmailPrefixAttribute][0].ToString(),
|
||||||
SettingsService.Instance.Server.UserEmailSuffix).ToLowerInvariant();
|
SettingsService.Instance.Sync.UserEmailSuffix).ToLowerInvariant();
|
||||||
}
|
}
|
||||||
else if(item.Properties.Contains(SettingsService.Instance.Server.UserEmailAttribute) &&
|
else if(item.Properties.Contains(SettingsService.Instance.Sync.UserEmailAttribute) &&
|
||||||
item.Properties[SettingsService.Instance.Server.UserEmailAttribute].Count > 0)
|
item.Properties[SettingsService.Instance.Sync.UserEmailAttribute].Count > 0)
|
||||||
{
|
{
|
||||||
user.Email = item.Properties[SettingsService.Instance.Server.UserEmailAttribute][0]
|
user.Email = item.Properties[SettingsService.Instance.Sync.UserEmailAttribute][0]
|
||||||
.ToString()
|
.ToString()
|
||||||
.ToLowerInvariant();
|
.ToLowerInvariant();
|
||||||
}
|
}
|
||||||
@@ -165,8 +219,8 @@ namespace Bit.Core.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dates
|
// Dates
|
||||||
user.CreationDate = ParseDate(item.Properties, SettingsService.Instance.Server.CreationDateAttribute);
|
user.CreationDate = ParseDate(item.Properties, SettingsService.Instance.Sync.CreationDateAttribute);
|
||||||
user.RevisionDate = ParseDate(item.Properties, SettingsService.Instance.Server.RevisionDateAttribute);
|
user.RevisionDate = ParseDate(item.Properties, SettingsService.Instance.Sync.RevisionDateAttribute);
|
||||||
|
|
||||||
users.Add(user);
|
users.Add(user);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user