AuthenticationSchemesHelper.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / AuthenticationSchemesHelper.cs / 1 / AuthenticationSchemesHelper.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Channels
{ 
    using System.ComponentModel;
    using System.Globalization; 
    using System.Net; 

    static class AuthenticationSchemesHelper 
    {
        public static bool DoesAuthTypeMatch(AuthenticationSchemes authScheme, string authType)
        {
            bool result = false; 
            if ((authType == null) || (authType.Length == 0))
            { 
                result = (authScheme == AuthenticationSchemes.Anonymous); 
            }
            else 
            {
                if (authScheme == AuthenticationSchemes.Negotiate)
                {
                    result = (authType.Equals("ntlm", StringComparison.OrdinalIgnoreCase) || 
                        authType.Equals("kerberos", StringComparison.OrdinalIgnoreCase) ||
                        authType.Equals("negotiate", StringComparison.OrdinalIgnoreCase)); 
                } 
                else
                { 
                    result = authScheme.ToString().Equals(authType, StringComparison.OrdinalIgnoreCase);
                }
            }
            return result; 
        }
 
        public static bool IsSingleton(AuthenticationSchemes v) 
        {
            bool result; 
            switch (v)
            {
                case AuthenticationSchemes.Digest:
                case AuthenticationSchemes.Negotiate: 
                case AuthenticationSchemes.Ntlm:
                case AuthenticationSchemes.Basic: 
                case AuthenticationSchemes.Anonymous: 
                    result = true;
                    break; 
                default:
                    result = false;
                    break;
            } 
            return result;
        } 
 
        public static bool IsWindowsAuth(AuthenticationSchemes authScheme)
        { 
            return ((authScheme == AuthenticationSchemes.Negotiate) || (authScheme == AuthenticationSchemes.Ntlm));
        }

        internal static string ToString(AuthenticationSchemes authScheme) 
        {
            string result; 
 
            switch (authScheme)
            { 
                case AuthenticationSchemes.Anonymous:
                    result = "anonymous";
                    break;
                case AuthenticationSchemes.Basic: 
                    result = "basic";
                    break; 
                case AuthenticationSchemes.Digest: 
                    result = "digest";
                    break; 
                case AuthenticationSchemes.Negotiate:
                    result = "negotiate";
                    break;
                case AuthenticationSchemes.Ntlm: 
                    result = "ntlm";
                    break; 
                default: 
                    DiagnosticUtility.DebugAssert("unknown authentication scheme");
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException( 
                        "authScheme", (int)authScheme, typeof(AuthenticationSchemes)));
            }

#if DEBUG 
            DiagnosticUtility.DebugAssert(result.Equals(authScheme.ToString().ToLowerInvariant()),
                "incorrect auth scheme conversion"); 
#endif 
            return result;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK