1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Globalization; 6 using System.Net; 7 using System.Security.Cryptography.X509Certificates; 8 9 namespace System.DirectoryServices.Protocols 10 { 11 public abstract class DirectoryConnection 12 { 13 internal NetworkCredential _directoryCredential; 14 private X509CertificateCollection _certificatesCollection; 15 internal TimeSpan _connectionTimeOut = new TimeSpan(0, 0, 30); 16 internal DirectoryIdentifier _directoryIdentifier; 17 DirectoryConnection()18 protected DirectoryConnection() => _certificatesCollection = new X509CertificateCollection(); 19 20 public virtual DirectoryIdentifier Directory => _directoryIdentifier; 21 22 public X509CertificateCollection ClientCertificates => _certificatesCollection; 23 24 public virtual TimeSpan Timeout 25 { 26 get => _connectionTimeOut; 27 set 28 { 29 if (value < TimeSpan.Zero) 30 { 31 throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.NoNegativeTime), nameof(value)); 32 } 33 34 _connectionTimeOut = value; 35 } 36 } 37 38 public virtual NetworkCredential Credential 39 { 40 set 41 { 42 _directoryCredential = (value != null) ? new NetworkCredential(value.UserName, value.Password, value.Domain) : null; 43 } 44 } 45 SendRequest(DirectoryRequest request)46 public abstract DirectoryResponse SendRequest(DirectoryRequest request); 47 GetCredential()48 internal NetworkCredential GetCredential() => _directoryCredential; 49 } 50 } 51