287 lines
13 KiB
C#
287 lines
13 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Specialized;
|
|
|
|
namespace System.Net
|
|
{
|
|
/// <summary>Manages the authentication modules called during the client authentication process.</summary>
|
|
// Token: 0x020001FB RID: 507
|
|
public class AuthenticationManager
|
|
{
|
|
// Token: 0x0600112F RID: 4399 RVA: 0x000321E8 File Offset: 0x000303E8
|
|
private AuthenticationManager()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06001131 RID: 4401 RVA: 0x00032204 File Offset: 0x00030404
|
|
private static void EnsureModules()
|
|
{
|
|
object obj = AuthenticationManager.locker;
|
|
lock (obj)
|
|
{
|
|
if (AuthenticationManager.modules == null)
|
|
{
|
|
AuthenticationManager.modules = new ArrayList();
|
|
AuthenticationManager.modules.Add(new BasicClient());
|
|
AuthenticationManager.modules.Add(new DigestClient());
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets or sets the credential policy to be used for resource requests made using the <see cref="T:System.Net.HttpWebRequest" /> class.</summary>
|
|
/// <returns>An object that implements the <see cref="T:System.Net.ICredentialPolicy" /> interface that determines whether credentials are sent with requests. The default value is null.</returns>
|
|
// Token: 0x170005AA RID: 1450
|
|
// (get) Token: 0x06001132 RID: 4402 RVA: 0x00032280 File Offset: 0x00030480
|
|
// (set) Token: 0x06001133 RID: 4403 RVA: 0x00032288 File Offset: 0x00030488
|
|
public static ICredentialPolicy CredentialPolicy
|
|
{
|
|
get
|
|
{
|
|
return AuthenticationManager.credential_policy;
|
|
}
|
|
set
|
|
{
|
|
AuthenticationManager.credential_policy = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001134 RID: 4404 RVA: 0x00032290 File Offset: 0x00030490
|
|
private static Exception GetMustImplement()
|
|
{
|
|
return new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>Gets the dictionary that contains Service Principal Names (SPNs) that are used to identify hosts during Kerberos authentication for requests made using <see cref="T:System.Net.WebRequest" /> and its derived classes.</summary>
|
|
/// <returns>A writable <see cref="T:System.Collections.Specialized.StringDictionary" /> that contains the SPN values for keys composed of host information. </returns>
|
|
// Token: 0x170005AB RID: 1451
|
|
// (get) Token: 0x06001135 RID: 4405 RVA: 0x00032298 File Offset: 0x00030498
|
|
[global::System.MonoTODO]
|
|
public static global::System.Collections.Specialized.StringDictionary CustomTargetNameDictionary
|
|
{
|
|
get
|
|
{
|
|
throw AuthenticationManager.GetMustImplement();
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets a list of authentication modules that are registered with the authentication manager.</summary>
|
|
/// <returns>An <see cref="T:System.Collections.IEnumerator" /> that enables the registered authentication modules to be read.</returns>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x170005AC RID: 1452
|
|
// (get) Token: 0x06001136 RID: 4406 RVA: 0x000322A0 File Offset: 0x000304A0
|
|
public static IEnumerator RegisteredModules
|
|
{
|
|
get
|
|
{
|
|
AuthenticationManager.EnsureModules();
|
|
return AuthenticationManager.modules.GetEnumerator();
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001137 RID: 4407 RVA: 0x000322B4 File Offset: 0x000304B4
|
|
internal static void Clear()
|
|
{
|
|
AuthenticationManager.EnsureModules();
|
|
ArrayList arrayList = AuthenticationManager.modules;
|
|
lock (arrayList)
|
|
{
|
|
AuthenticationManager.modules.Clear();
|
|
}
|
|
}
|
|
|
|
/// <summary>Calls each registered authentication module to find the first module that can respond to the authentication request.</summary>
|
|
/// <returns>An instance of the <see cref="T:System.Net.Authorization" /> class containing the result of the authorization attempt. If there is no authentication module to respond to the challenge, this method returns null.</returns>
|
|
/// <param name="challenge">The challenge returned by the Internet resource. </param>
|
|
/// <param name="request">The <see cref="T:System.Net.WebRequest" /> that initiated the authentication challenge. </param>
|
|
/// <param name="credentials">The <see cref="T:System.Net.ICredentials" /> associated with this request. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="challenge" /> is null.-or- <paramref name="request" /> is null.-or- <paramref name="credentials" /> is null. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x06001138 RID: 4408 RVA: 0x00032304 File Offset: 0x00030504
|
|
public static Authorization Authenticate(string challenge, WebRequest request, ICredentials credentials)
|
|
{
|
|
if (request == null)
|
|
{
|
|
throw new ArgumentNullException("request");
|
|
}
|
|
if (credentials == null)
|
|
{
|
|
throw new ArgumentNullException("credentials");
|
|
}
|
|
if (challenge == null)
|
|
{
|
|
throw new ArgumentNullException("challenge");
|
|
}
|
|
return AuthenticationManager.DoAuthenticate(challenge, request, credentials);
|
|
}
|
|
|
|
// Token: 0x06001139 RID: 4409 RVA: 0x00032344 File Offset: 0x00030544
|
|
private static Authorization DoAuthenticate(string challenge, WebRequest request, ICredentials credentials)
|
|
{
|
|
AuthenticationManager.EnsureModules();
|
|
ArrayList arrayList = AuthenticationManager.modules;
|
|
lock (arrayList)
|
|
{
|
|
foreach (object obj in AuthenticationManager.modules)
|
|
{
|
|
IAuthenticationModule authenticationModule = (IAuthenticationModule)obj;
|
|
Authorization authorization = authenticationModule.Authenticate(challenge, request, credentials);
|
|
if (authorization != null)
|
|
{
|
|
authorization.Module = authenticationModule;
|
|
return authorization;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>Preauthenticates a request.</summary>
|
|
/// <returns>An instance of the <see cref="T:System.Net.Authorization" /> class if the request can be preauthenticated; otherwise, null. If <paramref name="credentials" /> is null, this method returns null.</returns>
|
|
/// <param name="request">A <see cref="T:System.Net.WebRequest" /> to an Internet resource. </param>
|
|
/// <param name="credentials">The <see cref="T:System.Net.ICredentials" /> associated with the request. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="request" /> is null. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600113A RID: 4410 RVA: 0x0003240C File Offset: 0x0003060C
|
|
public static Authorization PreAuthenticate(WebRequest request, ICredentials credentials)
|
|
{
|
|
if (request == null)
|
|
{
|
|
throw new ArgumentNullException("request");
|
|
}
|
|
if (credentials == null)
|
|
{
|
|
return null;
|
|
}
|
|
AuthenticationManager.EnsureModules();
|
|
ArrayList arrayList = AuthenticationManager.modules;
|
|
lock (arrayList)
|
|
{
|
|
foreach (object obj in AuthenticationManager.modules)
|
|
{
|
|
IAuthenticationModule authenticationModule = (IAuthenticationModule)obj;
|
|
Authorization authorization = authenticationModule.PreAuthenticate(request, credentials);
|
|
if (authorization != null)
|
|
{
|
|
authorization.Module = authenticationModule;
|
|
return authorization;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>Registers an authentication module with the authentication manager.</summary>
|
|
/// <param name="authenticationModule">The <see cref="T:System.Net.IAuthenticationModule" /> to register with the authentication manager. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="authenticationModule" /> is null. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600113B RID: 4411 RVA: 0x000324EC File Offset: 0x000306EC
|
|
public static void Register(IAuthenticationModule authenticationModule)
|
|
{
|
|
if (authenticationModule == null)
|
|
{
|
|
throw new ArgumentNullException("authenticationModule");
|
|
}
|
|
AuthenticationManager.DoUnregister(authenticationModule.AuthenticationType, false);
|
|
ArrayList arrayList = AuthenticationManager.modules;
|
|
lock (arrayList)
|
|
{
|
|
AuthenticationManager.modules.Add(authenticationModule);
|
|
}
|
|
}
|
|
|
|
/// <summary>Removes the specified authentication module from the list of registered modules.</summary>
|
|
/// <param name="authenticationModule">The <see cref="T:System.Net.IAuthenticationModule" /> to remove from the list of registered modules. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="authenticationModule" /> is null. </exception>
|
|
/// <exception cref="T:System.InvalidOperationException">The specified <see cref="T:System.Net.IAuthenticationModule" /> is not registered. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600113C RID: 4412 RVA: 0x00032558 File Offset: 0x00030758
|
|
public static void Unregister(IAuthenticationModule authenticationModule)
|
|
{
|
|
if (authenticationModule == null)
|
|
{
|
|
throw new ArgumentNullException("authenticationModule");
|
|
}
|
|
AuthenticationManager.DoUnregister(authenticationModule.AuthenticationType, true);
|
|
}
|
|
|
|
/// <summary>Removes authentication modules with the specified authentication scheme from the list of registered modules.</summary>
|
|
/// <param name="authenticationScheme">The authentication scheme of the module to remove. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="authenticationScheme" /> is null. </exception>
|
|
/// <exception cref="T:System.InvalidOperationException">A module for this authentication scheme is not registered. </exception>
|
|
/// <PermissionSet>
|
|
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
|
|
/// </PermissionSet>
|
|
// Token: 0x0600113D RID: 4413 RVA: 0x00032578 File Offset: 0x00030778
|
|
public static void Unregister(string authenticationScheme)
|
|
{
|
|
if (authenticationScheme == null)
|
|
{
|
|
throw new ArgumentNullException("authenticationScheme");
|
|
}
|
|
AuthenticationManager.DoUnregister(authenticationScheme, true);
|
|
}
|
|
|
|
// Token: 0x0600113E RID: 4414 RVA: 0x00032594 File Offset: 0x00030794
|
|
private static void DoUnregister(string authenticationScheme, bool throwEx)
|
|
{
|
|
AuthenticationManager.EnsureModules();
|
|
ArrayList arrayList = AuthenticationManager.modules;
|
|
lock (arrayList)
|
|
{
|
|
IAuthenticationModule authenticationModule = null;
|
|
foreach (object obj in AuthenticationManager.modules)
|
|
{
|
|
IAuthenticationModule authenticationModule2 = (IAuthenticationModule)obj;
|
|
string authenticationType = authenticationModule2.AuthenticationType;
|
|
if (string.Compare(authenticationType, authenticationScheme, true) == 0)
|
|
{
|
|
authenticationModule = authenticationModule2;
|
|
break;
|
|
}
|
|
}
|
|
if (authenticationModule == null)
|
|
{
|
|
if (throwEx)
|
|
{
|
|
throw new InvalidOperationException("Scheme not registered.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AuthenticationManager.modules.Remove(authenticationModule);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x04000F4A RID: 3914
|
|
private static ArrayList modules;
|
|
|
|
// Token: 0x04000F4B RID: 3915
|
|
private static object locker = new object();
|
|
|
|
// Token: 0x04000F4C RID: 3916
|
|
private static ICredentialPolicy credential_policy = null;
|
|
}
|
|
}
|