示例#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;
 }
示例#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");
 }
示例#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())
 {
 }
示例#9
0
 internal ScramSha256Authenticator(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
     : base(credential, HashAlgorithmName.SHA256, randomStringGenerator, H256, Hi256, Hmac256)
 {
 }
示例#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)
 {
 }
示例#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));
 }
示例#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())
 {
 }
示例#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;
 }
示例#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);
        }
示例#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())
 {
 }
示例#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.");
        }
示例#28
0
 internal DefaultAuthenticator(UsernamePasswordCredential credential, IRandomStringGenerator randomStringGenerator)
 {
     _credential            = Ensure.IsNotNull(credential, nameof(credential));
     _randomStringGenerator = Ensure.IsNotNull(randomStringGenerator, nameof(randomStringGenerator));
 }