mscorlib(4.0.0.0) API with additions
AuthenticationManager.cs
1 using System.Collections;
3 using System.Threading;
4 
5 namespace System.Net
6 {
8  public class AuthenticationManager
9  {
10  private static object instanceLock = new object();
11 
12  private static IAuthenticationManager internalInstance = null;
13 
14  internal const string authenticationManagerRoot = "System.Net.AuthenticationManager";
15 
16  internal const string configHighPerformance = "System.Net.AuthenticationManager.HighPerformance";
17 
18  internal const string configPrefixLookupMaxCount = "System.Net.AuthenticationManager.PrefixLookupMaxCount";
19 
20  private static IAuthenticationManager Instance
21  {
22  get
23  {
24  if (internalInstance == null)
25  {
26  lock (instanceLock)
27  {
28  if (internalInstance == null)
29  {
30  internalInstance = SelectAuthenticationManagerInstance();
31  }
32  }
33  }
34  return internalInstance;
35  }
36  }
37 
41  {
42  get
43  {
44  return Instance.CredentialPolicy;
45  }
46  set
47  {
48  ExceptionHelper.ControlPolicyPermission.Demand();
49  Instance.CredentialPolicy = value;
50  }
51  }
52 
55  public static StringDictionary CustomTargetNameDictionary => Instance.CustomTargetNameDictionary;
56 
57  internal static SpnDictionary SpnDictionary => Instance.SpnDictionary;
58 
59  internal static bool OSSupportsExtendedProtection => Instance.OSSupportsExtendedProtection;
60 
61  internal static bool SspSupportsExtendedProtection => Instance.SspSupportsExtendedProtection;
62 
65  public static IEnumerator RegisteredModules => Instance.RegisteredModules;
66 
67  private AuthenticationManager()
68  {
69  }
70 
71  private static IAuthenticationManager SelectAuthenticationManagerInstance()
72  {
73  bool flag = false;
74  try
75  {
76  if (RegistryConfiguration.GlobalConfigReadInt("System.Net.AuthenticationManager.HighPerformance", 0) == 1)
77  {
78  flag = true;
79  }
80  else if (RegistryConfiguration.AppConfigReadInt("System.Net.AuthenticationManager.HighPerformance", 0) == 1)
81  {
82  flag = true;
83  }
84  if (flag)
85  {
86  int? num = ReadPrefixLookupMaxEntriesConfig();
87  if (num.HasValue && num > 0)
88  {
89  return new AuthenticationManager2(num.Value);
90  }
91  return new AuthenticationManager2();
92  }
93  }
94  catch (Exception ex)
95  {
96  if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
97  {
98  throw;
99  }
100  }
101  return new AuthenticationManagerDefault();
102  }
103 
104  private static int? ReadPrefixLookupMaxEntriesConfig()
105  {
106  int? result = null;
107  int num = RegistryConfiguration.GlobalConfigReadInt("System.Net.AuthenticationManager.PrefixLookupMaxCount", -1);
108  if (num > 0)
109  {
110  result = num;
111  }
112  num = RegistryConfiguration.AppConfigReadInt("System.Net.AuthenticationManager.PrefixLookupMaxCount", -1);
113  if (num > 0)
114  {
115  result = num;
116  }
117  return result;
118  }
119 
120  internal static void EnsureConfigLoaded()
121  {
122  Instance.EnsureConfigLoaded();
123  }
124 
134  public static Authorization Authenticate(string challenge, WebRequest request, ICredentials credentials)
135  {
136  return Instance.Authenticate(challenge, request, credentials);
137  }
138 
145  public static Authorization PreAuthenticate(WebRequest request, ICredentials credentials)
146  {
147  return Instance.PreAuthenticate(request, credentials);
148  }
149 
154  public static void Register(IAuthenticationModule authenticationModule)
155  {
156  ExceptionHelper.UnmanagedPermission.Demand();
157  Instance.Register(authenticationModule);
158  }
159 
165  public static void Unregister(IAuthenticationModule authenticationModule)
166  {
167  ExceptionHelper.UnmanagedPermission.Demand();
168  Instance.Unregister(authenticationModule);
169  }
170 
176  public static void Unregister(string authenticationScheme)
177  {
178  ExceptionHelper.UnmanagedPermission.Demand();
179  Instance.Unregister(authenticationScheme);
180  }
181 
182  internal static void BindModule(Uri uri, Authorization response, IAuthenticationModule module)
183  {
184  Instance.BindModule(uri, response, module);
185  }
186 
187  internal static int FindSubstringNotInQuotes(string challenge, string signature)
188  {
189  int num = -1;
190  if (challenge != null && signature != null && challenge.Length >= signature.Length)
191  {
192  int num2 = -1;
193  int num3 = -1;
194  for (int i = 0; i < challenge.Length; i++)
195  {
196  if (num >= 0)
197  {
198  break;
199  }
200  if (challenge[i] == '"')
201  {
202  if (num2 <= num3)
203  {
204  num2 = i;
205  }
206  else
207  {
208  num3 = i;
209  }
210  }
211  if (i != challenge.Length - 1 && (challenge[i] != '"' || num2 <= num3))
212  {
213  continue;
214  }
215  if (i == challenge.Length - 1)
216  {
217  num2 = challenge.Length;
218  }
219  if (num2 < num3 + 3)
220  {
221  continue;
222  }
223  int num4 = num3 + 1;
224  int num5 = num2 - num3 - 1;
225  do
226  {
227  num = IndexOf(challenge, signature, num4, num5);
228  if (num >= 0)
229  {
230  if ((num == 0 || challenge[num - 1] == ' ' || challenge[num - 1] == ',') && (num + signature.Length == challenge.Length || challenge[num + signature.Length] == ' ' || challenge[num + signature.Length] == ','))
231  {
232  break;
233  }
234  num5 -= num - num4 + 1;
235  num4 = num + 1;
236  }
237  }
238  while (num >= 0);
239  }
240  }
241  return num;
242  }
243 
244  private static int IndexOf(string challenge, string lwrCaseSignature, int start, int count)
245  {
246  count += start + 1 - lwrCaseSignature.Length;
247  while (start < count)
248  {
249  int i;
250  for (i = 0; i < lwrCaseSignature.Length && (challenge[start + i] | 0x20) == lwrCaseSignature[i]; i++)
251  {
252  }
253  if (i == lwrCaseSignature.Length)
254  {
255  return start;
256  }
257  start++;
258  }
259  return -1;
260  }
261 
262  internal static int SplitNoQuotes(string challenge, ref int offset)
263  {
264  int num = offset;
265  offset = -1;
266  if (challenge != null && num < challenge.Length)
267  {
268  int num2 = -1;
269  int num3 = -1;
270  for (int i = num; i < challenge.Length; i++)
271  {
272  if (num2 > num3 && challenge[i] == '\\' && i + 1 < challenge.Length && challenge[i + 1] == '"')
273  {
274  i++;
275  }
276  else if (challenge[i] == '"')
277  {
278  if (num2 <= num3)
279  {
280  num2 = i;
281  }
282  else
283  {
284  num3 = i;
285  }
286  }
287  else if (challenge[i] == '=' && num2 <= num3 && offset < 0)
288  {
289  offset = i;
290  }
291  else if (challenge[i] == ',' && num2 <= num3)
292  {
293  return i;
294  }
295  }
296  }
297  return -1;
298  }
299 
300  internal static Authorization GetGroupAuthorization(IAuthenticationModule thisModule, string token, bool finished, NTAuthentication authSession, bool shareAuthenticatedConnections, bool mutualAuth)
301  {
302  return new Authorization(token, finished, shareAuthenticatedConnections ? null : (thisModule.GetType().FullName + "/" + authSession.UniqueUserId), mutualAuth);
303  }
304  }
305 }
static IEnumerator RegisteredModules
Gets a list of authentication modules that are registered with the authentication manager.
static StringDictionary CustomTargetNameDictionary
Gets the dictionary that contains Service Principal Names (SPNs) that are used to identify hosts duri...
Contains an authentication message for an Internet server.
Definition: Authorization.cs:4
static void Unregister(string authenticationScheme)
Removes authentication modules with the specified authentication scheme from the list of registered m...
Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
Definition: WebRequest.cs:21
Implements a hash table with the key and the value strongly typed to be strings rather than objects.
Definition: __Canon.cs:3
The Authorization header, which specifies the credentials that the client presents in order to authen...
static ICredentialPolicy CredentialPolicy
Gets or sets the credential policy to be used for resource requests made using the T:System....
static Authorization PreAuthenticate(WebRequest request, ICredentials credentials)
Preauthenticates a request.
Provides the base authentication interface for retrieving credentials for Web client authentication.
Definition: ICredentials.cs:5
Manages the authentication modules called during the client authentication process.
Provides the base authentication interface for Web client authentication modules.
static Authorization Authenticate(string challenge, WebRequest request, ICredentials credentials)
Calls each registered authentication module to find the first module that can respond to the authenti...
static void Unregister(IAuthenticationModule authenticationModule)
Removes the specified authentication module from the list of registered modules.
Defines the credential policy to be used for resource requests that are made using T:System....
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition: Uri.cs:19
The exception that is thrown when a call is made to the M:System.Threading.Thread....
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
static void Register(IAuthenticationModule authenticationModule)
Registers an authentication module with the authentication manager.