Example #1
0
        /// <exception cref="AuthenticationException" />
        private async Task <Response> Authenticate(byte[] token, IAuthenticator authenticator)
        {
            var request  = new AuthResponseRequest(token);
            var response = await Send(request).ConfigureAwait(false);

            if (response is AuthSuccessResponse)
            {
                // It is now authenticated, dispose Authenticator if it implements IDisposable()
                // ReSharper disable once SuspiciousTypeConversion.Global
                var disposableAuthenticator = authenticator as IDisposable;
                if (disposableAuthenticator != null)
                {
                    disposableAuthenticator.Dispose();
                }
                return(response);
            }
            if (response is AuthChallengeResponse)
            {
                token = authenticator.EvaluateChallenge(((AuthChallengeResponse)response).Token);
                if (token == null)
                {
                    // If we get a null response, then authentication has completed
                    // return without sending a further response back to the server.
                    return(response);
                }
                return(await Authenticate(token, authenticator).ConfigureAwait(false));
            }
            throw new ProtocolErrorException("Expected SASL response, obtained " + response.GetType().Name);
        }
Example #2
0
        /// <exception cref="AuthenticationException" />
        private Task <Response> Authenticate(byte[] token, IAuthenticator authenticator)
        {
            var request = new AuthResponseRequest(ProtocolVersion, token);

            return(Send(request)
                   .Then(response =>
            {
                if (response is AuthSuccessResponse)
                {
                    //It is now authenticated
                    return TaskHelper.ToTask(response);
                }
                if (response is AuthChallengeResponse)
                {
                    token = authenticator.EvaluateChallenge(((AuthChallengeResponse)response).Token);
                    if (token == null)
                    {
                        // If we get a null response, then authentication has completed
                        //return without sending a further response back to the server.
                        return TaskHelper.ToTask(response);
                    }
                    return Authenticate(token, authenticator);
                }
                throw new ProtocolErrorException("Expected SASL response, obtained " + response.GetType().Name);
            }));
        }
Example #3
0
        /// <exception cref="AuthenticationException" />
        private void Authenticate(byte[] token, IAuthenticator authenticator)
        {
            var request  = new AuthResponseRequest(this.ProtocolVersion, token);
            var response = TaskHelper.WaitToComplete(this.Send(request), Configuration.SocketOptions.ConnectTimeoutMillis);

            if (response is AuthSuccessResponse)
            {
                //It is now authenticated
                return;
            }
            if (response is AuthChallengeResponse)
            {
                token = authenticator.EvaluateChallenge((response as AuthChallengeResponse).Token);
                if (token == null)
                {
                    // If we get a null response, then authentication has completed
                    //return without sending a further response back to the server.
                    return;
                }
                Authenticate(token, authenticator);
                return;
            }
            throw new ProtocolErrorException("Expected SASL response, obtained " + response.GetType().Name);
        }
Example #4
0
 /// <exception cref="AuthenticationException" />
 private void Authenticate(byte[] token, IAuthenticator authenticator)
 {
     var request = new AuthResponseRequest(this.ProtocolVersion, token);
     var response = TaskHelper.WaitToComplete(this.Send(request), Configuration.SocketOptions.ConnectTimeoutMillis);
     if (response is AuthSuccessResponse)
     {
         //It is now authenticated
         return;
     }
     if (response is AuthChallengeResponse)
     {
         token = authenticator.EvaluateChallenge((response as AuthChallengeResponse).Token);
         if (token == null)
         {
             // If we get a null response, then authentication has completed
             //return without sending a further response back to the server.
             return;
         }
         Authenticate(token, authenticator);
         return;
     }
     throw new ProtocolErrorException("Expected SASL response, obtained " + response.GetType().Name);
 }
Example #5
0
 /// <exception cref="AuthenticationException" />
 private Task<AbstractResponse> Authenticate(byte[] token, IAuthenticator authenticator)
 {
     var request = new AuthResponseRequest(ProtocolVersion, token);
     return Send(request)
         .Then(response =>
         {
             if (response is AuthSuccessResponse)
             {
                 //It is now authenticated
                 return TaskHelper.ToTask(response);
             }
             if (response is AuthChallengeResponse)
             {
                 token = authenticator.EvaluateChallenge(((AuthChallengeResponse)response).Token);
                 if (token == null)
                 {
                     // If we get a null response, then authentication has completed
                     //return without sending a further response back to the server.
                     return TaskHelper.ToTask(response);
                 }
                 return Authenticate(token, authenticator);
             }
             throw new ProtocolErrorException("Expected SASL response, obtained " + response.GetType().Name);
         });
 }