Tech Support > Operating Systems > Windows 2003 > ADAM - help with hopefully newbie question
ADAM - help with hopefully newbie question
Posted by Spencer Harbar [MVP] on March 5th, 2004


Hi!

I am hoping someone out there can help me...
I have the following code:

//user supplied credentials
string NTUser = TxtNTUser.Value;
string NTPassword = TxtNTPassword.Value;

//first bind is as ADAM admin
string ldpQuery = "LDAP://localhost:389/CN=mcmsadam,O=Harbar,C=NET";

string ldpAdminUID = "DESTINY\\harbars";
string ldpAdminPwd = "notstupidenuff2giveoutpassword";

DirectoryEntry de = new DirectoryEntry (ldpQuery, ldpAdminUID, ldpAdminPwd, AuthenticationTypes.Secure);

//now we're 'binded' try the user supplied credentials...

try
{
string sLDAPobj = "CN=mcmsadam,O=harbar,c=NET";
string sBindName = "CN=" + TxtNTUser.Value + ",O=harbar,c=NET";

DirectoryEntry ent = new DirectoryEntry("LDAP://localhost:389/" + sLDAPobj, sBindName, NTPassword, AuthenticationTypes.None);

//not until you attempt attribute retrieval will a bind occur
string sUser = (string)ent.Properties["name"].Value;

//do redirect
CmsAuthenticationTicket ticket = CmsFormsAuthentication.AuthenticateAsUser(NTUser, NTPassword);

if( ticket != null )
{
CmsFormsAuthentication.RedirectFromLoginPage(ticke t, true, CheckPersistent.Checked);
}
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

my problem is that the first bind works (if I query an attribute of the de object in the immediate window - i get the value no problems).

However, the second one - the line which retreives the attribute - fails - with the message "there is no such object on the server".
If i do the bind as previously (Secure auth type and same admin creds) it works



I pretty much copied the code from an ADAM webcast

Can anybody shed light on this?


--
thx
Spence
www.harbar.net/mcms/

Posted by Al Mulnick on March 5th, 2004


Afraid I can't fix it off the cuff, but maybe I can help narrow it down a little.
Why are your authentication types different?
Is anything logged in the ADAM Instance event log? Have you turned up the logging just in case?
Why are your creds in NTLM format in the part that works and in LDAP format in the other?

Al
"Spencer Harbar [MVP]" <spence@harbar.net> wrote in message news:OYeOnZlAEHA.3048@tk2msftngp13.phx.gbl...
Hi!

I am hoping someone out there can help me...
I have the following code:

//user supplied credentials
string NTUser = TxtNTUser.Value;
string NTPassword = TxtNTPassword.Value;

//first bind is as ADAM admin
string ldpQuery = "LDAP://localhost:389/CN=mcmsadam,O=Harbar,C=NET";

string ldpAdminUID = "DESTINY\\harbars";
string ldpAdminPwd = "notstupidenuff2giveoutpassword";

DirectoryEntry de = new DirectoryEntry (ldpQuery, ldpAdminUID, ldpAdminPwd, AuthenticationTypes.Secure);

//now we're 'binded' try the user supplied credentials...

try
{
string sLDAPobj = "CN=mcmsadam,O=harbar,c=NET";
string sBindName = "CN=" + TxtNTUser.Value + ",O=harbar,c=NET";

DirectoryEntry ent = new DirectoryEntry("LDAP://localhost:389/" + sLDAPobj, sBindName, NTPassword, AuthenticationTypes.None);

//not until you attempt attribute retrieval will a bind occur
string sUser = (string)ent.Properties["name"].Value;

//do redirect
CmsAuthenticationTicket ticket = CmsFormsAuthentication.AuthenticateAsUser(NTUser, NTPassword);

if( ticket != null )
{
CmsFormsAuthentication.RedirectFromLoginPage(ticke t, true, CheckPersistent.Checked);
}
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

my problem is that the first bind works (if I query an attribute of the de object in the immediate window - i get the value no problems).

However, the second one - the line which retreives the attribute - fails - with the message "there is no such object on the server".
If i do the bind as previously (Secure auth type and same admin creds) it works



I pretty much copied the code from an ADAM webcast

Can anybody shed light on this?


--
thx
Spence
www.harbar.net/mcms/

Posted by Arild Bakken on March 5th, 2004


Also, is the ADAM user member of any groups so that it has enough permissions to see and read the object in question?

Arild
"Al Mulnick" <amulnick_No_SPAM@ncDOTrr.com> wrote in message news:eihU$qlAEHA.3004@TK2MSFTNGP10.phx.gbl...
Afraid I can't fix it off the cuff, but maybe I can help narrow it down a little.
Why are your authentication types different?
Is anything logged in the ADAM Instance event log? Have you turned up the logging just in case?
Why are your creds in NTLM format in the part that works and in LDAP format in the other?

Al
"Spencer Harbar [MVP]" <spence@harbar.net> wrote in message news:OYeOnZlAEHA.3048@tk2msftngp13.phx.gbl...
Hi!

I am hoping someone out there can help me...
I have the following code:

//user supplied credentials
string NTUser = TxtNTUser.Value;
string NTPassword = TxtNTPassword.Value;

//first bind is as ADAM admin
string ldpQuery = "LDAP://localhost:389/CN=mcmsadam,O=Harbar,C=NET";

string ldpAdminUID = "DESTINY\\harbars";
string ldpAdminPwd = "notstupidenuff2giveoutpassword";

DirectoryEntry de = new DirectoryEntry (ldpQuery, ldpAdminUID, ldpAdminPwd, AuthenticationTypes.Secure);

//now we're 'binded' try the user supplied credentials...

try
{
string sLDAPobj = "CN=mcmsadam,O=harbar,c=NET";
string sBindName = "CN=" + TxtNTUser.Value + ",O=harbar,c=NET";

DirectoryEntry ent = new DirectoryEntry("LDAP://localhost:389/" + sLDAPobj, sBindName, NTPassword, AuthenticationTypes.None);

//not until you attempt attribute retrieval will a bind occur
string sUser = (string)ent.Properties["name"].Value;

//do redirect
CmsAuthenticationTicket ticket = CmsFormsAuthentication.AuthenticateAsUser(NTUser, NTPassword);

if( ticket != null )
{
CmsFormsAuthentication.RedirectFromLoginPage(ticke t, true, CheckPersistent.Checked);
}
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

my problem is that the first bind works (if I query an attribute of the de object in the immediate window - i get the value no problems).

However, the second one - the line which retreives the attribute - fails - with the message "there is no such object on the server".
If i do the bind as previously (Secure auth type and same admin creds) it works



I pretty much copied the code from an ADAM webcast

Can anybody shed light on this?


--
thx
Spence
www.harbar.net/mcms/

Posted by Spencer Harbar on March 5th, 2004


The types are different - err well, cos they were in the code I stole!
The idea is that i'm trying to auth the ADAM user and then if that works go do some other stuff... hence why theres a DN for the second bind rather than NTLM style creds.

I had tried changing the auth type to 'secure' but that also failed.
Nothing in the event log - but I will try uping the logging.

thx
s.


"Al Mulnick" <amulnick_No_SPAM@ncDOTrr.com> wrote in message news:eihU$qlAEHA.3004@TK2MSFTNGP10.phx.gbl...
Afraid I can't fix it off the cuff, but maybe I can help narrow it down a little.
Why are your authentication types different?
Is anything logged in the ADAM Instance event log? Have you turned up the logging just in case?
Why are your creds in NTLM format in the part that works and in LDAP format in the other?

Al
"Spencer Harbar [MVP]" <spence@harbar.net> wrote in message news:OYeOnZlAEHA.3048@tk2msftngp13.phx.gbl...
Hi!

I am hoping someone out there can help me...
I have the following code:

//user supplied credentials
string NTUser = TxtNTUser.Value;
string NTPassword = TxtNTPassword.Value;

//first bind is as ADAM admin
string ldpQuery = "LDAP://localhost:389/CN=mcmsadam,O=Harbar,C=NET";

string ldpAdminUID = "DESTINY\\harbars";
string ldpAdminPwd = "notstupidenuff2giveoutpassword";

DirectoryEntry de = new DirectoryEntry (ldpQuery, ldpAdminUID, ldpAdminPwd, AuthenticationTypes.Secure);

//now we're 'binded' try the user supplied credentials...

try
{
string sLDAPobj = "CN=mcmsadam,O=harbar,c=NET";
string sBindName = "CN=" + TxtNTUser.Value + ",O=harbar,c=NET";

DirectoryEntry ent = new DirectoryEntry("LDAP://localhost:389/" + sLDAPobj, sBindName, NTPassword, AuthenticationTypes.None);

//not until you attempt attribute retrieval will a bind occur
string sUser = (string)ent.Properties["name"].Value;

//do redirect
CmsAuthenticationTicket ticket = CmsFormsAuthentication.AuthenticateAsUser(NTUser, NTPassword);

if( ticket != null )
{
CmsFormsAuthentication.RedirectFromLoginPage(ticke t, true, CheckPersistent.Checked);
}
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

my problem is that the first bind works (if I query an attribute of the de object in the immediate window - i get the value no problems).

However, the second one - the line which retreives the attribute - fails - with the message "there is no such object on the server".
If i do the bind as previously (Secure auth type and same admin creds) it works



I pretty much copied the code from an ADAM webcast

Can anybody shed light on this?


--
thx
Spence
www.harbar.net/mcms/

Posted by Spencer Harbar on March 5th, 2004


aha!

adding the mcmsadam user to the Readers Role solved it!

duh!

thanks very much!

s.
"Arild Bakken" <arildb_@hotmail.com> wrote in message news:u4DkYKpAEHA.3348@TK2MSFTNGP11.phx.gbl...
Also, is the ADAM user member of any groups so that it has enough permissions to see and read the object in question?

Arild
"Al Mulnick" <amulnick_No_SPAM@ncDOTrr.com> wrote in message news:eihU$qlAEHA.3004@TK2MSFTNGP10.phx.gbl...
Afraid I can't fix it off the cuff, but maybe I can help narrow it down a little.
Why are your authentication types different?
Is anything logged in the ADAM Instance event log? Have you turned up the logging just in case?
Why are your creds in NTLM format in the part that works and in LDAP format in the other?

Al
"Spencer Harbar [MVP]" <spence@harbar.net> wrote in message news:OYeOnZlAEHA.3048@tk2msftngp13.phx.gbl...
Hi!

I am hoping someone out there can help me...
I have the following code:

//user supplied credentials
string NTUser = TxtNTUser.Value;
string NTPassword = TxtNTPassword.Value;

//first bind is as ADAM admin
string ldpQuery = "LDAP://localhost:389/CN=mcmsadam,O=Harbar,C=NET";

string ldpAdminUID = "DESTINY\\harbars";
string ldpAdminPwd = "notstupidenuff2giveoutpassword";

DirectoryEntry de = new DirectoryEntry (ldpQuery, ldpAdminUID, ldpAdminPwd, AuthenticationTypes.Secure);

//now we're 'binded' try the user supplied credentials...

try
{
string sLDAPobj = "CN=mcmsadam,O=harbar,c=NET";
string sBindName = "CN=" + TxtNTUser.Value + ",O=harbar,c=NET";

DirectoryEntry ent = new DirectoryEntry("LDAP://localhost:389/" + sLDAPobj, sBindName, NTPassword, AuthenticationTypes.None);

//not until you attempt attribute retrieval will a bind occur
string sUser = (string)ent.Properties["name"].Value;

//do redirect
CmsAuthenticationTicket ticket = CmsFormsAuthentication.AuthenticateAsUser(NTUser, NTPassword);

if( ticket != null )
{
CmsFormsAuthentication.RedirectFromLoginPage(ticke t, true, CheckPersistent.Checked);
}
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}

my problem is that the first bind works (if I query an attribute of the de object in the immediate window - i get the value no problems).

However, the second one - the line which retreives the attribute - fails - with the message "there is no such object on the server".
If i do the bind as previously (Secure auth type and same admin creds) it works



I pretty much copied the code from an ADAM webcast

Can anybody shed light on this?


--
thx
Spence
www.harbar.net/mcms/


Similar Posts