Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am new to LDAP. I have written the below code that authenticates users with LDAP. I currently have to validate users with a server that has a biding authentication type of GSS-Negotiate. I couldn't find any examples to validate the user with such a binding authentication type. The below code I tried doesn't work on this binding authentication. What am I missing in the below code segment. Any help would be much appreciated. Also is there an internet LDAP server in which I can validate a user with GSS-Negotiate binding to test it out?

What I have tried:

<pre lang="c#">

<pre>public static string AuthFunction_One(string identity, string password, string containerString, string adServerName, bool useLDAPS, IdentityType identityType)
    {

        string failedString = "FAILED";
        string successString = "SUCCESS";
        string returnValue = failedString;

        try
        {
            PrincipalContext ctx = null;
            if (useLDAPS)
            {
                ctx = new PrincipalContext(ContextType.Domain, adServerName, containerString, ContextOptions.Negotiate | ContextOptions.SecureSocketLayer);
            }
            else
            {
                ctx = new PrincipalContext(ContextType.Domain, adServerName, containerString);
            }
            UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(ctx, identityType, identity);
            PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();
            try
            {
                foreach (Principal result in oPrincipalSearchResult)
                {

                }

            }
            catch (Exception ex)
            {
                NLogHelper.GetInstance().Log("ADUtilityClass", "AuthFunction_One", NLog.LogLevel.Debug, "Failed to probe groups. Ex: " + ex.ToString());
            }

            if (ctx.ValidateCredentials(identity, password))
            {
                return successString;
            }
            else
            {
                return failedString;
            }
        }
        catch (Exception ex)
        { 
            NLogHelper.GetInstance().Log("ADUtilityClass", "AuthFunction_One", NLog.LogLevel.Debug, "Error in function. Ex: " + ex.ToString());
            return failedString;
        }
    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900