| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Net; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.Channels |
| | | 7 | | { |
| | | 8 | | internal static class AuthenticationSchemesHelper |
| | | 9 | | { |
| | | 10 | | //public static bool DoesAuthTypeMatch(AuthenticationSchemes authScheme, string authType) |
| | | 11 | | //{ |
| | | 12 | | // if ((authType == null) || (authType.Length == 0)) |
| | | 13 | | // { |
| | | 14 | | // return authScheme.IsSet(AuthenticationSchemes.Anonymous); |
| | | 15 | | // } |
| | | 16 | | |
| | | 17 | | // if (authType.Equals("kerberos", StringComparison.OrdinalIgnoreCase) || |
| | | 18 | | // authType.Equals("negotiate", StringComparison.OrdinalIgnoreCase)) |
| | | 19 | | // { |
| | | 20 | | // return authScheme.IsSet(AuthenticationSchemes.Negotiate); |
| | | 21 | | // } |
| | | 22 | | // else if (authType.Equals("ntlm", StringComparison.OrdinalIgnoreCase)) |
| | | 23 | | // { |
| | | 24 | | // return authScheme.IsSet(AuthenticationSchemes.Negotiate) || |
| | | 25 | | // authScheme.IsSet(AuthenticationSchemes.Ntlm); |
| | | 26 | | // } |
| | | 27 | | |
| | | 28 | | // AuthenticationSchemes authTypeScheme; |
| | | 29 | | // if (!Enum.TryParse<AuthenticationSchemes>(authType, true, out authTypeScheme)) |
| | | 30 | | // { |
| | | 31 | | // return false; |
| | | 32 | | // } |
| | | 33 | | |
| | | 34 | | // return authScheme.IsSet(authTypeScheme); |
| | | 35 | | //} |
| | | 36 | | |
| | | 37 | | public static bool IsSingleton(this AuthenticationSchemes v) |
| | | 38 | | { |
| | | 39 | | bool result; |
| | | 40 | | switch (v) |
| | | 41 | | { |
| | | 42 | | case AuthenticationSchemes.Digest: |
| | | 43 | | case AuthenticationSchemes.Negotiate: |
| | | 44 | | case AuthenticationSchemes.Ntlm: |
| | | 45 | | case AuthenticationSchemes.Basic: |
| | | 46 | | case AuthenticationSchemes.Anonymous: |
| | 0 | 47 | | result = true; |
| | 0 | 48 | | break; |
| | | 49 | | default: |
| | 0 | 50 | | result = false; |
| | | 51 | | break; |
| | | 52 | | } |
| | 0 | 53 | | return result; |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | public static bool IsSet(this AuthenticationSchemes thisPtr, AuthenticationSchemes authenticationSchemes) |
| | | 57 | | { |
| | 0 | 58 | | return (thisPtr & authenticationSchemes) == authenticationSchemes; |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public static bool IsNotSet(this AuthenticationSchemes thisPtr, AuthenticationSchemes authenticationSchemes) |
| | | 62 | | { |
| | 0 | 63 | | return (thisPtr & authenticationSchemes) == 0; |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | //internal static string ToString(AuthenticationSchemes authScheme) |
| | | 67 | | //{ |
| | | 68 | | // return authScheme.ToString().ToLowerInvariant(); |
| | | 69 | | //} |
| | | 70 | | } |
| | | 71 | | } |