LDAP Authentication Problem

Last post 06-03-2009 10:24 AM by jeff@zina.com. 2 replies.

Sort Posts:

  • LDAP Authentication Problem

    06-02-2009, 4:56 AM
    • Member
      1 point Member
    • rpc24
    • Member since 01-02-2009, 12:06 PM
    • Posts 9

    I developed an application in sharepoint and configured it with LDAP. But  i am unable to login tot he site using AD credentials. 

      <membership>
          <providers>
            <add name="LDAPFBAMembership" type="Microsoft.Office.Server.Security.LdapMembershipProvider, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" server="wipro.com" port="389" useSSL="false" userDNAttribute="distinguishedName" userNameAttribute="sAMAccountName" userContainer="DC=Domain,DC=com" userObjectClass="person" userFilter="(|(ObjectCategory=group)(ObjectClass=person))" scope="Subtree" otherRequiredUserAttributes="sn,givenname,cn" />
          </providers>
        </membership>

     

        <roleManager defaultProvider="AspNetWindowsTokenRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".PeopleDCRole">
          <providers>
            <add name="LDAPFBARole" type="Microsoft.Office.Server.Security.LdapRoleProvider, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" server="wipro.com" port="389" useSSL="false" groupContainer="DC=Domain, DC=com" groupNameAttribute="cn" groupMemberAttribute="member" userNameAttribute="sAMAccountName" dnAttribute="distinguishedName" groupFilter="(ObjectClass=group)" scope="Subtree" />
          </providers>
        </roleManager>

     

    and then added above tags in web.config file of both sites(actual site and extended one) and also in Central admin's web.config file. Then in Authentication Provider (Central Adminstration-->Application Management ) changed  the authentication type to form and added the provider as well as Role name. But still i'm unable to login using the proper credentials.

     

    Can anyone please tell me, where i am going wrong or i'm missing any step.

     

    Thanks in advance

    Reshma

    Filed under:
  • Re: LDAP Authentication Problem

    06-02-2009, 10:35 AM
    • Participant
      856 point Participant
    • jacobodolil
    • Member since 03-19-2009, 3:23 PM
    • Cochin
    • Posts 225

    Hi

    The C# LDAP Class uses the System.DirectoryServices namespace to perform Active Directory search. See the code below:


    public bool IsAuthenticated(String domain, String username, String pwd)
    {
    //Create the directory entry
    String domainAndUsername = domain + @"\" + username;
    DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
    bool returnval = true;
    ErrDesc = "";

    try
    {
    //Bind to the native AdsObject to force authentication.
    Object obj = entry.NativeObject;

    //Search the user on the Active Directory
    DirectorySearcher search = new DirectorySearcher(entry);

    search.Filter = "(SAMAccountName=" + username + ")";
    search.PropertiesToLoad.Add("cn");
    SearchResult result = search.FindOne();

    if (null == result)
    {
    returnval = false;
    }

    //Update the new path to the user in the directory.
    _path = result.Path;
    _filterAttribute = (String)result.Properties["cn"][0];
    }
    catch (Exception ex)
    {
    returnval = false;
    ErrDesc = "Error authenticating user. " + ex.Message;
    }

    return returnval;
    }



     

     

    IsAuthenticated function searches for a domain user inside a specific Domain. You just have to compile this class to build the DLL and call it from VB.NET or ASP.NET as shown below:


    Imports SingleSignOnExt 'Import SingleSignOnExt.dll


    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim son As New SingleSignOn()

    son.LDAP_Path = "LDAP://yourdomain"

    If son.IsAuthenticated("yourdomain", TextBox1.Text, TextBox2.Text) Then 'Parameters: Domain, Username, Password
    Label1.Text = "User is authenticated!"
    Else
    Label1.Text = "User is invalid! -- " & son.ErrDesc
    End If


    End Sub

    End Class
    Thanks & Regards
    Jacob


    Mark As Answer if this post Helped you
  • Re: LDAP Authentication Problem

    06-03-2009, 10:24 AM
    • All-Star
      77,629 point All-Star
    • jeff@zina.com
    • Member since 09-26-2003, 6:43 AM
    • Naples, FL, USA
    • Posts 10,560
    • Moderator
      TrustedFriends-MVPs

    rpc24:
    Can anyone please tell me, where i am going wrong...

    Sure,  Read this:

    http://forums.asp.net/t/1047141.aspx

    Jeff

    Blatant Self Promotion: ASP.NET 3.5 CMS Development
Page 1 of 1 (3 items)