none
How to authenticate LDAP user with GSS Negotiate binding authentication using C#? RRS feed

  • Question

  • 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?

    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;
            }
        }


    mayooran99

    Saturday, June 3, 2017 1:49 PM

All replies