Exemple #1
0
 /// <summary>
 /// Returns an LdapFilter for Users and contacts in a group.
 /// </summary>
 /// <param name="group">The group's Distinguished Name.</param>
 /// <returns>LdapFilter for the Users and Contacts.</returns>
 public static LdapFilter UsersContactsInGroup(DistinguishedName group) =>
 LdapFilter.And(
     new LdapFilter("objectCategory=person"),
     LdapFilter.Or(
         new LdapFilter("objectClass=contact"),
         new LdapFilter("objectClass=user")),
     new LdapFilter("memberOf", "=", $"{group}"));
Exemple #2
0
        public void Z_Complex_1()
        {
            // Arrange
            var expected = "(&(objectCategory=person)(objectClass=user)"
                           + "(!(userAccountControl:1.2.840.113556.1.4.803:=65536))"
                           + "(!(userAccountControl:1.2.840.113556.1.4.803:=2))"
                           + "(!samaccountname=gen-*)(!samaccountname=tst-*)"
                           + "(!samaccountname=adm-*)(!samaccountname=res-*)"
                           + "(!samaccountname=tmp-*)(!samaccountname=trn-*)"
                           + "(!samaccountname=app-*)(!samaccountname=svc-*)"
                           + "(!samaccountname=*test*)(!samaccountname=*$))";

            // Act
            var filter =
                LdapFilter.And(
                    new LdapFilter("objectCategory=person"),
                    new LdapFilter("objectClass=user"),
                    new LdapFilter("userAccountControl:1.2.840.113556.1.4.803:=65536").Not(),
                    new LdapFilter("userAccountControl:1.2.840.113556.1.4.803:=2").Not(),
                    new LdapFilter("samaccountname=gen-*").Not(),
                    new LdapFilter("samaccountname=tst-*").Not(),
                    new LdapFilter("samaccountname=adm-*").Not(),
                    new LdapFilter("samaccountname=res-*").Not(),
                    new LdapFilter("samaccountname=tmp-*").Not(),
                    new LdapFilter("samaccountname=trn-*").Not(),
                    new LdapFilter("samaccountname=app-*").Not(),
                    new LdapFilter("samaccountname=svc-*").Not(),
                    new LdapFilter("samaccountname=*test*").Not(),
                    new LdapFilter("samaccountname=*$").Not());

            // Assert
            Assert.Equal(expected, filter.ToString());
        }
Exemple #3
0
        public void Compound_Element_And_Multiple_Filters()
        {
            // Arrange
            var expected = "(&(objectCategory=person)(objectClass=contact)(sn=Easterling))";
            var filter1  = new LdapFilter("objectCategory=person");
            var filter2  = new LdapFilter("objectClass=contact");
            var filter3  = new LdapFilter("sn=Easterling");

            // Act
            var filter = LdapFilter.And(filter1, filter2, filter3);

            // Assert
            Assert.Equal(expected, filter.ToString());
        }
        public void Users_Whose_Passwords_Do_Not_Expire()
        {
            // Arrange
            const string expected = "(&(&(objectCategory=person)(objectClass=user))"
                                    + "(userAccountControl:1.2.840.113556.1.4.803:=65536))";

            // Act
            var filter = LdapFilter.And(
                ActiveDirectoryCommonFilters.Users,
                ActiveDirectoryCommonFilters.UserAccessControl(ADS_USER_FLAG.DONT_EXPIRE_PASSWD));

            // Assert
            Assert.Equal(expected, filter.ToString());
        }
        public void Users_Who_Are_Locked_Out()
        {
            // Arrange
            const string expected = "(&(&(objectCategory=person)(objectClass=user))"
                                    + "(userAccountControl:1.2.840.113556.1.4.803:=16))";

            // Act
            var filter = LdapFilter.And(
                ActiveDirectoryCommonFilters.Users,
                ActiveDirectoryCommonFilters.UserAccessControl(ADS_USER_FLAG.LOCKOUT));

            // Assert
            Assert.Equal(expected, filter.ToString());
        }
Exemple #6
0
        public void Z_Complex_2()
        {
            // Arrange
            var expected = "(&(objectCategory=person)(objectClass=contact)(|(sn=Easterling)(sn=Zivuku)))";

            // Act
            var filter =
                LdapFilter.And(
                    new LdapFilter("objectCategory=person"),
                    new LdapFilter("objectClass=contact"),
                    new LdapFilter("sn=Zivuku").Or("sn=Easterling"));

            // Assert
            Assert.Equal(expected, filter.ToString());
        }
Exemple #7
0
 /// <summary>
 /// Returns an LdapFilter for Users that were created before the specified date.
 /// </summary>
 /// <param name="firstDate">The first date of the range.</param>
 /// <param name="secondDate">The second date of the range.</param>
 /// <returns>LdapFilter for the Users.</returns>
 public static LdapFilter UsersCreatedBetweenDates(DateTime firstDate, DateTime secondDate) =>
 Users.And(
     LdapFilter.And(
         new LdapFilter("whenCreated", ">=", AdDateTime.ToLdapDateTime(firstDate)),
         new LdapFilter("whenCreated", "<=", AdDateTime.ToLdapDateTime(secondDate))),
     true);