Search in sources :

Example 1 with AuthenticationFailureException

use of com.rabbitmq.stream.AuthenticationFailureException in project rabbitmq-stream-java-client by rabbitmq.

the class Client method authenticate.

private void authenticate() {
    List<String> saslMechanisms = getSaslMechanisms();
    SaslMechanism saslMechanism = this.saslConfiguration.getSaslMechanism(saslMechanisms);
    byte[] challenge = null;
    boolean authDone = false;
    while (!authDone) {
        byte[] saslResponse = saslMechanism.handleChallenge(challenge, this.credentialsProvider);
        SaslAuthenticateResponse saslAuthenticateResponse = sendSaslAuthenticate(saslMechanism, saslResponse);
        if (saslAuthenticateResponse.isOk()) {
            authDone = true;
        } else if (saslAuthenticateResponse.isChallenge()) {
            challenge = saslAuthenticateResponse.challenge;
        } else if (saslAuthenticateResponse.isAuthenticationFailure()) {
            throw new AuthenticationFailureException("Unexpected response code during authentication: " + formatConstant(saslAuthenticateResponse.getResponseCode()));
        } else {
            throw new StreamException("Unexpected response code during authentication: " + formatConstant(saslAuthenticateResponse.getResponseCode()));
        }
    }
}
Also used : SaslMechanism(com.rabbitmq.stream.sasl.SaslMechanism) AuthenticationFailureException(com.rabbitmq.stream.AuthenticationFailureException) StreamException(com.rabbitmq.stream.StreamException)

Aggregations

AuthenticationFailureException (com.rabbitmq.stream.AuthenticationFailureException)1 StreamException (com.rabbitmq.stream.StreamException)1 SaslMechanism (com.rabbitmq.stream.sasl.SaslMechanism)1