Beispiel #1
0
        /// <summary>
        /// Gets the basic authentication header to be added to a HttpRequest
        /// </summary>
        /// <param name="authInfo"></param>
        /// <returns></returns>
        public HTTPHeader GetBasicAuthHeader(HttpAuthenticationInfo authInfo)
        {
            HTTPHeader header = null;
            string     credentialsString;
            string     decryptedPassword = Encryptor.DecryptToString(authInfo.Credentials.Password);

            if (String.IsNullOrEmpty(authInfo.Credentials.Domain))
            {
                credentialsString = String.Format("{0}:{1}", authInfo.Credentials.UserName, decryptedPassword);
            }
            else
            {
                credentialsString = String.Format("{0}\\{1}:{2}", authInfo.Credentials.Domain, authInfo.Credentials.UserName, decryptedPassword);
            }
            //base64 encode the string
            credentialsString = Utils.Base64Encode(credentialsString);
            if (authInfo.IsProxy)
            {
                header = new HTTPHeader("Proxy-Authorization", String.Format("Basic {0}", credentialsString));
            }
            else
            {
                header = new HTTPHeader("Authorization", String.Format("Basic {0}", credentialsString));
            }
            return(header);
        }
        /// <summary>
        /// Makes a clone of this authentication infor object
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            HttpAuthenticationInfo clone = new HttpAuthenticationInfo();


            if (_credentials != null)
            {
                clone._credentials = new NetworkCredential(_credentials.UserName, _credentials.Password, _credentials.Domain);
                clone._isProxy     = _isProxy;
            }

            return(clone);
        }
Beispiel #3
0
        /// <summary>
        /// Checks if the specified request requires credentials (an entry exists in the memory)
        /// </summary>
        /// <param name="reqInfo"></param>
        /// <param name="authInfo"></param>
        /// <returns></returns>
        public bool RequiresCredentials(HttpRequestInfo reqInfo, out HttpAuthenticationInfo authInfo)
        {
            int reqHash = reqInfo.HostAndPort.GetHashCode();

            authInfo = null;
            CacheEntry entry = this.GetEntry(reqHash);

            if (entry != null)
            {
                authInfo = entry.GetClone() as HttpAuthenticationInfo;
                return(true);
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Gets the credentials for the specified requests using the credential provider
        /// </summary>
        /// <param name="reqInfo"></param>
        /// <param name="isProxy"></param>
        /// <returns></returns>
        public HttpAuthenticationInfo GetCredentials(HttpRequestInfo reqInfo, bool isProxy)
        {
            HttpAuthenticationInfo authInfo = null;
            string domain, userName, password;

            if (_credentialsProvider != null && _credentialsProvider.Execute(out domain, out userName, out password))
            {
                //encrypt
                string encryptedPassword = Encryptor.EncryptToString(password);

                authInfo = new HttpAuthenticationInfo(new NetworkCredential(userName, encryptedPassword, domain), isProxy);
                //store the auth info in the cache
                this.Add(reqInfo.HostAndPort.GetHashCode(), new CacheEntry((ICloneable)authInfo.Clone()));
            }
            return(authInfo);
        }