Reputation: 165
I've set up slapd and created some basic Users and Groups.
In my code (.NET 7.0), I'm able to bind to the slapd LDAP server with a user named test as follows:
string userDN = "cn=test,ou=DepartmentOne,dc=example,dc=com", userPassword = "test";
var ldapConnection = new LdapConnection(new LdapDirectoryIdentifier("localhost", 389))
{
AuthType = AuthType.Basic
};
ldapConnection.SessionOptions.ProtocolVersion = 3;
ldapConnection.Bind(new NetworkCredential(userDN, userPassword));
My problem is that I can't expect users to know their DistinguishedName (DN) before binding, but they must fill in their DN to bind to the slapd LDAP server or else the server will return Error Code 49. If, for example, I only know that my username is "test", and I don't know that I'm in the OrganizationalUnit (OU) named DepartmentOne, then I'm unable to bind to the server.
I use Bind() to authenticate users, and what I need is to configure slapd so that users don't have to fill in their DN but merely their username in order to bind succesfully. It's only after binding that I want to check whether or not the user is part of the DepartmentOne OU and authenticate them accordingly. Currently, it works the other way around: I must already know what OU my test user is in before I can bind and thereby authenticate.
How do I configure slapd so that I'm able to bind with the following code (or similar code) instead (where I don't get an error related to invalid credentials/invalid DN syntax):
string username = "test", userPassword = "test";
var ldapConnection = new LdapConnection(new LdapDirectoryIdentifier("localhost", 389))
{
AuthType = AuthType.Basic
};
ldapConnection.SessionOptions.ProtocolVersion = 3;
ldapConnection.Bind(new NetworkCredential(username, userPassword));
Upvotes: 0
Views: 228