/// <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); }
/// <include file='doc\AuthenticationManager.uex' path='docs/doc[@for="AuthenticationManager.PreAuthenticate"]/*' /> /// <devdoc> /// <para>Pre-authenticates a request.</para> /// </devdoc> public static Authorization PreAuthenticate(WebRequest request, ICredentials credentials) { GlobalLog.Print("AuthenticationManager::PreAuthenticate() request:" + ValidationHelper.HashString(request) + " credentials:" + ValidationHelper.HashString(credentials)); if (request == null) { throw new ArgumentNullException("request"); } if (credentials == null) { return(null); } // // PrefixLookup is thread-safe // string moduleName = s_ModuleBinding.Lookup(((HttpWebRequest)request).ChallengedUri.AbsoluteUri) as string; GlobalLog.Print("AuthenticationManager::PreAuthenticate() s_ModuleBinding.Lookup returns:" + ValidationHelper.ToString(moduleName)); if (moduleName == null) { return(null); } IAuthenticationModule module = findModule(moduleName); if (module == null) { // The module could have been unregistered // No preauthentication is possible return(null); } else { // Otherwise invoke the PreAuthenticate method HttpWebRequest httpWebRequest = request as HttpWebRequest; if (httpWebRequest != null) { httpWebRequest.CurrentAuthenticationState.Module = module; } Authorization authorization = module.PreAuthenticate(request, credentials); GlobalLog.Print("AuthenticationManager::PreAuthenticate() IAuthenticationModule.PreAuthenticate() returned authorization:" + ValidationHelper.HashString(authorization)); return(authorization); } }
public static Authorization PreAuthenticate(WebRequest request, ICredentials credentials) { if (request == null) { throw new ArgumentNullException("request"); } if (credentials == null) { return(null); } HttpWebRequest request2 = request as HttpWebRequest; if (request2 == null) { return(null); } string authenticationType = s_ModuleBinding.Lookup(request2.ChallengedUri.AbsoluteUri) as string; if (authenticationType == null) { return(null); } IAuthenticationModule module = findModule(authenticationType); if (module == null) { return(null); } if (request2.ChallengedUri.Scheme == Uri.UriSchemeHttps) { ChannelBinding cachedChannelBinding = request2.ServicePoint.CachedChannelBinding as ChannelBinding; if (cachedChannelBinding != null) { request2.CurrentAuthenticationState.TransportContext = new CachedTransportContext(cachedChannelBinding); } } Authorization authorization = module.PreAuthenticate(request, credentials); if (((authorization != null) && !authorization.Complete) && (request2 != null)) { request2.CurrentAuthenticationState.Module = module; } return(authorization); }