ADAM vs ADAM user authentication with C # - cannot communicate

I installed an ADAM instance and added some testing users. From C #, I can bind to ADAM using a Windows account, but I cannot bind it to one of the ADAM users. (I can successfully bind adam users in ldp) and I made sure users are enabled by setting msDS-UserAccountDisabled to false. When I connect to my Windows account, I can successfully search and return properties for ADAM users, but I am still trying to authenticate them, when I try to connect to my ADAM user account, I get the error:

Error: System.Runtime.InteropServices.COMException (0x8007052E): Login failed: unknown username or invalid password. at System.DirectoryServices.DirectoryEntry.Bind (Boolean throwIfFail)

Here is the code I'm using:

string userName = txtUserName.Text;
string password = txtPassword.Text;
string ADConnectionString = "LDAP://localhost:389/CN=sandbox,DC=ITOrg";
DirectoryEntry entry = new DirectoryEntry(ADConnectionString);

entry.Username = "myComputer\\Administrator";
entry.Password = "myPassword";
try 
{
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(CN=" + userName + "))";
SearchResultCollection result = searcher.FindAll();
if (result.Count > 0)
{
    //bind with simple bind
    using (DirectoryEntry de = new DirectoryEntry(result[0].Path, userName, password,AuthenticationTypes.None))
    {
         if (de.Guid != null) // this is the line where it dies
         {
              Label1.Text = "Successfully authenticated";
              Label2.Text = result[0].Properties["displayName"][0].ToString();
              Label3.Text = result[0].Properties["telephoneNumber"][0].ToString();
          } else 
          {
             Lable1.Text = "Unable to Authenticate";
          }
     }
}
else
{
    Lable1.Text = "UserName :" + userName + " not found"; 
}
} catch(Exception ex)
{
     Label1.Text = "Error searching: " + ex.ToString();
}

      

Thanks in advance for any help, greatly appreciated!

+1


a source to share


1 answer


This is probably a username format issue. When authenticating an ADAM user to SDS, you must use a simple LDAP bind and use the ADAM-supported name format. ADAM technically allows a digest out to be used as well, but this is not available in SDS (SDS.Protocols only), so this is not your coding approach.

You are using simple binding because you have AuthenticationTypes.None set to keep the part in order. The part that is most likely wrong is the username format.

ADAM accepts the user's full name, their displayName (if set and unique) and / or the user's PrincipalName (if set and unique) as a bindable username, so start with the user's full DN and see if that works. If so, you can try other username values. Note that you can put whatever you want for displayName or userPrincipalName in ADAM. There is no confirmation. Just make sure the values ​​are unique.



If you really want to do something like ADAM bind authentication, you will get better performance and scale using the ValidateCredentials PrincipalContext method in .NET 3.5.

This stuff is documented and discussed in the forums at http://www.directoryprogramming.net all the time and this is the place I go to more often since this is my site. :) A friend sent me to this post or I would never have it have not seen.

+6


a source







All Articles