Esempio n. 1
0
 // constructors
 public MongoDBCRAuthenticator(UsernamePasswordCredential credential)
 {
     _credential = Ensure.IsNotNull(credential, "credential");
 }
 public ClientFirst(byte[] bytesToSendToServer, string clientFirstMessageBare, UsernamePasswordCredential credential, string rPrefix)
 {
     _bytesToSendToServer = bytesToSendToServer;
     _clientFirstMessageBare = clientFirstMessageBare;
     _credential = credential;
     _rPrefix = rPrefix;
 }
Esempio n. 3
0
 internal ScramSha1Authenticator(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
     : base(credential, HashAlgorithmName.SHA1, randomStringGenerator, H1, Hi1, Hmac1)
 {
 }
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="GssapiAuthenticator"/> class.
 /// </summary>
 /// <param name="credential">The credential.</param>
 /// <param name="properties">The properties.</param>
 public GssapiAuthenticator(UsernamePasswordCredential credential, IEnumerable<KeyValuePair<string, string>> properties)
     : base(CreateMechanism(credential, properties))
 {
 }
 internal ScramSha1Authenticator(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
     : base(new ScramSha1Mechanism(credential, randomStringGenerator))
 {
     _databaseName = credential.Source;
 }
 internal DefaultAuthenticator(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
 {
     _credential = Ensure.IsNotNull(credential, "credential");
     _randomStringGenerator = Ensure.IsNotNull(randomStringGenerator, "randomStringGenerator");
 }
 // constructors
 public PlainMechanism(UsernamePasswordCredential credential)
 {
     _credential = Ensure.IsNotNull(credential, "credential");
 }
Esempio n. 8
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="ScramSha1Authenticator"/> class.
 /// </summary>
 /// <param name="credential">The credential.</param>
 public ScramSha1Authenticator(UsernamePasswordCredential credential)
     : this(credential, new RNGCryptoServiceProviderRandomStringGenerator())
 {
 }
Esempio n. 9
0
 internal ScramSha256Authenticator(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
     : base(credential, HashAlgorithmName.SHA256, randomStringGenerator, H256, Hi256, Hmac256)
 {
 }
Esempio n. 10
0
 // constructors
 public PlainMechanism(UsernamePasswordCredential credential)
 {
     _credential = Ensure.IsNotNull(credential, nameof(credential));
 }
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultAuthenticator"/> class.
 /// </summary>
 /// <param name="credential">The credential.</param>
 /// <param name="serverApi">The server API.</param>
 public DefaultAuthenticator(UsernamePasswordCredential credential, ServerApi serverApi)
     : this(credential, new DefaultRandomStringGenerator(), serverApi)
 {
 }
Esempio n. 12
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="PlainAuthenticator"/> class.
 /// </summary>
 /// <param name="credential">The credential.</param>
 public PlainAuthenticator(UsernamePasswordCredential credential)
     : base(new PlainMechanism(credential))
 {
     _databaseName = credential.Source;
 }
 public ScramSha1Authenticator(UsernamePasswordCredential credential)
     : this(credential, serverApi : null)
 {
 }
 public PlainAuthenticator(UsernamePasswordCredential credential)
     : this(credential, serverApi : null)
 {
 }
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoDBCRAuthenticator"/> class.
 /// </summary>
 /// <param name="credential">The credential.</param>
 public MongoDBCRAuthenticator(UsernamePasswordCredential credential)
 {
     _credential = Ensure.IsNotNull(credential, nameof(credential));
 }
Esempio n. 16
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoAWSAuthenticator"/> class.
 /// </summary>
 /// <param name="credential">The credentials.</param>
 /// <param name="properties">The properties.</param>
 public MongoAWSAuthenticator(UsernamePasswordCredential credential, IEnumerable <KeyValuePair <string, string> > properties)
     : this(credential, properties, new DefaultRandomByteGenerator(), SystemClock.Instance)
 {
 }
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultAuthenticator"/> class.
 /// </summary>
 /// <param name="credential">The credential.</param>
 public DefaultAuthenticator(UsernamePasswordCredential credential)
     : this(credential, new DefaultRandomStringGenerator())
 {
 }
Esempio n. 18
0
 public ClientFirst(byte[] bytesToSendToServer, string clientFirstMessageBare, UsernamePasswordCredential credential, string rPrefix)
 {
     _bytesToSendToServer    = bytesToSendToServer;
     _clientFirstMessageBare = clientFirstMessageBare;
     _credential             = credential;
     _rPrefix = rPrefix;
 }
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="PlainAuthenticator"/> class.
 /// </summary>
 /// <param name="credential">The credential.</param>
 public PlainAuthenticator(UsernamePasswordCredential credential)
     : base(new PlainMechanism(credential))
 {
     _databaseName = credential.Source;
 }
Esempio n. 20
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="ScramSha1Authenticator"/> class.
 /// </summary>
 /// <param name="credential">The credential.</param>
 public ScramSha1Authenticator(UsernamePasswordCredential credential)
     : this(credential, new DefaultRandomStringGenerator())
 {
 }
        private static GssapiMechanism CreateMechanism(UsernamePasswordCredential credential, IEnumerable<KeyValuePair<string, string>> properties)
        {
            if (credential.Source != "$external")
            {
                throw new ArgumentException("GSSAPI authentication may only use the $external source.", "credential");
            }

            return CreateMechanism(credential.Username, credential.Password, properties);
        }
Esempio n. 22
0
 internal ScramSha1Authenticator(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
     : base(new ScramSha1Mechanism(credential, randomStringGenerator))
 {
     _databaseName = credential.Source;
 }
 // constructors
 public ScramSha1Authenticator(UsernamePasswordCredential credential)
     : this(credential, new RNGCryptoServiceProviderRandomStringGenerator())
 {
 }
Esempio n. 24
0
 public ScramSha1Mechanism(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
 {
     _credential            = Ensure.IsNotNull(credential, nameof(credential));
     _randomStringGenerator = Ensure.IsNotNull(randomStringGenerator, nameof(randomStringGenerator));
 }
 public ScramSha1Mechanism(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
 {
     _credential = Ensure.IsNotNull(credential, "credential");
     _randomStringGenerator = Ensure.IsNotNull(randomStringGenerator, "randomStringGenerator");
 }
 // constructors
 public GssapiAuthenticator(UsernamePasswordCredential credential, IEnumerable <KeyValuePair <string, string> > properties)
     : base(CreateMechanism(credential, properties))
 {
 }
        private static IAuthenticator CreateAuthenticator(ConnectionString connectionString)
        {
            if (connectionString.Password != null)
            {
                var defaultSource = GetDefaultSource(connectionString);

                var credential = new UsernamePasswordCredential(
                        connectionString.AuthSource ?? connectionString.DatabaseName ?? defaultSource,
                        connectionString.Username,
                        connectionString.Password);

                if (connectionString.AuthMechanism == null)
                {
                    return new DefaultAuthenticator(credential);
                }
                else if (connectionString.AuthMechanism == MongoDBCRAuthenticator.MechanismName)
                {
                    return new MongoDBCRAuthenticator(credential);
                }
                else if (connectionString.AuthMechanism == ScramSha1Authenticator.MechanismName)
                {
                    return new ScramSha1Authenticator(credential);
                }
                else if (connectionString.AuthMechanism == PlainAuthenticator.MechanismName)
                {
                    return new PlainAuthenticator(credential);
                }
                else if (connectionString.AuthMechanism == GssapiAuthenticator.MechanismName)
                {
                    return new GssapiAuthenticator(credential, connectionString.AuthMechanismProperties);
                }
            }
            else
            {
                if (connectionString.AuthMechanism == MongoDBX509Authenticator.MechanismName)
                {
                    return new MongoDBX509Authenticator(connectionString.Username);
                }
                else if (connectionString.AuthMechanism == GssapiAuthenticator.MechanismName)
                {
                    return new GssapiAuthenticator(connectionString.Username, connectionString.AuthMechanismProperties);
                }
            }

            throw new NotSupportedException("Unable to create an authenticator.");
        }
Esempio n. 28
0
 internal DefaultAuthenticator(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
 {
     _credential            = Ensure.IsNotNull(credential, nameof(credential));
     _randomStringGenerator = Ensure.IsNotNull(randomStringGenerator, nameof(randomStringGenerator));
 }