public int InsertMembersOfGroupToTable(LdapGroup group, string tableCode)
        {
            _log.DebugFormat("Insert data on users from group \"{0}\" to table {1}.", group.Name, tableCode);
            var filter = "(&" + _ldapUsersFilter + _ldapUsersInGroupFilter + ")";
            var result = InsertUsersToTableByFilter(tableCode, GetUserInGroupFilterString(filter, group));

            _log.DebugFormat("{0} records about users from group \"{1}\" added to table {2}.", result, group.Name, tableCode);
            return(result);
        }
        public int InsertGroupsToTable(string tableCode)
        {
            // TODO ########### ########### ########### ###### ##### ####### GetGroups
            _log.DebugFormat("Inserting group data into table {0}.", tableCode);
            var result = 0;

            string[] requiredGroupAttributes = GetRequiredGroupAttributes();
            var      request = new SearchRequest(_ldapGroupsEntry, _ldapGroupsFilter, SearchScope.Subtree,
                                                 requiredGroupAttributes);
            PageResultRequestControl paging = CreatePageResultRequestControl();

            request.Controls.Add(paging);
            SortRequestControl sortControl = CreateSortRequestControl(_ldapGroupNameAttribute);

            request.Controls.Add(sortControl);
            do
            {
                SearchResponse response;
                try {
                    response = _ldapConnection.SendRequest(request, RequestTimeout) as SearchResponse;
                } catch (Exception exception) {
                    LogLdapRequestError(exception, request);
                    throw;
                }
                if (response.ResultCode == ResultCode.Success)
                {
                    foreach (SearchResultEntry entry in response.Entries)
                    {
                        CheckEntryAttributes(entry, requiredGroupAttributes);
                        LdapGroup ldapGroup   = CreateLdapGroup(entry);
                        var       insertGroup = new Insert(_userConnection).Into(tableCode)
                                                .Set("Id", Column.Parameter(ldapGroup.Id))
                                                .Set("Name", Column.Parameter(ldapGroup.Name))
                                                .Set("Dn", Column.Parameter(ldapGroup.Dn))
                                                .Set("ModifiedOn", Column.Parameter(ldapGroup.ModifiedOn));
                        try {
                            result += insertGroup.Execute();
                        } catch (Exception e) {
                            _log.ErrorFormat("An error occurred while adding the record to the \"{0}\" table: {1}", e,
                                             tableCode, e.Message);
                            throw;
                        }
                    }
                }
                else
                {
                    _log.DebugFormat("Unable to obtain the list of folders. Result code: {0}. Error: {1}.",
                                     response.ResultCode, response.ErrorMessage ?? string.Empty);
                }
                var responseControl = (PageResultResponseControl)Array.Find(response.Controls,
                                                                            item => item is PageResultResponseControl);
                paging.Cookie = responseControl.Cookie;
            } while (paging.Cookie.Length != 0);
            _log.DebugFormat("{0} group records added to table {1}.", result, tableCode);
            return(result);
        }
        public List <LdapUser> GetMembersOfGroup(LdapGroup group, DateTime?ldapModifiedDate)
        {
            _log.DebugFormat("Receiving list of users in group \"{0}\" from server.", group.Name);
            string          ldapModifiedUsersFilter = GetUserFilterWithMinModifiedOnAttributeOrDate(ldapModifiedDate);
            var             filter    = "(&" + ldapModifiedUsersFilter + _ldapUsersInGroupFilter + ")";
            List <LdapUser> usersList = GetUsersByLdapFilter(GetUserInGroupFilterString(filter, group));

            _log.DebugFormat("{0} users of group \"{1}\" received from server.", usersList.Count, group.Name);
            return(usersList);
        }
        private LdapGroup CreateLdapGroup(SearchResultEntry entry)
        {
            LdapGroup ldapGroup = new LdapGroup();

            ldapGroup.Id         = GetEntryIdentityAttribute(entry, _ldapGroupIdentityAttribute);
            ldapGroup.Name       = GetEntryRequiredAttributeStringValue(entry, _ldapGroupNameAttribute);
            ldapGroup.Dn         = entry.DistinguishedName;
            ldapGroup.ModifiedOn = GetEntryDateTimeAttributeValue(entry, _ldapEntryModifiedOnAttribute);
            return(ldapGroup);
        }
        private string GetUserInGroupFilterString(string filter, LdapGroup group)
        {
            string groupDn   = ReplaceSpecialCharacters(group.Dn);
            string groupName = ReplaceSpecialCharacters(group.Name);

            return(filter.Replace(MacroOpenBracket + DnMacroName + MacroCloseBracket, groupDn)
                   .Replace(MacroOpenBracket + LdapGroupNameAttributeSysSettingCode.Replace("Attribute", string.Empty) +
                            MacroCloseBracket, groupName).Replace(MacroOpenBracket + LdapGroupIdentityAttributeSysSettingCode
                                                                  .Replace("Attribute", string.Empty) + MacroCloseBracket, group.Id));
        }
        public List <LdapGroup> GetGroups()
        {
            _log.Debug("Obtaining list of user groups from server.");
            var groupsList = new List <LdapGroup>();

            string[] requiredGroupAttributes = GetRequiredGroupAttributes();
            var      request = new SearchRequest(_ldapGroupsEntry, _ldapGroupsFilter, SearchScope.Subtree,
                                                 requiredGroupAttributes);
            PageResultRequestControl paging = CreatePageResultRequestControl();

            request.Controls.Add(paging);
            SortRequestControl sortControl = CreateSortRequestControl(_ldapGroupNameAttribute);

            request.Controls.Add(sortControl);
            do
            {
                SearchResponse response;
                try {
                    response = _ldapConnection.SendRequest(request, RequestTimeout) as SearchResponse;
                } catch (Exception exception) {
                    LogLdapRequestError(exception, request);
                    throw;
                }
                if (response.ResultCode == ResultCode.Success)
                {
                    foreach (SearchResultEntry entry in response.Entries)
                    {
                        CheckEntryAttributes(entry, requiredGroupAttributes);
                        LdapGroup ldapGroup = CreateLdapGroup(entry);
                        groupsList.Add(ldapGroup);
                    }
                }
                else
                {
                    _log.DebugFormat("Unable to obtain the list of folders. Result code: {0}. Error: {1}.",
                                     response.ResultCode, response.ErrorMessage ?? string.Empty);
                }
                var responseControl = (PageResultResponseControl)Array.Find(response.Controls,
                                                                            item => item is PageResultResponseControl);
                paging.Cookie = responseControl.Cookie;
            } while (paging.Cookie.Length != 0);
            _log.DebugFormat("{0} user group(s) received from server.", groupsList.Count);
            return(groupsList);
        }
 public List <LdapUser> GetMembersOfGroup(LdapGroup group)
 {
     return(GetMembersOfGroup(group, null));
 }
 public int InsertMembersOfGroupToTable(LdapGroup group)
 {
     return(InsertMembersOfGroupToTable(group, "SysLDAPSynchUser"));
 }