Anonymous_User Absent Member.
Absent Member.
389 views

LDAP bind error


When i run the code below, i get this:

Exception Details: Novell.Directory.Ldap.LdapException: 49

Source Error:
Line 35: ldapConn.Bind(userDN, userPasswd); Line 36:

Below is the full code:


Code:
--------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Authentication;
using Novell.Directory.Ldap;
using System.DirectoryServices;
using System.Net;

namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void login_Click(object sender, EventArgs e)
{
string userDN = "cn=" + usernametxt.Text;
string userPasswd = passwordtxt.Text;
string searchBase = "o=University";
string searchFilter = "objectClass=*";
// Creating an LdapConnection instance
LdapConnection ldapConn = new LdapConnection();

//Connect function will create a socket connection to the server
ldapConn.Connect("11.11.201.35", 389);

//Bind function will Bind the user object Credentials to the Server

ldapConn.Bind(userDN, userPasswd);

// Searches in the Marketing container and return all child entries just below this
//container i.e Single level search
LdapSearchQueue queue = ldapConn.Search(searchBase,
LdapConnection.SCOPE_ONE,
searchFilter,
null,
false,
(LdapSearchQueue)null,
(LdapSearchConstraints)null);

LdapMessage message;
while ((message = queue.getResponse()) != null)
{
if (message is LdapSearchResult)
{
LdapEntry entry = ((LdapSearchResult)message).Entry;
System.Console.Out.WriteLine("\n" + entry.DN);
System.Console.Out.WriteLine("\tAttributes: ");
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;
Console.WriteLine(attributeName + "value:" +attributeVal);
}
}
}
ldapConn.Disconnect();
}

}
}

--------------------


--
spyxdaxworld
------------------------------------------------------------------------
spyxdaxworld's Profile: http://forums.novell.com/member.php?userid=122409
View this thread: http://forums.novell.com/showthread.php?t=450596

Labels (1)
0 Likes
1 Reply
Anonymous_User Absent Member.
Absent Member.

Re: LDAP bind error

Check the error codes at
http://developer.novell.com/documentation/jldap/jldapenu/api/com/novell/ldap/LDAPException.html

49 INVALID_CREDENTIALS

Better, catch the LDAP exception and use ex.getMessage()

Your userDN does not look like a real DN
userDN = "cn=" + usernametxt.Text;

Also note that
bind(java.lang.String dn, java.lang.String passwd)
is deprecated

Wolfgang


On 11.01.2012 22:56, spyxdaxworld wrote:
>
> When i run the code below, i get this:
>
> Exception Details: Novell.Directory.Ldap.LdapException: 49
>
> Source Error:
> Line 35: ldapConn.Bind(userDN, userPasswd); Line 36:
>
> Below is the full code:
>
>
> Code:
> --------------------
>
> using System;
> using System.Collections.Generic;
> using System.Linq;
> using System.Web;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Security.Authentication;
> using Novell.Directory.Ldap;
> using System.DirectoryServices;
> using System.Net;
>
> namespace WebApplication1
> {
> public partial class _Default : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
>
> }
>
> protected void login_Click(object sender, EventArgs e)
> {
> string userDN = "cn=" + usernametxt.Text;
> string userPasswd = passwordtxt.Text;
> string searchBase = "o=University";
> string searchFilter = "objectClass=*";
> // Creating an LdapConnection instance
> LdapConnection ldapConn = new LdapConnection();
>
> //Connect function will create a socket connection to the server
> ldapConn.Connect("11.11.201.35", 389);
>
> //Bind function will Bind the user object Credentials to the Server
>
> ldapConn.Bind(userDN, userPasswd);
>
> // Searches in the Marketing container and return all child entries just below this
> //container i.e Single level search
> LdapSearchQueue queue = ldapConn.Search(searchBase,
> LdapConnection.SCOPE_ONE,
> searchFilter,
> null,
> false,
> (LdapSearchQueue)null,
> (LdapSearchConstraints)null);
>
> LdapMessage message;
> while ((message = queue.getResponse()) != null)
> {
> if (message is LdapSearchResult)
> {
> LdapEntry entry = ((LdapSearchResult)message).Entry;
> System.Console.Out.WriteLine("\n" + entry.DN);
> System.Console.Out.WriteLine("\tAttributes: ");
> 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;
> Console.WriteLine(attributeName + "value:" +attributeVal);
> }
> }
> }
> ldapConn.Disconnect();
> }
>
> }
> }
>
> --------------------
>
>

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.