Search in sources :

Example 1 with MechanismMismatchException

use of io.vertx.proton.sasl.MechanismMismatchException in project vertx-proton by vert-x3.

the class ProtonSaslClientAuthenticatorImpl method handleSaslInit.

private void handleSaslInit() throws SaslException {
    String[] remoteMechanisms = sasl.getRemoteMechanisms();
    if (remoteMechanisms != null && remoteMechanisms.length != 0) {
        Principal localPrincipal = null;
        SSLSession sslSession = socket.sslSession();
        if (sslSession != null) {
            localPrincipal = sslSession.getLocalPrincipal();
        }
        mechanism = ProtonSaslMechanismFinderImpl.findMatchingMechanism(username, password, localPrincipal, mechanismsRestriction, remoteMechanisms);
        if (mechanism != null) {
            mechanism.setUsername(username);
            mechanism.setPassword(password);
            sasl.setMechanisms(mechanism.getName());
            byte[] response = mechanism.getInitialResponse();
            if (response != null) {
                sasl.send(response, 0, response.length);
            }
        } else {
            throw new MechanismMismatchException("Could not find a suitable SASL mechanism for the remote peer using the available credentials.", remoteMechanisms);
        }
    }
}
Also used : SSLSession(javax.net.ssl.SSLSession) MechanismMismatchException(io.vertx.proton.sasl.MechanismMismatchException) Principal(java.security.Principal)

Aggregations

MechanismMismatchException (io.vertx.proton.sasl.MechanismMismatchException)1 Principal (java.security.Principal)1 SSLSession (javax.net.ssl.SSLSession)1