سؤال

I know this question has been asked before, and I apologize for opening yet another one, however all the solutions that I've read on-line have not fixed the problem I have. For reasons best left unsaid, I need to get this working within the next three days. I've only used LDAP once before and I have no one here who can help me (not even the admin).

Here is the basic code I'm trying:

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://serverName.dev.domain.com:portNumber/o-domain,o=dxc.com","uid=userName,ou=bindids,o=domain,o=dcx.com", "password", AuthenticationTypes.None); 
DirectorySearcher dSearch = new DirectorySearcher(rootEntry);
try
{
foreach (SearchResult result in dSearch.FindAll())

Etc. This fails on the dSearch.FindAll() line

I have no query written at this time (suggestions/syntax on that would be AWESEOME) because I have no idea what values I need to pull back from the directory. I've been told by the admin that this is NOT Active Directory.

When I remove AuthenticationTypes, I get a different error saying that I have an unknown username or bad password. My admin has checked both and assures me that they work. He even reset the password, in case it was a reserved character issue.

Any help or thoughts you can provide would be greatly appreciated. I've been working at this for about 12 hours straight and my brain is frazzled.

EDIT: Here's the full error

Error: An invalid dn Syntax has been specified

@Alexanderius - Thank you for the alternative format. With this I get a COMException: The server is not Operational.

@X3074861X - It's an Oracle Directory Server (aka SUN One Directory Server).

EDIT: I have modified my code slightly. (Changing o-Domain to o=Domain and added a different query). Now I'm getting a COMException: "There is no such object on the server".

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://ServerName.Domain.com:2394/o=Domanin,o=dxc.com",
                    "uid=UserName,ou=bindids,o=Domain,o=dcx.com", "Password", AuthenticationTypes.None);
DirectorySearcher dSearch = new DirectorySearcher(rootEntry);
dSearch.Filter = "uid=" + "AUser";
dSearch.SizeLimit = 100;
dSearch.SearchScope = SearchScope.Subtree;
try
{
SearchResult newTest = dSearch.FindOne();

ETC.

UPDATE: THERE'S ANOTHER ERROR THAT I DIDN'T NOTICE!! After the bind statement, when I hover over "rootEntry", I see it has a 'System.Runtime.InteropServices.COMException: Unspecified error \r\n". It's not that helpful to me, but maybe one of you folks have seen it before?

لا يوجد حل صحيح

نصائح أخرى

I am connecting to my AD like this:

DirectoryEntry = new DirectoryEntry("LDAP://Myserver/MyRootEntry,dc=MyDomainName,dc=net", "SomeUserName", "SomeUserPassword", AuthenticationTypes.Secure);

My server name is: myserver.mydomain.net

Try to connect like that.

I've been using this implementation for authenticating patrons with iPlanet, which is built from the SUN stack, so it should work against an Oracle Directory server as well. For customization and some of the lower level specifics, I'm a huge fan of the System.DirectoryServices and System.DirectoryServices.Protocols libraries, especially when working with non-AD directory servers :

// build your server name - we'll use 'serverName.dev.domain.com' and port 389
var BuildServerName = new StringBuilder();
BuildServerName.Append("serverName.dev.domain.com");
BuildServerName.Append(":" + Convert.ToString(389));

// setup an ldapconnection to that endpoint
var ldapConnection = new LdapConnection(BuildServerName.ToString());

Now we need to detail some information about this connection :

// it looks like you have an administrative account to bind with, so use that here
var networkCredential = new NetworkCredential("userName", "password", "dc=MyDomainName,dc=net");

// set the following to true if it's over ssl (636), if not just set it to false
ldapConnection.SessionOptions.SecureSocketLayer = SSL;
ldapConnection.SessionOptions.VerifyServerCertificate += delegate { return true; };

// now set your auth type - I typically use 'negotiate' over LDAPS, and `simple` over LDAP
// for this example we'll just say you're not using LDAPS
ldapConnection.AuthType = AuthType.Basic;
ldapConnection.Bind(networkCredential);

Now you should be bound to the directory, which means you can search it using the SearchRequest object. Here is an example of how I use it :

// setup a new search request
var findThem = new SearchRequest();
findThem.Filter = "This is where you need to construct a filter for what you're looking for"
findThem.Scope = System.DirectoryServices.Protocols.SearchScope.Subtree;

// we'll execute a search using the binded administrative user
var searchresults = (SearchResponse) ldapConnection.SendRequest(findThem);

// this will contain entries if your search filter returned any results
if(searchresults.Entries.Count >= 1)
{
     // here are your list of returned entries
     SearchResultEntryCollection entries = searchresults.Entries;

     // do some work\extraction on them 
}

The last part here is your actual LDAP filter. If you wanted to search within your domain for a user with a uid of userName, your filter would be :

findthem.Filter = "(uid=username)";

If you want to combine say an objectClass with a specific attribute, you would do :

findthem.Filter = "(&(objectClass=user)(uid=username))";

And here are some good links on filtering :

LDAP Filtering Syntax

LDAP Query Basics

Oracle LDAP Search Filters

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top