Esempio n. 1
0
        private T QueryOne <T>(string searchBase, Dictionary <string, string> conditions) where T : class, ILdapEntry
        {
            var filter = LdapHelps.BuildFilter(conditions);

            using (var ldapConnection = GetConnection())
            {
                var search = ldapConnection.Search(searchBase, LdapConnection.SCOPE_SUB, filter,
                                                   _attributes, false, null, null);

                LdapMessage message;
                while ((message = search.getResponse()) != null)
                {
                    if (!(message is LdapSearchResult searchResultMessage))
                    {
                        continue;
                    }
                    var entry = searchResultMessage.Entry;
                    if (typeof(T) == typeof(LdapOrganization))
                    {
                        return(new LdapOrganization(entry.getAttributeSet()) as T);
                    }

                    if (typeof(T) == typeof(LdapUser))
                    {
                        return(new LdapUser(entry.getAttributeSet()) as T);
                    }
                    return(null);
                }
            }
            return(null);
        }
Esempio n. 2
0
        public void BuildCondition_With_Value()
        {
            // act
            var res = LdapHelps.BuildCondition("objectClass", "testNameA");

            // assert
            res.ShouldBe("(objectClass=testNameA)");
        }
Esempio n. 3
0
        public void BuildFilter_With_Empty_Condition()
        {
            // act
            var res = LdapHelps.BuildFilter(new Dictionary <string, string>());

            // assert
            res.ShouldBe("(&(objectClass=*))");
        }
Esempio n. 4
0
        public void BuildFilter_With_Null_Condition()
        {
            // act
            var res = LdapHelps.BuildFilter(null);

            // assert
            res.ShouldBe("(&(objectClass=*))");
        }
Esempio n. 5
0
        public void BuildCondition_With_WhiteSpace_Value()
        {
            // act
            var res = LdapHelps.BuildCondition("objectClass", "   ");

            // assert
            res.ShouldBeEmpty();
        }
Esempio n. 6
0
        public void BuildCondition_With_Null_Value()
        {
            // act
            var res = LdapHelps.BuildCondition("objectClass", null);

            // assert
            res.ShouldBeEmpty();
        }
Esempio n. 7
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))");
        }