Example #1
0
        public void BuildFilter_With_Null_Condition()
        {
            // act
            var res = LdapHelps.BuildFilter(null);

            // assert
            res.ShouldBe("(&(objectClass=*))");
        }
Example #2
0
        public void BuildFilter_With_Empty_Condition()
        {
            // act
            var res = LdapHelps.BuildFilter(new Dictionary <string, string>());

            // assert
            res.ShouldBe("(&(objectClass=*))");
        }
Example #3
0
        public void BuildFilter_With_Condition()
        {
            // act
            var conditions = new Dictionary <string, string>
            {
                { "objectClass", "testClassA" }, { "objectCategory", "testCategoryA" }, { "name", null }
            };
            var res = LdapHelps.BuildFilter(conditions);

            // assert
            res.ShouldBe("(&(objectClass=testClassA)(objectCategory=testCategoryA))");
        }
        protected virtual IList <T> Query <T>(string searchBase, Dictionary <string, string> conditions) where T : class, ILdapEntry
        {
            var filter = LdapHelps.BuildFilter(conditions);

            var result = new List <T>();

            using var ldapConnection = GetConnection();

            var search = ldapConnection.Search(
                searchBase,
                LdapConnection.ScopeSub,
                filter,
                Attributes,
                false);

            while (search.HasMore())
            {
                try
                {
                    var nextEntry = search.Next();
                    if (typeof(T) == typeof(LdapOrganization))
                    {
                        result.Add(new LdapOrganization(nextEntry.GetAttributeSet()) as T);
                    }

                    if (typeof(T) == typeof(LdapUser))
                    {
                        result.Add(new LdapUser(nextEntry.GetAttributeSet()) as T);
                    }
                }
                catch (LdapException e)
                {
                    Logger.LogException(e);
                }
            }

            return(result);
        }