tags:

views:

29

answers:

2

I have been trying to find some tutorials on how to connect to OpenDS using .NET's LDAP types to no avail. Can anyone point me to some articles/tutorials that have good samples on using OpenDS as a directory service and accessing and working with it using C#.

This is what I have tried so far, but always get an invalid username/password error. I'm stuck at what credentials need to go in or if what i'm trying to do makes any sense at all.

DirectoryEntry directoryEntry = new DirectoryEntry
                                            {
                                                Path = @"LDAP://SUnnikris-va-d:389/dc=example,dc=com",
                                                Username = "uid=user.0",
                                                Password = "TestPass!",
                                                AuthenticationType = AuthenticationTypes.ServerBind
                                            };

        directoryEntry.RefreshCache();

        DirectoryEntry newUser = directoryEntry.Children.Add("uid=nuser,ou=People,dc=example,dc=com", "person");
        newUser.Properties["objectClass"].Value = new object[] { "top", "person", "organizationalPerson", "inetorgPerson" };
        newUser.Properties["uid"].Value = "nuser";
        newUser.Properties["givenName"].Value = "new";
        newUser.Properties["sn"].Value = "user";
        newUser.Properties["cn"].Value = "new user";
        newUser.Properties["userPassword"].Value = "nuser";
        newUser.CommitChanges();
A: 

I guess your username is wrong you need to put the full ldap path of the username i.e. uid=admin,ou=AdminOU,dc=example,dc=com

you can also use System.DirectoryServices.AccountManagement for easiser implementation have a look here -> http://anyrest.wordpress.com/2010/06/28/active-directory-c/

Raymund
A: 

I figured it out, OpenDS uses the canonical name as the superuser for administration. Essentially, the problem was with the credentials I was using, instead of a uid I had to specify this:-

NetworkCredential myCreds = new NetworkCredential("cn=Directory Manager", "TestPass!");
Cranialsurge