Blog2Blog Maak je eigen Blog2Blog | Gratis je eigen blog c.q weblog op internet
Naamloos
Naamloos Home | Profile | Archives | Friends

[C#] Group membership in AD (nested groups also)31/10/2007

public static bool IsMember(string ldapGroup, string ldapUser)

{

DirectoryEntry de = new DirectoryEntry(ldapUser);

return IsMember(ldapGroup, de, false);

}

 

public static bool IsMember(string ldapGroup, DirectoryEntry de, bool member)

{

if (!member)

{

foreach (string memberof in de.Properties["memberof"])

{

DirectoryEntry de2 = new DirectoryEntry("LDAP://" + memberof);

if (de2.Properties["distinguishedName"][0].ToString().ToLower() == ldapGroup.ToLower().Split('/')[2])

{

return true;

}

if (de2.Properties["objectClass"].Contains("group"))

{

member = IsMember(ldapGroup, de2, member);

}

}

return member;

}

else

{

return member;

}

}

0 Comments | Post Comment | Permanent Link