directoryservices

Extending GroupPrincipal and Members property

北慕城南 提交于 2019-12-08 02:26:49
问题 I want to extend the GroupPrincipal class to handle some custom properties: using System.DirectoryServices.AccountManagement; [DirectoryRdnPrefix("CN")] [DirectoryObjectClass("group")] public class MyGroupPrincipal : GroupPrincipal { // ... } How could I override the Members property for MyGroupPrincipal so that if it has a member that is a group an instance of MyGroupPrincipal and not of GroupPrincipal is returned? I would like to write e.g. MyGroupPrincipal group = GetGroup(); foreach (var

Using DirectorySearcher to query multiple OUs

拥有回忆 提交于 2019-12-07 15:33:29
I have the following code: var directoryEntry = new DirectoryEntry(distributionListsListADSPath); var directorySearcher = new DirectorySearcher(directoryEntry) { SizeLimit = int.MaxValue, PageSize = int.MaxValue }; var result = directorySearcher.FindAll(); The problem is I want to search two seperate OUs. So what I do is run through this twice, once where private const string distributionListsListADSPath = "LDAP://OU=Distribution Lists,OU=Groups,DC=enron,DC=com"; and a second where it is private const string distributionListsListADSPath = "LDAP://OU=Security Groups,OU=Groups,DC=enron,DC=com";

Method for copying large amounts of data in C#

自闭症网瘾萝莉.ら 提交于 2019-12-07 14:19:56
问题 I am using the following method to copy the contents of a directory to a different directory. public void DirCopy(string SourcePath, string DestinationPath) { if (Directory.Exists(DestinationPath)) { System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(DestinationPath); foreach (FileInfo file in downloadedMessageInfo.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories()) { dir.Delete(true); } } //======================================

Unable to turn on SecureSocketLayer with DirectoryServices.Protocols.LdapConnection

强颜欢笑 提交于 2019-12-07 05:30:11
问题 I am trying to fix a bug with SSL in a product and noticed that although the code sets SSL to be true, in the next line in the code SSL is still at false. I wrote a unit test for this and the unit test confirms my suspicions. [TestMethod] public void SecureSocketLayerSetToTrue( ) { var ldapConnection = new LdapConnection( new LdapDirectoryIdentifier( "ldap.test.com", 636 )); ldapConnection.SessionOptions.SecureSocketLayer = true; Assert.IsTrue( ldapConnection.SessionOptions.SecureSocketLayer

Active Directory List OU's

霸气de小男生 提交于 2019-12-07 02:39:32
问题 I have this code currently, string defaultNamingContext; DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"); defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString(); rootDSE = new DirectoryEntry("LDAP://" + defaultNamingContext); //DirectoryEntry domain = new DirectoryEntry((string)"LDAP://" + defaultNamingContext); DirectorySearcher ouSearch = new DirectorySearcher(rootDSE,"(objectCategory=Organizational-Unit)", null, SearchScope.Subtree); MessageBox

“new DirectoryEntry(distinguishedName as string)” doesn't work when DN contains a “/”

主宰稳场 提交于 2019-12-06 12:37:33
问题 I have the following code to convert a distinguishedName to a sAMAccountName: Dim de As New DirectoryEntry("LDAP://" & stringDN) Return CType(de.Properties("samaccountname")(0), String) It works great for every DN I pass it, except for one. We have an AD group on our domain that has a "/" in it - call it "Programmers/DBAs". The DN for this group is "Programmers/DBAs,OU=User Groups,DC=mydomain,DC=local". When I try to use this DN as the stringDN above, I get a COMException of "Unknown error

Mocking the “Properties” property of DirectoryEntry

末鹿安然 提交于 2019-12-06 09:23:39
问题 I'm trying to unit test some Active Directory code, pretty much the same as outlined in this question: Create an instance of DirectoryEntry for use in test The accepted answer suggests implementing a wrapper/adapter for the DirectoryEntry class, which I have: public interface IDirectoryEntry : IDisposable { PropertyCollection Properties { get; } } public class DirectoryEntryWrapper : DirectoryEntry, IDirectoryEntry { } The problem is that the " Properties " property on my IDirectoryEntry mock

How do I add a user to AD using System.DirectoryServices.AccountManagement?

百般思念 提交于 2019-12-06 08:11:20
问题 Using the .net 3.5 framework and C# I'm trying to add a new user to AD from C# and can't find any examples. I see that the PrincipalCollection object has an overloaded 'add' method but can't seem to figure out how it works. Can anyone help? How create a new user object, add it into AD. Secondly, the user that will be adding in new people may not actually have the security to do this. Is there a way that I can impersonate another user account that will have permissions and add the account that

Extending GroupPrincipal and Members property

可紊 提交于 2019-12-06 07:35:46
I want to extend the GroupPrincipal class to handle some custom properties: using System.DirectoryServices.AccountManagement; [DirectoryRdnPrefix("CN")] [DirectoryObjectClass("group")] public class MyGroupPrincipal : GroupPrincipal { // ... } How could I override the Members property for MyGroupPrincipal so that if it has a member that is a group an instance of MyGroupPrincipal and not of GroupPrincipal is returned? I would like to write e.g. MyGroupPrincipal group = GetGroup(); foreach (var m in group.Members) { if (m is MyGroupPrincipal) { // always fails: m is a normal GroupPrincipal // do

Authentication Types when switching from System.DirectoryServices to DirectoryServices.Protocols

自闭症网瘾萝莉.ら 提交于 2019-12-06 07:08:17
问题 I need to know the equivalent AuthType values from AuthenticationTypes to migrate from S.DS to S.DS.P code. I am rewriting an LDAP connection module that currently uses the System.DirectoryServices namespace. To increase compatibility with non-ActiveDirectory servers, I am trying to rewrite all of the code to use System.DirectoryServices.Protocols (as per the suggestion in "The .NET Developer's Guide to Directory Services Programming). Everything is going smoothly except for the transition