PreAuthenticate() public static method

public static PreAuthenticate ( System request, ICredentials credentials ) : Authorization
request System
credentials ICredentials
return Authorization
 internal void PreAuthIfNeeded(HttpWebRequest httpWebRequest, ICredentials authInfo)
 {
     if (!this.TriedPreAuth)
     {
         this.TriedPreAuth = true;
         if (authInfo != null)
         {
             this.PrepareState(httpWebRequest);
             System.Net.Authorization authorization = null;
             try
             {
                 authorization = AuthenticationManager.PreAuthenticate(httpWebRequest, authInfo);
                 if ((authorization != null) && (authorization.Message != null))
                 {
                     this.UniqueGroupId = authorization.ConnectionGroupId;
                     httpWebRequest.Headers.Set(this.AuthorizationHeader, authorization.Message);
                 }
             }
             catch (Exception)
             {
                 this.ClearSession(httpWebRequest);
             }
         }
     }
 }
Exemplo n.º 2
0
 //
 internal void PreAuthIfNeeded(HttpWebRequest httpWebRequest, ICredentials authInfo)
 {
     //
     // attempt to do preauth, if needed
     //
     GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::PreAuthIfNeeded() TriedPreAuth:" + TriedPreAuth.ToString() + " authInfo:" + ValidationHelper.HashString(authInfo));
     if (!TriedPreAuth)
     {
         TriedPreAuth = true;
         if (authInfo != null)
         {
             PrepareState(httpWebRequest);
             Authorization preauth = null;
             try {
                 preauth = AuthenticationManager.PreAuthenticate(httpWebRequest, authInfo);
                 GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::PreAuthIfNeeded() preauth:" + ValidationHelper.HashString(preauth));
                 if (preauth != null && preauth.Message != null)
                 {
                     GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::PreAuthIfNeeded() setting TriedPreAuth to Complete:" + preauth.Complete.ToString());
                     UniqueGroupId = preauth.ConnectionGroupId;
                     httpWebRequest.Headers.Set(AuthorizationHeader, preauth.Message);
                 }
             }
             catch (Exception exception) {
                 GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::PreAuthIfNeeded() PreAuthenticate() returned exception:" + exception.Message);
                 ClearSession(httpWebRequest);
             }
         }
     }
 }
Exemplo n.º 3
0
		void DoPreAuthenticate ()
		{
			bool isProxy = (proxy != null && !proxy.IsBypassed (actualUri));
			ICredentials creds = (!isProxy || credentials != null) ? credentials : proxy.Credentials;
			Authorization auth = AuthenticationManager.PreAuthenticate (this, creds);
			if (auth == null)
				return;

			webHeaders.RemoveInternal ("Proxy-Authorization");
			webHeaders.RemoveInternal ("Authorization");
			string authHeader = (isProxy && credentials == null) ? "Proxy-Authorization" : "Authorization";
			webHeaders [authHeader] = auth.Message;
			usedPreAuth = true;
		}
Exemplo n.º 4
0
        internal bool AddHttpAuthHeaders(String challenge)
        {
            ICredentials  cred;
            String        challengeType = "Basic"; /* default */
            Authorization auth;

            if (credentials == null)
            {
                return(false);
            }
            if (challenge == null && !preAuthenticate)
            {
                return(false);        /* TODO : throw an exception here ? */
            }
            else if (challenge != null)
            {
                int len = challenge.IndexOf(' ');
                challengeType = (len == -1) ? challenge :
                                challenge.Substring(0, len);
            }
            cred = credentials.GetCredential(this.Address, challengeType);
            if (cred == null)
            {
                return(false);        /* TODO : throw an exception here ? */
            }

            if (preAuthenticate)
            {
                auth = AuthenticationManager.PreAuthenticate(this,
                                                             cred);
            }
            else
            {
                auth = AuthenticationManager.Authenticate(challenge,
                                                          this, cred);
            }

            if (auth == null)
            {
                return(false);        /* TODO : throw an exception here ? */
            }
            this.Headers["Authorization"] = auth.Message;
            return(true);
        }