Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrincipalContext - I Can't connect to a local openldap server

I have installed an openldap for windows server and I use LDAPAdmin to connect to it by its default values :

Server=ldap://localhost:389
Base:dc=maxcrc,dc=com
UserName:cn=Manager,dc=maxcrc,dc=com
Password:secret

Now I want to use PrincipalContext to add users to my ou=People The problem is I can't even connect to the server using PrincipalContext. I have searched the Net and found a lot of answers on how to connect to a ldap server but none of them are working for me.I keep getting a NullReferenceException or ServerNotFoundException for different combination of provided parameters for PrincipalContext constructor. I thought I could use PrincipalContext as one of the follows :

new PirncipalContext(ContextType.Domain,"maxcrc.com","dc=maxcrc,dc=com")

or

new PrincipalContext(ContextType.ApplicationDirectory,"localhost:389","dc=maxcrc,dc=com")

but none of them are working.Some say that I should provide username and password so I did that but I keep getting exception.

So please tell me how can I use PrincipalContext to connect to openldap ?

P.S. My computer is already joined to an Active Directory domain controller.

like image 309
Beatles1692 Avatar asked Mar 11 '15 14:03

Beatles1692


People also ask

How do I fix LDAP Server Unavailable?

Navigate to Administration > Settings > Advanced > Security > LDAP settings > LDAP connections. Check the connections and remove the IP address from the LDAP Server address field.


1 Answers

As the official documentation on MSDN states:

The System.DirectoryServices.AccountManagement namespace provides uniform access and manipulation of user, computer, and group security principals across the multiple principal stores: Active Directory Domain Services (AD DS), Active Directory Lightweight Directory Services (AD LDS), and Machine SAM (MSAM). System.DirectoryServices.AccountManagement manages directory objects independent of the System.DirectoryServices namespace.

Those classes are useful for Active Directory only - they are not portable to other, "generic" LDAP stores.

If you need to support OpenLDAP, either use DirectoryEntry and those functions, or use the lower level System.DirectoryServices.Protocol (bare-bones LDAP) layer.

like image 75
marc_s Avatar answered Nov 15 '22 04:11

marc_s