I have seen several questions that suggest something to do with users and groups but I have no idea what their use cases are.
All that I am trying to do is find the group that a user is linked to after they have been successfully authenticated.
using the following:
public bool LogInViaLDAP(LoginDTO userForLoginDto)
{
var user = userForLoginDto.Username;
string userDn = $"cn={user},ou=users,ou=system";
using (var connection = new LdapConnection { SecureSocketLayer = _isSecureSocketLayer })
{
connection.ConnectionTimeout = 36000;
connection.Connect(_domain, _port);
connection.Bind(userDn, userForLoginDto.Password);
string[] requiredAttributes = { "cn", "sn", "ou" };
string searchFilter = "objectClass=inetOrgPerson";
//this is where I was attempting to find the user's group association.
var groups = SearchForGroup(connection, userDn, searchFilter, requiredAttributes, false);
if (connection.Bound)
return true;
}
return false;
}
HashSet<string> SearchForGroup(LdapConnection connection, string user, string searchFilter, string[] requiredAttributes, bool typesOnly)
{
var result = connection.Search(user, LdapConnection.ScopeSub, searchFilter, requiredAttributes, typesOnly);
LdapEntry nextEntry = null;
while (result.HasMore())
{
nextEntry = result.Next();
}
//This only seems th return the
//sn - surname and cn - common name.
var data = nextEntry.GetAttributeSet();
return new HashSet<string>();
}