// constructors public ClusterKey( bool allowInsecureTls, string applicationName, Action <ClusterBuilder> clusterConfigurator, IReadOnlyList <CompressorConfiguration> compressors, #pragma warning disable CS0618 // Type or member is obsolete ConnectionMode connectionMode, ConnectionModeSwitch connectionModeSwitch, #pragma warning restore CS0618 // Type or member is obsolete TimeSpan connectTimeout, IReadOnlyList <MongoCredential> credentials, bool?directConnection, TimeSpan heartbeatInterval, TimeSpan heartbeatTimeout, bool ipv6, IReadOnlyDictionary <string, IReadOnlyDictionary <string, object> > kmsProviders, TimeSpan localThreshold, TimeSpan maxConnectionIdleTime, TimeSpan maxConnectionLifeTime, int maxConnectionPoolSize, int minConnectionPoolSize, int receiveBufferSize, string replicaSetName, IReadOnlyDictionary <string, BsonDocument> schemaMap, ConnectionStringScheme scheme, string sdamLogFilename, int sendBufferSize, ServerApi serverApi, IReadOnlyList <MongoServerAddress> servers, TimeSpan serverSelectionTimeout, TimeSpan socketTimeout, SslSettings sslSettings, bool useTls, int waitQueueSize, TimeSpan waitQueueTimeout) { ConnectionModeHelper.EnsureConnectionModeValuesAreValid(connectionMode, connectionModeSwitch, directConnection); _allowInsecureTls = allowInsecureTls; _applicationName = applicationName; _clusterConfigurator = clusterConfigurator; _compressors = compressors; _connectionMode = connectionMode; _connectionModeSwitch = connectionModeSwitch; _connectTimeout = connectTimeout; _credentials = credentials; _directConnection = directConnection; _heartbeatInterval = heartbeatInterval; _heartbeatTimeout = heartbeatTimeout; _ipv6 = ipv6; _kmsProviders = kmsProviders; _localThreshold = localThreshold; _maxConnectionIdleTime = maxConnectionIdleTime; _maxConnectionLifeTime = maxConnectionLifeTime; _maxConnectionPoolSize = maxConnectionPoolSize; _minConnectionPoolSize = minConnectionPoolSize; _receiveBufferSize = receiveBufferSize; _replicaSetName = replicaSetName; _schemaMap = schemaMap; _scheme = scheme; _sdamLogFilename = sdamLogFilename; _sendBufferSize = sendBufferSize; _serverApi = serverApi; _servers = servers; _serverSelectionTimeout = serverSelectionTimeout; _socketTimeout = socketTimeout; _sslSettings = sslSettings; _useTls = useTls; _waitQueueSize = waitQueueSize; _waitQueueTimeout = waitQueueTimeout; _hashCode = CalculateHashCode(); }
// internal methods internal IAuthenticator ToAuthenticator(ServerApi serverApi) { var passwordEvidence = _evidence as PasswordEvidence; if (passwordEvidence != null) { var insecurePassword = SecureStringHelper.ToInsecureString(passwordEvidence.SecurePassword); var credential = new UsernamePasswordCredential( _identity.Source, _identity.Username, insecurePassword); if (_mechanism == null) { return(new DefaultAuthenticator(credential, serverApi)); } #pragma warning disable 618 if (_mechanism == MongoDBCRAuthenticator.MechanismName) { return(new MongoDBCRAuthenticator(credential, serverApi)); #pragma warning restore 618 } if (_mechanism == ScramSha1Authenticator.MechanismName) { return(new ScramSha1Authenticator(credential, serverApi)); } if (_mechanism == ScramSha256Authenticator.MechanismName) { return(new ScramSha256Authenticator(credential, serverApi)); } if (_mechanism == PlainAuthenticator.MechanismName) { return(new PlainAuthenticator(credential, serverApi)); } if (_mechanism == GssapiAuthenticator.MechanismName) { return(new GssapiAuthenticator( credential, _mechanismProperties.Select(x => new KeyValuePair <string, string>(x.Key, x.Value.ToString())), serverApi)); } if (_mechanism == MongoAWSAuthenticator.MechanismName) { return(new MongoAWSAuthenticator( credential, _mechanismProperties.Select(x => new KeyValuePair <string, string>(x.Key, x.Value.ToString())), serverApi)); } } else if (_identity.Source == "$external" && _evidence is ExternalEvidence) { if (_mechanism == MongoDBX509Authenticator.MechanismName) { return(new MongoDBX509Authenticator(_identity.Username, serverApi)); } if (_mechanism == GssapiAuthenticator.MechanismName) { return(new GssapiAuthenticator( _identity.Username, _mechanismProperties.Select(x => new KeyValuePair <string, string>(x.Key, x.Value.ToString())), serverApi)); } if (_mechanism == MongoAWSAuthenticator.MechanismName) { return(new MongoAWSAuthenticator( _identity.Username, _mechanismProperties.Select(x => new KeyValuePair <string, string>(x.Key, x.Value.ToString())), serverApi)); } } throw new NotSupportedException("Unable to create an authenticator."); }