private SaslMechanism chooseSaslMechanismAndSendInit(Connection connection, InputStream in, OutputStream out) throws LoginException, IOException { Transport transport = connection.getTransport(); Sasl sasl = transport.sasl(); SaslMechanism mechanism = null; // read from network until we get a sasl-mechanisms readFromNetwork(connection, in, () -> sasl.getState() == PN_SASL_IDLE && sasl.getRemoteMechanisms().length == 0); for (SaslMechanismFactory factory : saslFactories) { if (Arrays.asList(sasl.getRemoteMechanisms()).contains(factory.getName())) { mechanism = factory.newInstance(callbackHandler, sharedState, options); if (mechanism != null) { sasl.setRemoteHostname(saslHostname); sasl.setMechanisms(factory.getName()); byte[] initialResponse = mechanism.getResponse(null); if (initialResponse != null && initialResponse.length != 0) { sasl.send(initialResponse, 0, initialResponse.length); } break; } } } if (mechanism == null) { throw new LoginException("Unable to authenticate using SASL delegation, no supported mechanisms"); } writeToNetwork(connection, out); return mechanism; }
sasl.setRemoteHostname(hostname); sasl.setListener(new SaslListener() {
sasl.setRemoteHostname(hostname); sasl.setListener(new SaslListener() {