Advertisement
yambroskin

Untitled

Aug 14th, 2018
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 27.43 KB | None | 0 0
  1. using EleWise.ELMA.Cache;
  2. using EleWise.ELMA.ComponentModel;
  3. using EleWise.ELMA.Extensions;
  4. using EleWise.ELMA.IntegrationLdap.Settings;
  5. using EleWise.ELMA.Logging;
  6. using EleWise.ELMA.Model.Attributes;
  7. using EleWise.ELMA.Runtime.Managers;
  8. using EleWise.ELMA.Security.Managers;
  9. using EleWise.ELMA.Security.Models;
  10. using EleWise.ELMA.Security.Services;
  11. using EleWise.ELMA.Services;
  12. using EleWise.ELMA.Threading;
  13. using EleWise.ELMA.ConfigurationModel;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.DirectoryServices;
  17. using System.Linq;
  18. using System.Threading;
  19. using EleWise.ELMA;
  20. using EleWise.ELMA.IntegrationLdap;
  21. using EleWise.ELMA.IntegrationLdap.Services;
  22.  
  23. namespace AlfaLdapExtension
  24. {
  25.     [Service]
  26.     public class TrickyLdapService :ILdapService
  27.     {
  28.         private static readonly ILogger IntegrationLdapLog = Logger.GetLogger("ElmaIntegrationLdap");
  29.  
  30.         private ICacheService CacheService
  31.         {
  32.             get
  33.             {
  34.                 return Locator.GetServiceNotNull<ICacheService>();
  35.             }
  36.         }
  37.  
  38.         /// <summary>
  39.         /// Получение строки поиска пользователя по доменному имени
  40.         /// </summary>
  41.         private string GetSearchStringDN(LdapExternalMembershipModuleSettings settings, string searchString)
  42.         {
  43.             if (string.IsNullOrWhiteSpace(settings.LdapParamLogin))
  44.             {
  45.                 throw new ArgumentNullException("LdapLogin");
  46.             }
  47.             if (string.IsNullOrWhiteSpace(searchString))
  48.             {
  49.                 throw new ArgumentNullException("Login");
  50.             }
  51.             var text = string.Format("({0}={1})", settings.LdapParamLogin, searchString);
  52.             if (!string.IsNullOrWhiteSpace(settings.LdapAuthFilter))
  53.             {
  54.                 text = string.Format("(&{0}{1})", settings.LdapAuthFilter, text);
  55.             }
  56.             return text;
  57.         }
  58.  
  59.         /// <summary>
  60.         /// Получение произвольной строки поиска
  61.         /// </summary>
  62.         private string GetSearchString(LdapExternalMembershipModuleSettings settings, string searchString)
  63.         {
  64.             var text = "";
  65.             if (!string.IsNullOrWhiteSpace(searchString))
  66.             {
  67.                 if (string.IsNullOrWhiteSpace(settings.LdapParamLogin))
  68.                 {
  69.                     throw new ArgumentNullException("LdapLogin");
  70.                 }
  71.                 text = string.Format("({0}=*{1}*)", settings.LdapParamLogin, searchString);
  72.                 if (!string.IsNullOrWhiteSpace(settings.LdapParamName))
  73.                 {
  74.                     text = string.Format("(|({0}=*{1}*){2})", settings.LdapParamName, searchString, text);
  75.                 }
  76.                 if (!string.IsNullOrWhiteSpace(settings.LdapParamSecond))
  77.                 {
  78.                     text = string.Format("(|({0}=*{1}*){2})", settings.LdapParamSecond, searchString, text);
  79.                 }
  80.                 if (!string.IsNullOrWhiteSpace(settings.LdapEMail))
  81.                 {
  82.                     text = string.Format("(|({0}=*{1}*){2})", settings.LdapEMail, searchString, text);
  83.                 }
  84.                 if (!string.IsNullOrWhiteSpace(settings.LdapParamMiddle))
  85.                 {
  86.                     text = string.Format("(|({0}=*{1}*){2})", settings.LdapParamMiddle, searchString, text);
  87.                 }
  88.                 if (!string.IsNullOrWhiteSpace(settings.LdapAuthFilter))
  89.                 {
  90.                     text = string.Format("(&{0}{1})", settings.LdapAuthFilter, text);
  91.                 }
  92.             }
  93.             else if (!string.IsNullOrWhiteSpace(settings.LdapAuthFilter))
  94.             {
  95.                 text = string.Format("{0}", settings.LdapAuthFilter);
  96.             }
  97.             return text;
  98.         }
  99.  
  100.         /// <summary>
  101.         /// Преобразование шаблона авторизации
  102.         /// </summary>
  103.         private string SetLoginTemplate(SearchResult searchResult, LdapExternalMembershipModuleSettings settings)
  104.         {
  105.             if (settings.UseForest && settings.LdapDomainTemplate != null && settings.LdapDomainTemplate.Contains("{$login}"))
  106.             {
  107.                 return settings.LdapDomainTemplate.Replace("{$login}", searchResult.Properties[settings.LdapParamLogin][0].ToString());
  108.             }
  109.             return searchResult.Properties[settings.LdapParamLogin][0].ToString();
  110.         }
  111.  
  112.         /// <summary>
  113.         /// Считывание данных о пользователе из результата поиска
  114.         /// </summary>
  115.         private IUser ReadUserParam(SearchResult searchResult, LdapExternalMembershipModuleSettings settings)
  116.         {
  117.             var user = UserManager.Instance.Create();
  118.             try
  119.             {
  120.                 user.UserName = SetLoginTemplate(searchResult, settings);
  121.             }
  122.             catch (Exception exception)
  123.             {
  124.                 var message = string.Format("Login read fail. Param: {0}", settings.LdapParamLogin);
  125.                IntegrationLdapLog.Debug(message, exception);
  126.             }
  127.             ReadUserParam(searchResult, settings, user);
  128.             return user;
  129.         }
  130.  
  131.         /// <summary>
  132.         /// Считывание данных о пользователе из результата поиска
  133.         /// </summary>
  134.         private bool ReadUserParam(SearchResult searchResult, LdapExternalMembershipModuleSettings settings, IUser user)
  135.         {
  136.             var result = false;
  137.             #region Поля из стандартного модуля
  138.            
  139.            
  140.             try
  141.             {
  142.                 var text = searchResult.Properties[settings.LdapParamName][0].ToString();
  143.                 if (user.FirstName != text)
  144.                 {
  145.                     user.FirstName = text;
  146.                     result = true;
  147.                 }
  148.             }
  149.             catch (Exception message)
  150.             {
  151.                IntegrationLdapLog.Debug(message);
  152.             }
  153.             try
  154.             {
  155.                 var text2 = searchResult.Properties[settings.LdapParamSecond][0].ToString();
  156.                 if (user.LastName != text2)
  157.                 {
  158.                     user.LastName = text2;
  159.                     result = true;
  160.                 }
  161.             }
  162.             catch (Exception message2)
  163.             {
  164.                IntegrationLdapLog.Debug(message2);
  165.             }
  166.             try
  167.             {
  168.                 var text3 = searchResult.Properties[settings.LdapParamMiddle][0].ToString();
  169.                 if (user.MiddleName != text3)
  170.                 {
  171.                     user.MiddleName = text3;
  172.                     result = true;
  173.                 }
  174.             }
  175.             catch (Exception message3)
  176.             {
  177.                IntegrationLdapLog.Debug(message3);
  178.             }
  179.             var fullName = user.GetFullName();
  180.             if (user.FullName != fullName)
  181.             {
  182.                 user.FullName = fullName;
  183.                 result = true;
  184.             }
  185.              #endregion
  186.             try
  187.             {
  188.                 var text4 = searchResult.Properties[settings.LdapEMail][0].ToString();
  189.                 if (user.EMail != text4)
  190.                 {
  191.                     user.EMail = text4;
  192.                     result = true;
  193.                 }
  194.             }
  195.             catch (Exception exception)
  196.             {
  197.                 var message4 = string.Format("Email read fail. Param: {0}", settings.LdapEMail);
  198.                IntegrationLdapLog.Debug(message4, exception);
  199.             }
  200.  
  201.             #region Загрузка города
  202.  
  203.             try
  204.             {
  205.                 var city = searchResult.Properties["l"][0].ToString();
  206.                 var userExt = user as IUserExt;
  207.                 if (userExt.City != city)
  208.                 {
  209.                     userExt.City = city;
  210.                 }
  211.             }
  212.             catch (Exception message3)
  213.             {
  214.                 IntegrationLdapLog.Debug(message3);
  215.             }
  216.  
  217.             #endregion
  218.  
  219.             return result;
  220.         }
  221.  
  222.         /// <summary>
  223.         /// Узел/объект LDAP
  224.         /// </summary>
  225.         private DirectoryEntry GetDirectoryEntry(LdapExternalMembershipModuleSettings settings)
  226.         {
  227.             if (settings == null)
  228.             {
  229.                 throw new Exception(SR.T("Отсутствуют настройки LDAP"));
  230.             }
  231.             return new DirectoryEntry
  232.             {
  233.                 Path = "LDAP://" + settings.LdapUrl + "/" + settings.LdapPath,
  234.                 AuthenticationType = (AuthenticationTypes)settings.LdapAuthType,
  235.                 Username = settings.LdapLogin,
  236.                 Password = settings.LdapPassword
  237.             };
  238.         }
  239.  
  240.         /// <summary>
  241.         /// Получение строки поиска для пользователя
  242.         /// </summary>
  243.         private string GetUserSearchString(LdapExternalMembershipModuleSettings settings, string searchString)
  244.         {
  245.             var text = "";
  246.             if (!string.IsNullOrWhiteSpace(searchString))
  247.             {
  248.                 if (string.IsNullOrWhiteSpace(settings.LdapParamLogin))
  249.                 {
  250.                     throw new ArgumentNullException("LdapLogin");
  251.                 }
  252.                 text = string.Format("({0}={1})", settings.LdapParamLogin, searchString);
  253.                 if (!string.IsNullOrWhiteSpace(settings.LdapAuthFilter))
  254.                 {
  255.                     text = string.Format("(&{0}{1})", settings.LdapAuthFilter, text);
  256.                 }
  257.             }
  258.             return text;
  259.         }
  260.  
  261.         private string SyncUsersStatusKey(Guid serviceUid)
  262.         {
  263.             return string.Format("SyncUsersStatusKey{0}", serviceUid.ToString("n"));
  264.         }
  265.  
  266.         private void AuthProviderSyncStatusSave(bool syncStatus, Guid serviceUid)
  267.         {
  268.             if (!syncStatus)
  269.             {
  270.                 CacheService.Remove(SyncUsersStatusKey(serviceUid));
  271.                 return;
  272.             }
  273.             CacheService.Insert(SyncUsersStatusKey(serviceUid), true);
  274.         }
  275.  
  276.         private void ExecuteSync(Guid serviceUid, LdapExternalMembershipModuleSettings settings, bool isAuto)
  277.         {
  278.             if (AuthProviderSyncRunning(serviceUid))
  279.             {
  280.                 return;
  281.             }
  282.             AuthProviderSyncStatusSave(true, serviceUid);
  283.             try
  284.             {
  285.                 var users = new Dictionary<string, IUser>();
  286.                 var list = DataAccessManager.BLOBManager.GetBLOB<List<string>>(serviceUid, "BlockedUsers") ?? new List<string>();
  287.                 var userSearchString = GetUserSearchString(settings, "");
  288.                 using (var directoryEntry = GetDirectoryEntry(settings))
  289.                 {
  290.                     using (var directorySearcher = new DirectorySearcher(directoryEntry, GetSearchString(settings, userSearchString))
  291.                     {
  292.                         PageSize = 1000
  293.                     })
  294.                     {
  295.                         using (var searchResultCollection = directorySearcher.FindAll())
  296.                         {
  297.                             var enumeration = UserManager.Instance.Find(u => u.AuthProviderGuid == serviceUid).GroupBy(u => u.UserName, StringComparer.InvariantCultureIgnoreCase);
  298.                             enumeration.ForEach(delegate (IGrouping<string, IUser> g)
  299.                             {
  300.                                 if (g.Count() != 1)
  301.                                 {
  302.                                    IntegrationLdapLog.Debug(SR.T("Ошибка синхронизации с LDAP: найдено несколько пользователей с UserName {0}", new object[]
  303.                                     {
  304.                                         g.Key
  305.                                     }));
  306.                                     return;
  307.                                 }
  308.                                 users.Add(g.Key.ToLower(), g.First());
  309.                             });
  310.                             if (isAuto)
  311.                             {
  312.                                 DataAccessManager.BLOBManager.SetBLOB(serviceUid, IntegrationLdapConstants.LastAutoSyncKey, DateTime.Now);
  313.                             }
  314.                             DataAccessManager.BLOBManager.SetBLOB(serviceUid, IntegrationLdapConstants.LastSyncKey, DateTime.Now);
  315.                             var flag = false;
  316.                             foreach (SearchResult searchResult in searchResultCollection)
  317.                             {
  318.                                 try
  319.                                 {
  320.                                     var key = searchResult.Properties[settings.LdapParamLogin][0].ToString().ToLower();
  321.                                     IUser user;
  322.                                     if (users.TryGetValue(key, out user))
  323.                                     {
  324.                                         if (user.Status == UserStatus.Active || list.Contains(user.UserName) || list.Contains(user.Uid.ToString("n")))
  325.                                         {
  326.                                             user.Status = UserStatus.Active;
  327.                                             list.Remove(user.UserName);
  328.                                             list.Remove(user.Uid.ToString("n"));
  329.                                             flag = true;
  330.                                             ReadUserParam(searchResult, settings, user);
  331.                                         }
  332.                                         users.Remove(key);
  333.                                     }
  334.                                 }
  335.                                 catch (Exception ex)
  336.                                 {
  337.                                     var message = string.Format("{0}: {1}", SR.T("Не удалось получить пользователя из LDAP"), ex.Message);
  338.                                    IntegrationLdapLog.Debug(message, ex);
  339.                                 }
  340.                             }
  341.                             foreach (var current in users.Values)
  342.                             {
  343.                                 current.Status = UserStatus.Blocked;
  344.                                 if (!list.Contains(current.Uid.ToString("n")))
  345.                                 {
  346.                                     list.Add(current.Uid.ToString("n"));
  347.                                 }
  348.                                 flag = true;
  349.                             }
  350.                             if (flag)
  351.                             {
  352.                                 DataAccessManager.BLOBManager.SetBLOB(serviceUid, "BlockedUsers", list);
  353.                             }
  354.                         }
  355.                     }
  356.                 }
  357.             }
  358.             catch (Exception ex2)
  359.             {
  360.                 var message2 = string.Format("{0}: {1}", SR.T("Ошибка синхронизации с LDAP"), ex2.Message);
  361.                IntegrationLdapLog.Error(message2, ex2);
  362.             }
  363.             finally
  364.             {
  365.                 AuthProviderSyncStatusSave(false, serviceUid);
  366.             }
  367.         }
  368.  
  369.         /// <summary>
  370.         /// Проверка на наличие запущенной синхронизации
  371.         /// </summary>
  372.         public bool AuthProviderSyncRunning(Guid serviceUid)
  373.         {
  374.             bool flag;
  375.             return CacheService.TryGetValue(SyncUsersStatusKey(serviceUid), out flag) && flag;
  376.         }
  377.  
  378.         /// <summary>
  379.         /// Запуск ручной синхронизации в отдельном потоке
  380.         /// </summary>
  381.         public void AuthProviderManualSyncStart(Guid serviceUid)
  382.         {
  383.             AuthProviderSyncStart(serviceUid, false);
  384.         }
  385.  
  386.         /// <summary>
  387.         /// Запуск автосинхронизации в отдельном потоке
  388.         /// </summary>
  389.         public void AuthProviderAutoSyncStart(Guid serviceUid)
  390.         {
  391.             AuthProviderSyncStart(serviceUid, true);
  392.         }
  393.  
  394.         /// <summary>
  395.         /// Запуск синхронизации в отдельном потоке
  396.         /// </summary>
  397.         private void AuthProviderSyncStart(Guid serviceUid, bool isAuto)
  398.         {
  399.             new Thread((ThreadStart)delegate
  400.             {
  401.                 new BackgroundTask(delegate
  402.                 {
  403.                     AuthProviderSync(serviceUid, isAuto);
  404.                 }, typeof(ILdapService), SR.T("Синхронизация импортированных пользователей"), SR.T("Синхронизация параметров импортированных пользователей ...")).Execute();
  405.             }).Start();
  406.         }
  407.  
  408.         /// <summary>
  409.         /// Запуск синхронизации
  410.         /// </summary>
  411.         [Transaction]
  412.         protected virtual void AuthProviderSync(Guid serviceUid, bool isAuto)
  413.         {
  414.             var ldapExternalMembershipModuleSettings = Locator.GetServiceNotNull<IExternalMembershipManager>().LoadSettings(serviceUid) as LdapExternalMembershipModuleSettings;
  415.             if (ldapExternalMembershipModuleSettings != null)
  416.             {
  417.                 ExecuteSync(serviceUid, ldapExternalMembershipModuleSettings, isAuto);
  418.             }
  419.         }
  420.  
  421.         /// <summary>
  422.         /// Получить дату последней синхронизации
  423.         /// </summary>
  424.         public DateTime? GetLastSyncDate(Guid serviceUid)
  425.         {
  426.             return DataAccessManager.BLOBManager.GetBLOB<DateTime?>(serviceUid, IntegrationLdapConstants.LastSyncKey);
  427.         }
  428.  
  429.         /// <summary>
  430.         ///  Заполнение свойств пользователя данными из LDAP
  431.         /// </summary>
  432.         public void Sync(EleWise.ELMA.Security.IUser user, LdapExternalMembershipModuleSettings settings)
  433.         {
  434.             if (user == null)
  435.             {
  436.                IntegrationLdapLog.Debug("Synchronization Error: user is null");
  437.                 return;
  438.             }
  439.             if (settings == null)
  440.             {
  441.                IntegrationLdapLog.Debug(SR.T("Отсутствуют настройки LDAP"));
  442.                 return;
  443.             }
  444.             if (string.IsNullOrWhiteSpace(settings.LdapUrl))
  445.             {
  446.                IntegrationLdapLog.Error(SR.T("Отсутствует адрес LDAP сервера"));
  447.                 return;
  448.             }
  449.             using (var directoryEntry = GetDirectoryEntry(settings))
  450.             {
  451.                 var userSearchString = GetUserSearchString(settings, user.UserName);
  452.                 if (string.IsNullOrWhiteSpace(userSearchString))
  453.                 {
  454.                    IntegrationLdapLog.Debug(string.Format("Synchronization Error: can't read from LDAP {0}", user.UserName));
  455.                 }
  456.                 else
  457.                 {
  458.                     using (var directorySearcher = new DirectorySearcher(directoryEntry, userSearchString))
  459.                     {
  460.                         using (var searchResultCollection = directorySearcher.FindAll())
  461.                         {
  462.                             if (searchResultCollection != null && searchResultCollection.Count > 0)
  463.                             {
  464.                                 ReadUserParam(searchResultCollection[0], settings, (IUser)user);
  465.                             }
  466.                             else
  467.                             {
  468.                                IntegrationLdapLog.Debug(SR.T("Не удалось получить дополнительную информацию о пользователе LDAP"));
  469.                             }
  470.                         }
  471.                     }
  472.                 }
  473.             }
  474.         }
  475.  
  476.         /// <summary>
  477.         /// Валидация по Distinguished Names
  478.         /// </summary>
  479.         public bool ValidatingDN(UserValidationContext context, LdapExternalMembershipModuleSettings settings)
  480.         {
  481.             return ValidatingDN(context.User.UserName, context.Password, settings);
  482.         }
  483.  
  484.         /// <summary>
  485.         /// Валидация по доменному имени
  486.         /// </summary>
  487.         public bool ValidatingTemplate(UserValidationContext context, LdapExternalMembershipModuleSettings settings)
  488.         {
  489.             return ValidatingTemplate(context.User.UserName, context.Password, settings);
  490.         }
  491.  
  492.         /// <summary>
  493.         /// Валидация по Distinguished Names
  494.         /// </summary>
  495.         public bool ValidatingDN(string userName, string password, LdapExternalMembershipModuleSettings settings)
  496.         {
  497.             if (settings == null || string.IsNullOrWhiteSpace(settings.LdapUrl))
  498.             {
  499.                IntegrationLdapLog.Debug(SR.T("Отсутствуют настройки LDAP"));
  500.                 return false;
  501.             }
  502.             if (settings == null)
  503.             {
  504.                 throw new Exception(SR.T("Отсутствуют настройки LDAP"));
  505.             }
  506.             bool result;
  507.             using (var directoryEntry = new DirectoryEntry
  508.             {
  509.                 Path = "LDAP://" + settings.LdapUrl + "/" + settings.LdapPath,
  510.                 AuthenticationType = (AuthenticationTypes)settings.LdapAuthType,
  511.                 Username = settings.LdapLogin,
  512.                 Password = settings.LdapPassword
  513.             })
  514.             {
  515.                 using (var directorySearcher = new DirectorySearcher(directoryEntry, GetSearchStringDN(settings, userName)))
  516.                 {
  517.                     using (var searchResultCollection = directorySearcher.FindAll())
  518.                     {
  519.                         if (searchResultCollection == null)
  520.                         {
  521.                             throw new Exception("searchResultCollection == null");
  522.                         }
  523.                         if (searchResultCollection.Count == 0)
  524.                         {
  525.                             throw new Exception("User not found in LDAP");
  526.                         }
  527.                         if (searchResultCollection.Count > 1)
  528.                         {
  529.                             throw new Exception("It is more than one user in LDAP");
  530.                         }
  531.                         var searchResult = searchResultCollection[0];
  532.                         if ((settings.LdapAuthType == 0 || settings.LdapAuthType == 4) && string.IsNullOrEmpty(password))
  533.                         {
  534.                             result = false;
  535.                         }
  536.                         else
  537.                         {
  538.                             using (var directoryEntry2 = new DirectoryEntry
  539.                             {
  540.                                 Path = searchResult.Path,
  541.                                 AuthenticationType = (AuthenticationTypes)settings.LdapAuthType,
  542.                                 Username = searchResult.Path.Remove(0, ("LDAP://" + settings.LdapUrl + "/").Length),
  543.                                 Password = password
  544.                             })
  545.                             {
  546.                                 var arg_161_0 = directoryEntry2.NativeObject;
  547.                             }
  548.                             result = true;
  549.                         }
  550.                     }
  551.                 }
  552.             }
  553.             return result;
  554.         }
  555.  
  556.         /// <summary>
  557.         /// Валидация по доменному имени
  558.         /// </summary>
  559.         public bool ValidatingTemplate(string userName, string password, LdapExternalMembershipModuleSettings settings)
  560.         {
  561.             if (settings == null || string.IsNullOrWhiteSpace(settings.LdapUrl))
  562.             {
  563.                IntegrationLdapLog.Debug(SR.T("Отсутствуют настройки LDAP"));
  564.                 return false;
  565.             }
  566.             if ((settings.LdapAuthType == 0 || settings.LdapAuthType == 4) && string.IsNullOrEmpty(password))
  567.             {
  568.                 return false;
  569.             }
  570.             var username = (settings.LdapAuthLogin == null) ? userName : settings.LdapAuthLogin.Replace("{$login}", userName);
  571.             using (var directoryEntry = new DirectoryEntry
  572.             {
  573.                 Path = "LDAP://" + settings.LdapUrl + "/" + settings.LdapPath,
  574.                 AuthenticationType = (AuthenticationTypes)settings.LdapAuthType,
  575.                 Username = username,
  576.                 Password = password
  577.             })
  578.             {
  579.                 var arg_A7_0 = directoryEntry.NativeObject;
  580.             }
  581.             return true;
  582.         }
  583.  
  584.         /// <summary>
  585.         /// Поиск пользователей в LDAP
  586.         /// </summary>
  587.         public IEnumerable<EleWise.ELMA.Security.IUser> FindUsers(string searchString, LdapExternalMembershipModuleSettings settings, Guid serviceUid)
  588.         {
  589.             var list = new List<EleWise.ELMA.Security.IUser>();
  590.             try
  591.             {
  592.                 if (searchString == null)
  593.                 {
  594.                     return list;
  595.                 }
  596.                 if (settings == null)
  597.                 {
  598.                     throw new Exception(SR.T("Отсутствуют настройки LDAP"));
  599.                 }
  600.                 if (string.IsNullOrWhiteSpace(settings.LdapUrl))
  601.                 {
  602.                     throw new Exception(SR.T("Отсутствует адрес LDAP сервера"));
  603.                 }
  604.                 if (string.IsNullOrWhiteSpace(settings.LdapParamLogin))
  605.                 {
  606.                     throw new Exception(SR.T("Отсутствует настройка параметра \"Логин\""));
  607.                 }
  608.                 using (var directoryEntry = GetDirectoryEntry(settings))
  609.                 {
  610.                     using (var directorySearcher = new DirectorySearcher(directoryEntry, GetSearchString(settings, searchString))
  611.                     {
  612.                         PageSize = 1000,
  613.                         CacheResults = false
  614.                     })
  615.                     {
  616.                         using (var searchResultCollection = directorySearcher.FindAll())
  617.                         {
  618.                             foreach (SearchResult searchResult in searchResultCollection)
  619.                             {
  620.                                 try
  621.                                 {
  622.                                     var user = ReadUserParam(searchResult, settings);
  623.                                     user.AuthProviderGuid = serviceUid;
  624.                                     list.Add(user);
  625.                                 }
  626.                                 catch (Exception ex)
  627.                                 {
  628.                                     var message = string.Format("{0}: {1}", "Import user from LDAP failed", ex.Message);
  629.                                    IntegrationLdapLog.Error(message, ex);
  630.                                 }
  631.                             }
  632.                         }
  633.                     }
  634.                 }
  635.             }
  636.             catch (Exception ex2)
  637.             {
  638.                 var message2 = string.Format("{0}: {1}", SR.T("Не удалось получить список пользователей из LDAP"), ex2.Message);
  639.                IntegrationLdapLog.Debug(message2, ex2);
  640.                 throw new Exception(message2);
  641.             }
  642.             return list;
  643.         }
  644.     }
  645.  
  646. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement