public void Remove(string?host, int port, string?authenticationType) { if (host == null || authenticationType == null) { // These couldn't possibly have been inserted into // the cache because of the test in Add(). return; } if (port < 0) { return; } if (_cacheForHosts == null) { if (NetEventSource.IsEnabled) { NetEventSource.Info(this, "Short-circuiting because the dictionary is null."); } return; } ++_version; var key = new CredentialHostKey(host, port, authenticationType); if (NetEventSource.IsEnabled) { NetEventSource.Info(this, $"Removing key:[{key}]"); } _cacheForHosts.Remove(key); }
public void Add(string host, int port, string authenticationType, NetworkCredential credential) { if (host == null) { throw new ArgumentNullException("host"); } if (authenticationType == null) { throw new ArgumentNullException("authenticationType"); } if (host.Length == 0) { throw new ArgumentException(SR.GetString("net_emptystringcall", new object[] { "host" })); } if (port < 0) { throw new ArgumentOutOfRangeException("port"); } if ((((credential is SystemNetworkCredential) && (string.Compare(authenticationType, "NTLM", StringComparison.OrdinalIgnoreCase) != 0)) && (!DigestClient.WDigestAvailable || (string.Compare(authenticationType, "Digest", StringComparison.OrdinalIgnoreCase) != 0))) && ((string.Compare(authenticationType, "Kerberos", StringComparison.OrdinalIgnoreCase) != 0) && (string.Compare(authenticationType, "Negotiate", StringComparison.OrdinalIgnoreCase) != 0))) { throw new ArgumentException(SR.GetString("net_nodefaultcreds", new object[] { authenticationType }), "authenticationType"); } this.m_version++; CredentialHostKey key = new CredentialHostKey(host, port, authenticationType); this.cacheForHosts.Add(key, credential); if (credential is SystemNetworkCredential) { this.m_NumbDefaultCredInCache++; } }
public NetworkCredential?GetCredential(string host, int port, string authenticationType) { ArgumentException.ThrowIfNullOrEmpty(host); ArgumentNullException.ThrowIfNull(authenticationType); if (port < 0) { throw new ArgumentOutOfRangeException(nameof(port)); } if (_cacheForHosts == null) { if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(this, "CredentialCache::GetCredential short-circuiting because the dictionary is null."); } return(null); } var key = new CredentialHostKey(host, port, authenticationType); NetworkCredential?match; _cacheForHosts.TryGetValue(key, out match); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(this, $"Returning {((match == null) ? "null" : "(" + match.UserName + ":" + match.Domain + ")")}"); } return(match); }
public void Add(string host, int port, string authenticationType, NetworkCredential credential) { // Parameter validation if (host == null) { throw new ArgumentNullException("host"); } if (authenticationType == null) { throw new ArgumentNullException("authenticationType"); } if (host.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, "host")); } if (port < 0) { throw new ArgumentOutOfRangeException("port"); } ++_version; CredentialHostKey key = new CredentialHostKey(host, port, authenticationType); GlobalLog.Print("CredentialCache::Add() Adding key:[" + key.ToString() + "], cred:[" + credential.Domain + "],[" + credential.UserName + "]"); _cacheForHosts.Add(key, credential); if (credential is SystemNetworkCredential) { ++_numbDefaultCredInCache; } }
public NetworkCredential GetCredential(string host, int port, string authenticationType) { if (host == null) { throw new ArgumentNullException("host"); } if (authenticationType == null) { throw new ArgumentNullException("authenticationType"); } if (host.Length == 0) { throw new ArgumentException(SR.GetString("net_emptystringcall", new object[] { "host" })); } if (port < 0) { throw new ArgumentOutOfRangeException("port"); } NetworkCredential credential = null; IDictionaryEnumerator enumerator = this.cacheForHosts.GetEnumerator(); while (enumerator.MoveNext()) { CredentialHostKey key = (CredentialHostKey)enumerator.Key; if (key.Match(host, port, authenticationType)) { credential = (NetworkCredential)enumerator.Value; } } return(credential); }
public void Remove(string host, int port, string authenticationType) { if (host == null || authenticationType == null) { // These couldn't possibly have been inserted into // the cache because of the test in Add(). return; } if (port < 0) { return; } ++_version; CredentialHostKey key = new CredentialHostKey(host, port, authenticationType); if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::Remove() Removing key:[" + key.ToString() + "]"); } if (_cacheForHosts[key] is SystemNetworkCredential) { --_numbDefaultCredInCache; } _cacheForHosts.Remove(key); }
public void Remove(string host, int port, string authenticationType) { if (host == null || authenticationType == null) { // These couldn't possibly have been inserted into // the cache because of the test in Add(). return; } if (port < 0) { return; } if (_cacheForHosts == null) { if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::Remove() Short-circuiting because the dictionary is null."); } return; } ++_version; var key = new CredentialHostKey(host, port, authenticationType); if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::Remove() Removing key:[" + key.ToString() + "]"); } _cacheForHosts.Remove(key); }
public void Add(string host, int port, string authenticationType, NetworkCredential credential) { ArgumentException.ThrowIfNullOrEmpty(host); ArgumentNullException.ThrowIfNull(authenticationType); if (port < 0) { throw new ArgumentOutOfRangeException(nameof(port)); } if ((credential is SystemNetworkCredential) && !((string.Equals(authenticationType, NegotiationInfoClass.NTLM, StringComparison.OrdinalIgnoreCase)) || (string.Equals(authenticationType, NegotiationInfoClass.Kerberos, StringComparison.OrdinalIgnoreCase)) || (string.Equals(authenticationType, NegotiationInfoClass.Negotiate, StringComparison.OrdinalIgnoreCase))) ) { throw new ArgumentException(SR.Format(SR.net_nodefaultcreds, authenticationType), nameof(authenticationType)); } ++_version; var key = new CredentialHostKey(host, port, authenticationType); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(this, $"Adding key:[{key}], cred:[{credential.Domain}],[{credential.UserName}]"); } _cacheForHosts ??= new Dictionary <CredentialHostKey, NetworkCredential>(); _cacheForHosts.Add(key, credential); }
public override bool Equals(object comparand) { CredentialHostKey key = comparand as CredentialHostKey; if (comparand == null) { return(false); } return(((string.Compare(this.AuthenticationType, key.AuthenticationType, StringComparison.OrdinalIgnoreCase) == 0) && (string.Compare(this.Host, key.Host, StringComparison.OrdinalIgnoreCase) == 0)) && (this.Port == key.Port)); }
public void Remove(string host, int port, string authenticationType) { if (((host != null) && (authenticationType != null)) && (port >= 0)) { this.m_version++; CredentialHostKey key = new CredentialHostKey(host, port, authenticationType); if (this.cacheForHosts[key] is SystemNetworkCredential) { this.m_NumbDefaultCredInCache--; } this.cacheForHosts.Remove(key); } }
public void Add(string host, int port, string authenticationType, NetworkCredential credential) { // // parameter validation // if (host == null) { throw new ArgumentNullException("host"); } if (authenticationType == null) { throw new ArgumentNullException("authenticationType"); } if (host.Length == 0) { throw new ArgumentException(SR.GetString(SR.net_emptystringcall, "host")); } if (port < 0) { throw new ArgumentOutOfRangeException("port"); } if ((credential is SystemNetworkCredential) #if !FEATURE_PAL && !((string.Compare(authenticationType, NtlmClient.AuthType, StringComparison.OrdinalIgnoreCase) == 0) || (DigestClient.WDigestAvailable && (string.Compare(authenticationType, DigestClient.AuthType, StringComparison.OrdinalIgnoreCase) == 0)) || (string.Compare(authenticationType, KerberosClient.AuthType, StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(authenticationType, NegotiateClient.AuthType, StringComparison.OrdinalIgnoreCase) == 0)) #endif ) { throw new ArgumentException(SR.GetString(SR.net_nodefaultcreds, authenticationType), "authenticationType"); } ++m_version; CredentialHostKey key = new CredentialHostKey(host, port, authenticationType); GlobalLog.Print("CredentialCache::Add() Adding key:[" + key.ToString() + "], cred:[" + credential.Domain + "],[" + credential.UserName + "]"); cacheForHosts.Add(key, credential); if (credential is SystemNetworkCredential) { ++m_NumbDefaultCredInCache; } }
public NetworkCredential GetCredential(string host, int port, string authenticationType) { if (host == null) { throw new ArgumentNullException("host"); } if (authenticationType == null) { throw new ArgumentNullException("authenticationType"); } if (host.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, "host")); } if (port < 0) { throw new ArgumentOutOfRangeException("port"); } bool globalLogEnabled = GlobalLog.IsEnabled; if (globalLogEnabled) { GlobalLog.Print("CredentialCache::GetCredential(host=\"" + host + ":" + port.ToString() + "\", authenticationType=\"" + authenticationType + "\")"); } NetworkCredential match = null; IDictionaryEnumerator credEnum = _cacheForHosts.GetEnumerator(); // Enumerate through every credential in the cache while (credEnum.MoveNext()) { CredentialHostKey key = (CredentialHostKey)credEnum.Key; // Determine if this credential is applicable to the current Uri/AuthType if (key.Match(host, port, authenticationType)) { match = (NetworkCredential)credEnum.Value; } } if (globalLogEnabled) { GlobalLog.Print("CredentialCache::GetCredential returning " + ((match == null) ? "null" : "(" + match.UserName + ":" + match.Domain + ")")); } return(match); }
public NetworkCredential GetCredential(string host, int port, string authenticationType) { if (host == null) { throw new ArgumentNullException(nameof(host)); } if (authenticationType == null) { throw new ArgumentNullException(nameof(authenticationType)); } if (host.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(host)), nameof(host)); } if (port < 0) { throw new ArgumentOutOfRangeException(nameof(port)); } if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::GetCredential(host=\"" + host + ":" + port.ToString() + "\", authenticationType=\"" + authenticationType + "\")"); } if (_cacheForHosts == null) { if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::GetCredential short-circuiting because the dictionary is null."); } return(null); } var key = new CredentialHostKey(host, port, authenticationType); NetworkCredential match = null; _cacheForHosts.TryGetValue(key, out match); if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::GetCredential returning " + ((match == null) ? "null" : "(" + match.UserName + ":" + match.Domain + ")")); } return(match); }
public NetworkCredential?GetCredential(string host, int port, string authenticationType) { if (host == null) { throw new ArgumentNullException(nameof(host)); } if (authenticationType == null) { throw new ArgumentNullException(nameof(authenticationType)); } if (host.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(host)), nameof(host)); } if (port < 0) { throw new ArgumentOutOfRangeException(nameof(port)); } if (NetEventSource.IsEnabled) { NetEventSource.Enter(this, host, port, authenticationType); } if (_cacheForHosts == null) { if (NetEventSource.IsEnabled) { NetEventSource.Info(this, "CredentialCache::GetCredential short-circuiting because the dictionary is null."); } return(null); } var key = new CredentialHostKey(host, port, authenticationType); NetworkCredential?match = null; _cacheForHosts.TryGetValue(key, out match); if (NetEventSource.IsEnabled) { NetEventSource.Info(this, $"Returning {((match == null) ? "null" : "(" + match.UserName + ":" + match.Domain + ")")}"); } return(match); }
public override bool Equals(object comparand) { CredentialHostKey comparedCredentialKey = comparand as CredentialHostKey; if (comparand == null) { // This covers also the compared == null case return(false); } bool equals = string.Equals(AuthenticationType, comparedCredentialKey.AuthenticationType, StringComparison.OrdinalIgnoreCase) && string.Equals(Host, comparedCredentialKey.Host, StringComparison.OrdinalIgnoreCase) && Port == comparedCredentialKey.Port; GlobalLog.Print("CredentialKey::Equals(" + ToString() + ", " + comparedCredentialKey.ToString() + ") returns " + equals.ToString()); return(equals); }
public NetworkCredential GetCredential(string host, int port, string authenticationType) { if (host == null) { throw new ArgumentNullException(nameof(host)); } if (authenticationType == null) { throw new ArgumentNullException(nameof(authenticationType)); } if (host.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, "host")); } if (port < 0) { throw new ArgumentOutOfRangeException(nameof(port)); } if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::GetCredential(host=\"" + host + ":" + port.ToString() + "\", authenticationType=\"" + authenticationType + "\")"); } NetworkCredential match = null; // Enumerate through every credential in the cache foreach (KeyValuePair <CredentialHostKey, NetworkCredential> pair in _cacheForHosts) { CredentialHostKey key = pair.Key; // Determine if this credential is applicable to the current Uri/AuthType if (key.Match(host, port, authenticationType)) { match = pair.Value; } } if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::GetCredential returning " + ((match == null) ? "null" : "(" + match.UserName + ":" + match.Domain + ")")); } return(match); }
public void Add(string host, int port, string authenticationType, NetworkCredential credential) { if (host == null) { throw new ArgumentNullException(nameof(host)); } if (authenticationType == null) { throw new ArgumentNullException(nameof(authenticationType)); } if (host.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(host)), nameof(host)); } if (port < 0) { throw new ArgumentOutOfRangeException(nameof(port)); } ++_version; var key = new CredentialHostKey(host, port, authenticationType); if (NetEventSource.IsEnabled) { NetEventSource.Info(this, $"Adding key:[{key}], cred:[{credential.Domain}],[{credential.UserName}]"); } if (_cacheForHosts == null) { _cacheForHosts = new Dictionary <CredentialHostKey, NetworkCredential>(); } _cacheForHosts.Add(key, credential); }
public void Add(string host, int port, string authenticationType, NetworkCredential credential) { if (host == null) { throw new ArgumentNullException(nameof(host)); } if (authenticationType == null) { throw new ArgumentNullException(nameof(authenticationType)); } if (host.Length == 0) { throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(host)), nameof(host)); } if (port < 0) { throw new ArgumentOutOfRangeException(nameof(port)); } ++_version; var key = new CredentialHostKey(host, port, authenticationType); if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::Add() Adding key:[" + key.ToString() + "], cred:[" + credential.Domain + "],[" + credential.UserName + "]"); } if (_cacheForHosts == null) { _cacheForHosts = new Dictionary <CredentialHostKey, NetworkCredential>(); } _cacheForHosts.Add(key, credential); }
public void Add(string host, int port, string authenticationType, NetworkCredential credential) { // // parameter validation // if (host==null) { throw new ArgumentNullException("host"); } if (authenticationType==null) { throw new ArgumentNullException("authenticationType"); } if (host.Length == 0) { throw new ArgumentException(SR.GetString(SR.net_emptystringcall,"host")); } if (port < 0) { throw new ArgumentOutOfRangeException("port"); } if ((credential is SystemNetworkCredential) #if !FEATURE_PAL && !((string.Compare(authenticationType, NtlmClient.AuthType, StringComparison.OrdinalIgnoreCase)==0) || (DigestClient.WDigestAvailable && (string.Compare(authenticationType, DigestClient.AuthType, StringComparison.OrdinalIgnoreCase)==0)) || (string.Compare(authenticationType, KerberosClient.AuthType, StringComparison.OrdinalIgnoreCase)==0) || (string.Compare(authenticationType, NegotiateClient.AuthType, StringComparison.OrdinalIgnoreCase)==0)) #endif ) { throw new ArgumentException(SR.GetString(SR.net_nodefaultcreds, authenticationType), "authenticationType"); } ++m_version; CredentialHostKey key = new CredentialHostKey(host,port, authenticationType); GlobalLog.Print("CredentialCache::Add() Adding key:[" + key.ToString() + "], cred:[" + credential.Domain + "],[" + credential.UserName + "]"); cacheForHosts.Add(key, credential); if (credential is SystemNetworkCredential) { ++m_NumbDefaultCredInCache; } }
public void Remove(string host, int port, string authenticationType) { if (host==null || authenticationType==null) { // these couldn't possibly have been inserted into // the cache because of the test in Add() return; } if (port < 0) { return; } ++m_version; CredentialHostKey key = new CredentialHostKey(host, port, authenticationType); GlobalLog.Print("CredentialCache::Remove() Removing key:[" + key.ToString() + "]"); if (cacheForHosts[key] is SystemNetworkCredential) { --m_NumbDefaultCredInCache; } cacheForHosts.Remove(key); }