i am working on .net core project which require authentication to LDAP AD, i'm using Novell library to help me connect to the LDAP AD Server, but when i run the code it's taking around 2 minutes to get the response. Can anyone show me what's wrong? For your information, i'm hosting the .net core project on ubuntu server and the LDAP AD Server is in Windows Azure server.
Here's the code, thanks.
public ADResponse LdapSearch(string server, string filter, string username, string password)
{
try
{
using (var connection = new LdapConnection { SecureSocketLayer = false })
{
string DN = configuration.GetValue<string>("LdapServer:TeacherDN");
if (server == configuration.GetValue<string>("LdapServer:LdapStudent"))
{
DN = configuration.GetValue<string>("LdapServer:sphStudentDN");
}
int serverPort = configuration.GetValue<int>("LdapServer:sphLdapPort");
string[] attributes = { "name", "mail", "extensionAttribute2", "memberOf" };
connection.Connect(server, serverPort);
connection.Bind(username, password);
if (connection.Bound)
{
ADResponse data = new ADResponse();
LdapSearchQueue queue = connection.Search(DN,
LdapConnection.SCOPE_SUB,
filter,
attributes,
false,
(LdapSearchQueue)null,
(LdapSearchConstraints)null);
LdapMessage message;
while ((message = queue.getResponse()) != null)
{
if (message is LdapSearchResult)
{
LdapEntry entry = ((LdapSearchResult)message).Entry;
LdapAttributeSet attributeSet = entry.getAttributeSet();
System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
while (ienum.MoveNext())
{
LdapAttribute attribute = (LdapAttribute)ienum.Current;
string attributeName = attribute.Name;
string attributeVal = attribute.StringValue;
if (attributeName == "name")
{
data.name = attributeVal;
}
else if (attributeName == "mail")
{
data.mail = attributeVal;
}
else if (attributeName.ToLower() == "postofficebox")
{
data.pobox = attributeVal;
}
else if (attributeName.ToLower() == "extensionattribute2")
{
data.extensionattribute = attributeVal;
}
else if (attributeName.ToLower() == "memberof")
{
data.memberof = attributeVal;
}
}
}
}
connection.Disconnect();
return data;
}
}
}
catch (LdapException ex)
{
// Log exception
}
return null;
}
UPDATE :
The speed of querying is much faster in windows server, so i've already tried to host it on windows server and the process of querying ldap only take about 5 seconds. Anyone know why is that happen?
UPDATE :
I have tried to access another AD (From this public test AD) from the ubuntu server and its run smoothly and take only 2 second to query.