Exemple #1
0
        // internal methods
        internal IAuthenticator ToAuthenticator()
        {
            var passwordEvidence = _evidence as PasswordEvidence;

            if (passwordEvidence != null)
            {
                var insecurePassword = MongoUtils.ToInsecureString(passwordEvidence.SecurePassword);
                var credential       = new UsernamePasswordCredential(
                    _identity.Source,
                    _identity.Username,
                    insecurePassword);
                if (_mechanism == null)
                {
                    return(new DefaultAuthenticator(credential));
                }
#pragma warning disable 618
                else if (_mechanism == MongoDBCRAuthenticator.MechanismName)
                {
                    return(new MongoDBCRAuthenticator(credential));

#pragma warning restore 618
                }
                else if (_mechanism == ScramSha1Authenticator.MechanismName)
                {
                    return(new ScramSha1Authenticator(credential));
                }
                else if (_mechanism == ScramSha256Authenticator.MechanismName)
                {
                    return(new ScramSha256Authenticator(credential));
                }
                else if (_mechanism == PlainAuthenticator.MechanismName)
                {
                    return(new PlainAuthenticator(credential));
                }
                else if (_mechanism == GssapiAuthenticator.MechanismName)
                {
                    return(new GssapiAuthenticator(
                               credential,
                               _mechanismProperties.Select(x => new KeyValuePair <string, string>(x.Key, x.Value.ToString()))));
                }
            }
            else if (_identity.Source == "$external" && _evidence is ExternalEvidence)
            {
                if (_mechanism == MongoDBX509Authenticator.MechanismName)
                {
                    return(new MongoDBX509Authenticator(_identity.Username));
                }
                else if (_mechanism == GssapiAuthenticator.MechanismName)
                {
                    return(new GssapiAuthenticator(
                               _identity.Username,
                               _mechanismProperties.Select(x => new KeyValuePair <string, string>(x.Key, x.Value.ToString()))));
                }
            }

            throw new NotSupportedException("Unable to create an authenticator.");
        }
Exemple #2
0
        // internal methods
        internal IAuthenticator ToAuthenticator()
        {
            var passwordEvidence = _evidence as PasswordEvidence;

            if (passwordEvidence != null)
            {
                var credential = new UsernamePasswordCredential(
                    _identity.Source,
                    _identity.Username,
                    MongoUtils.ToInsecureString(passwordEvidence.SecurePassword));
                if (_mechanism == null || _mechanism == MongoDBCRAuthenticator.MechanismName)
                {
                    return(new MongoDBCRAuthenticator(credential));
                }
                else if (_mechanism == ScramSha1Authenticator.MechanismName)
                {
                    return(new ScramSha1Authenticator(credential));
                }
                else if (_mechanism == PlainAuthenticator.MechanismName)
                {
                    return(new PlainAuthenticator(credential));
                }
                else if (_mechanism == GssapiAuthenticator.MechanismName)
                {
                    return(new GssapiAuthenticator(credential, _mechanismProperties));
                }
            }
            else if (_identity.Source == "$external" && _evidence is ExternalEvidence)
            {
                if (_mechanism == MongoDBX509Authenticator.MechanismName)
                {
                    return(new MongoDBX509Authenticator(_identity.Username));
                }
                else if (_mechanism == GssapiAuthenticator.MechanismName)
                {
                    return(new GssapiAuthenticator(_identity.Username, _mechanismProperties));
                }
            }

            throw new NotSupportedException("Unable to create an authenticator.");
        }