I have developed a C# application using monodevelop, which basically does ldap authentication with windows active directory. It works fine in windows, but if I use the same code in Ubuntu instead of authenticating to windows active directory, I think it is trying to authenticate with novell active directory. It fails with novell.ldap.exception saying invalid credentials.
I have removed all the references to novell.directory.ldap, but system.directoryServices is internally referring to novell assembly.
My requirement is to use same set of .net assemblies System.DirectoryServices in both windows and Linux and authenticate with windows active directory.
Is there any way I can achieve this using C# monodevelop?
This is the piece of code always failing in ubuntu at Findall with invalid credentials. because it is always pointing to novell active directory
string strLdapURL = "LDAP://" + Domain + ":389";
DirectoryEntry entry = new DirectoryEntry(strLdapURL, strUserName, Password);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(ObjectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=2)(operatingSystem=*server*))";
mySearcher.PropertiesToLoad.Add("PwdLastSet");
mySearcher.SizeLimit = int.MaxValue;
mySearcher.PageSize = int.MaxValue;
mySearcher.Tombstone = false;
mySearcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
System.DirectoryServices.SearchResultCollection entry1 = mySearcher.FindAll(); 1 Answer
I fixed it myself
My assumption was wrong that novell.directory.ldap was pointing to novell's active directory structure. This works with windows active directory also, it's just a matter of specifying the proper windows active directory URL.
I just added reference to novell.directory.ldap assembly, and then in the credentials changed username administrator to Administrator(case sensitive).
Earlier I was just using username in the binding operation; there I appended domain name also like domain\Administrator. I was able to get it working.
string strDomain = "domain";
string strUserName = "Administrator";
string Password = "Password123";
String loginDN = strDomain + "\\" + strUserName;
int LdapVersion = LdapConnection.Ldap_V3;;
String ldapHost = domain;
string strLdapURL = "LDAP://" + Domain + ":389";
LdapConnection lc = new LdapConnection();
lc.Connect( ldapHost, LdapPort );
lc.Bind( LdapVersion, loginDN, password );