/// <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>
        public static Authorization PreAuthenticate(WebRequest request, ICredentials credentials)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (credentials == null)
            {
                return(null);
            }
            AuthenticationManager.EnsureModules();
            ArrayList obj = AuthenticationManager.modules;

            lock (obj)
            {
                foreach (object obj2 in AuthenticationManager.modules)
                {
                    IAuthenticationModule authenticationModule = (IAuthenticationModule)obj2;
                    Authorization         authorization        = authenticationModule.PreAuthenticate(request, credentials);
                    if (authorization != null)
                    {
                        authorization.Module = authenticationModule;
                        return(authorization);
                    }
                }
            }
            return(null);
        }
        internal static void Clear()
        {
            AuthenticationManager.EnsureModules();
            ArrayList obj = AuthenticationManager.modules;

            lock (obj)
            {
                AuthenticationManager.modules.Clear();
            }
        }
        private static Authorization DoAuthenticate(string challenge, WebRequest request, ICredentials credentials)
        {
            AuthenticationManager.EnsureModules();
            ArrayList obj = AuthenticationManager.modules;

            lock (obj)
            {
                foreach (object obj2 in AuthenticationManager.modules)
                {
                    IAuthenticationModule authenticationModule = (IAuthenticationModule)obj2;
                    Authorization         authorization        = authenticationModule.Authenticate(challenge, request, credentials);
                    if (authorization != null)
                    {
                        authorization.Module = authenticationModule;
                        return(authorization);
                    }
                }
            }
            return(null);
        }