private CoredataEntry CreateCoredataEntryFromAD(IDictionary properties) { string Guid = new Guid(properties.GetValue <System.Byte[]>(propertyResolver.ObjectGuidProperty, null)).ToString(); // Name logic string ChosenName = properties.GetValue <String>(propertyResolver.ChosenNameProperty, null); string Firstname = properties.GetValue <String>(propertyResolver.FirstnameProperty, null); string Surname = properties.GetValue <String>(propertyResolver.SurnameProperty, null); string Name = String.IsNullOrEmpty(ChosenName) ? Firstname + " " + Surname : ChosenName; // Disabled logic var accountControlValue = properties.GetValue <Int32>(propertyResolver.UserAccountControlProperty, 0); // Create entry var user = new CoredataEntry() { Uuid = Guid, Cpr = properties.GetValue <string>(propertyResolver.CprProperty, null), Name = Name, Email = properties.GetValue <string>(propertyResolver.EmailProperty, null), SamAccountName = properties.GetValue <string>(propertyResolver.SAMAccountNameProperty, null), Attributes = new Dictionary <string, string>(), Deleted = properties.GetValue <bool>(propertyResolver.DeletedProperty, false), Disabled = ((accountControlValue & AccountDisable) == AccountDisable), NSISAllowed = false }; return(user); }
public IEnumerable <CoredataEntry> GetFullSyncUsers(out byte[] directorySynchronizationCookie) { using (var directoryEntry = GenerateDirectoryEntry()) { Dictionary <string, CoredataEntry> result = new Dictionary <string, CoredataEntry>(); if (loadAllUsers) { // Full load string filter = CreateFilter("!(isDeleted=TRUE)", propertyResolver.CprProperty + "=*"); using (var directorySearcher = new DirectorySearcher(directoryEntry, filter, propertyResolver.AllProperties, SearchScope.Subtree)) { directorySearcher.DirectorySynchronization = new DirectorySynchronization(DirectorySynchronizationOptions.None); using (var searchResultCollection = directorySearcher.FindAll()) { Logger.Information("Found {0} users in Active Directory", searchResultCollection.Count); foreach (SearchResult searchResult in searchResultCollection) { Logger.Verbose("Full sync searchResult: {@searchResult}", searchResult); CoredataEntry user = CreateCoredataEntryFromAD(searchResult.Properties); if (user.IsActive() && user.IsValid()) { result.Add(user.Uuid, user); } } Logger.Information("{0} users where active and valid", result.Count); } directorySynchronizationCookie = directorySearcher.DirectorySynchronization.GetDirectorySynchronizationCookie(); } // Additional search for members of a specific group (Recursive / transative) filter = CreateFilter("!(isDeleted=TRUE)", propertyResolver.CprProperty + "=*", "memberOf:1.2.840.113556.1.4.1941:=" + nsisAllowedGroup); using (var directorySearcher = new DirectorySearcher(directoryEntry, filter, propertyResolver.AllProperties, SearchScope.Subtree)) { using (var searchResultCollection = directorySearcher.FindAll()) { foreach (SearchResult searchResult in searchResultCollection) { string Guid = new Guid(searchResult.Properties.GetValue <System.Byte[]>(propertyResolver.ObjectGuidProperty, null)).ToString(); result[Guid].NSISAllowed = true; } } } return(result.Values); } else { // Only load nsis string filter = CreateFilter("!(isDeleted=TRUE)", propertyResolver.CprProperty + "=*", "memberOf:1.2.840.113556.1.4.1941:=" + nsisAllowedGroup); using (var directorySearcher = new DirectorySearcher(directoryEntry, filter, propertyResolver.AllProperties, SearchScope.Subtree)) { directorySearcher.DirectorySynchronization = new DirectorySynchronization(DirectorySynchronizationOptions.None); using (var searchResultCollection = directorySearcher.FindAll()) { Logger.Information("Found {0} users in Active Directory", searchResultCollection.Count); foreach (SearchResult searchResult in searchResultCollection) { Logger.Verbose("Full sync searchResult: {@searchResult}", searchResult); CoredataEntry user = CreateCoredataEntryFromAD(searchResult.Properties); user.NSISAllowed = true; if (user.IsActive() && user.IsValid()) { result.Add(user.Uuid, user); } } } directorySynchronizationCookie = directorySearcher.DirectorySynchronization.GetDirectorySynchronizationCookie(); } return(result.Values); } } }
public CoredataDeleteEntry(CoredataEntry entry) { this.Uuid = entry.Uuid; this.Cpr = entry.Cpr; this.SamAccountName = entry.SamAccountName; }