Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

75 lines
2.6 KiB
C#

//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.ComponentModel;
using System.Net;
using System.Runtime;
using System.Text;
static class AuthenticationSchemesHelper
{
public static bool DoesAuthTypeMatch(AuthenticationSchemes authScheme, string authType)
{
if ((authType == null) || (authType.Length == 0))
{
return authScheme.IsSet(AuthenticationSchemes.Anonymous);
}
if (authType.Equals("kerberos", StringComparison.OrdinalIgnoreCase) ||
authType.Equals("negotiate", StringComparison.OrdinalIgnoreCase))
{
return authScheme.IsSet(AuthenticationSchemes.Negotiate);
}
else if (authType.Equals("ntlm", StringComparison.OrdinalIgnoreCase))
{
return authScheme.IsSet(AuthenticationSchemes.Negotiate) ||
authScheme.IsSet(AuthenticationSchemes.Ntlm);
}
AuthenticationSchemes authTypeScheme;
if (!Enum.TryParse<AuthenticationSchemes>(authType, true, out authTypeScheme))
{
return false;
}
return authScheme.IsSet(authTypeScheme);
}
public static bool IsSingleton(this 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 IsSet(this AuthenticationSchemes thisPtr, AuthenticationSchemes authenticationSchemes)
{
return (thisPtr & authenticationSchemes) == authenticationSchemes;
}
public static bool IsNotSet(this AuthenticationSchemes thisPtr, AuthenticationSchemes authenticationSchemes)
{
return (thisPtr & authenticationSchemes) == 0;
}
internal static string ToString(AuthenticationSchemes authScheme)
{
return authScheme.ToString().ToLowerInvariant();
}
}
}