public IEnumerable <ActiveDirectoryUserRecord> GetUserRecords(ActiveDirectoryServer adServer) { foreach (var userEntry in GetUsersEntries(adServer)) { ActiveDirectoryUserRecord result = new ActiveDirectoryUserRecord(); result.SourceUserPrincipal = userEntry; string dn = userEntry.DistinguishedName; result.Name = userEntry.DisplayName ?? ""; result.EmployeeID = userEntry.EmployeeId ?? ""; result.Title = userEntry.Title ?? ""; result.Department = userEntry.Department ?? ""; result.Location = userEntry.PhysicalDeliveryOfficeName ?? ""; result.Addresses = userEntry.EmailAddresses; if (!string.IsNullOrWhiteSpace(userEntry.TelephoneNumber)) { result.PhoneNumbers.Add(userEntry.TelephoneNumber); } if (userEntry.Sid != null) { result.SIDs.Add(userEntry.Sid.ToString()); } if (!string.IsNullOrWhiteSpace(userEntry.TelephoneNumber)) { result.PhoneNumbers.Add(userEntry.TelephoneNumber); } yield return(result); } }
protected PrincipalContext obtainContext(ActiveDirectoryServer adServer) { // Did they provide username and password? if (adServer.UserName != null && adServer.Password != null) { // Did they provide a context container? if (!string.IsNullOrWhiteSpace(adServer.ContextContainer)) { return(new PrincipalContext(ContextType.Domain, adServer.Domain, adServer.ContextContainer, adServer.UserName, adServer.Password)); } else { return(new PrincipalContext(ContextType.Domain, adServer.Domain, null, adServer.UserName, adServer.Password)); } } else // No user credentials { // Did they provide a context container? if (!string.IsNullOrWhiteSpace(adServer.ContextContainer)) { return(new PrincipalContext(ContextType.Domain, adServer.Domain, adServer.ContextContainer)); } else { return(new PrincipalContext(ContextType.Domain, adServer.Domain, null)); } } }
public IEnumerable <ExtendedUserPrincipal> GetUsersEntries(ActiveDirectoryServer adServer) { logger.Info(new String('=', 50)); if (string.IsNullOrWhiteSpace(adServer.Domain)) { logger.Info("Domain value is null/empty, using process domain..."); adServer.UseMachineDomain(); } logger.Info("Domain: " + adServer.Domain); if (!string.IsNullOrWhiteSpace(adServer.ContextContainer)) { logger.Info("Context Container: " + adServer.ContextContainer); } else { logger.Info("Context Container: None Provided"); } logger.Info("Initializing PrincipalContext..."); using (PrincipalContext context = obtainContext(adServer)) { logger.Info("Initializing PrincipalSearcher..."); using (var searcher = new PrincipalSearcher(new ExtendedUserPrincipal(context))) { logger.Info("Beginning UserPrincipal iteration..."); foreach (ExtendedUserPrincipal userEntry in searcher.FindAll()) { yield return(userEntry); } } } }
internal Guid CreateUser() { var registerUserStrategy = new RegisterUserStrategy(_userRepository, _configurationManager, _userRepository); var activateUserStrategy = new ActivateUserStrategy(_userRepository, _userRepository); var adServer = new ActiveDirectoryServer(ActiveDirectoryConfiguration.Instance); var userDirectoryProvider = new ActiveDirectoryUserDirectoryProvider(adServer, null); var username = GetUsername(); var userId = Guid.NewGuid(); userDirectoryProvider.CreateUser(userId.ToString(), Password); registerUserStrategy.Register(username, userId, ActivationCode, UserRoles.Candidate); activateUserStrategy.Activate(username, ActivationCode); var newCandidate = CreateFakeCandidate(userId, username); _candidateWriteRepository.Save(newCandidate); return(userId); }
public IEnumerable <ActiveDirectoryUserRecord> GetUserRecords(ActiveDirectoryServer adServer) { using (FileStream fs = new FileStream(CsvFilePath, FileMode.Open)) { foreach (var record in CsvReader.ReadFromStream(fs)) { ActiveDirectoryUserRecord userRecord = new ActiveDirectoryUserRecord() { EmployeeID = record["EmployeeID"], Name = record["Name"], Title = record["Title"], Department = record["Department"], Location = record["Location"], Addresses = record["EmailAddresses"].Split(new string[] { "; " }, StringSplitOptions.RemoveEmptyEntries).ToList(), PhoneNumbers = record["PhoneNumbers"].Split(new string[] { "; " }, StringSplitOptions.RemoveEmptyEntries).ToList(), SIDs = record["SIDs"].Split(new string[] { "; " }, StringSplitOptions.RemoveEmptyEntries).ToList(), }; yield return(userRecord); } } }
public IEnumerable <ActiveDirectoryUserRecord> GetUserRecords(ActiveDirectoryServer adServer) { int sequence = 0; ActiveDirectoryUserRecord record = null; record = new ActiveDirectoryUserRecord() { EmployeeID = (++sequence).ToString("0000000#"), Name = "Doe, John", Department = "IT", Title = "IT Manager", Location = "San Francisco", }; record.Addresses.AddRange(new string[] { "*****@*****.**", }); record.PhoneNumbers.AddRange(new string[] { "1 555-555-1234", }); record.SIDs.AddRange(new string[] { "", }); yield return(record); }