use of io.vertx.proton.ProtonClient in project hono by eclipse.
the class ConnectionFactoryImplTest method testConnectDoesNotUseSaslPlainForEmptyUsernameAndPassword.
/**
* Verifies that the factory does not enable SASL_PLAIN if the username and password are empty
* strings.
*/
@Test
public void testConnectDoesNotUseSaslPlainForEmptyUsernameAndPassword() {
// GIVEN a factory configured to connect to a server
final ProtonClientOptions options = new ProtonClientOptions();
final ProtonClient client = mock(ProtonClient.class);
final ConnectionFactoryImpl factory = new ConnectionFactoryImpl(vertx, props);
factory.setProtonClient(client);
// WHEN connecting to the server using empty strings for username and password
factory.connect(options, "", "", null, null, c -> {
});
// THEN the factory does not enable the SASL_PLAIN mechanism when establishing
// the connection
final ArgumentCaptor<ProtonClientOptions> optionsCaptor = ArgumentCaptor.forClass(ProtonClientOptions.class);
verify(client).connect(optionsCaptor.capture(), anyString(), anyInt(), eq(""), eq(""), VertxMockSupport.anyHandler());
assertFalse(optionsCaptor.getValue().getEnabledSaslMechanisms().contains("PLAIN"));
}
use of io.vertx.proton.ProtonClient in project hono by eclipse.
the class ConnectionFactoryImplTest method testConnectEnablesSslIfExplicitlyConfigured.
/**
* Verifies that the factory uses TLS when connecting to the peer if no trust store
* is configured but TLS has been enabled explicitly.
*/
@Test
public void testConnectEnablesSslIfExplicitlyConfigured() {
// GIVEN a factory configured to connect to a server using TLS
final ClientConfigProperties config = new ClientConfigProperties();
config.setHost("remote.host");
config.setTlsEnabled(true);
final ProtonClient client = mock(ProtonClient.class);
final ConnectionFactoryImpl factory = new ConnectionFactoryImpl(vertx, config);
factory.setProtonClient(client);
// WHEN connecting to the server
factory.connect(null, null, null, c -> {
});
// THEN the factory uses TLS when establishing the connection
final ArgumentCaptor<ProtonClientOptions> optionsCaptor = ArgumentCaptor.forClass(ProtonClientOptions.class);
verify(client).connect(optionsCaptor.capture(), eq("remote.host"), anyInt(), any(), any(), VertxMockSupport.anyHandler());
assertTrue(optionsCaptor.getValue().isSsl());
}
use of io.vertx.proton.ProtonClient in project hono by eclipse.
the class AmqpCliClient method connectToAdapter.
/**
* Connects to the AMQP org.eclipse.hono.cli.app.adapter.
*
* @return A future containing the established connection. The future will
* be succeeded once the connection is open.
*/
protected Future<ProtonConnection> connectToAdapter() {
final Promise<ProtonConnection> connectAttempt = Promise.promise();
final ProtonClientOptions options = new ProtonClientOptions();
final ProtonClient client = ProtonClient.create(vertx);
options.setConnectTimeout(properties.getConnectTimeout());
options.setHeartbeat(properties.getHeartbeatInterval());
options.setMaxFrameSize(properties.getMaxFrameSize());
Optional.ofNullable(properties.getAmqpHostname()).ifPresent(s -> options.setVirtualHost(s));
addTlsTrustOptions(options, properties);
if (!Strings.isNullOrEmpty(properties.getUsername()) && !Strings.isNullOrEmpty(properties.getPassword())) {
// SASL PLAIN auth
options.addEnabledSaslMechanism(ProtonSaslPlainImpl.MECH_NAME);
log.info("connecting to AMQP org.eclipse.hono.cli.app.adapter using SASL PLAIN [host: {}, port: {}, username: {}]", properties.getHost(), properties.getPort(), properties.getUsername());
client.connect(options, properties.getHost(), properties.getPort(), properties.getUsername(), properties.getPassword(), connectAttempt);
} else {
if (properties.getKeyCertOptions() != null && properties.getTrustOptions() != null) {
// SASL EXTERNAL auth
options.setKeyCertOptions(properties.getKeyCertOptions());
} else {
// SASL ANONYMOUS auth
}
log.info("connecting to AMQP org.eclipse.hono.cli.app.adapter [host: {}, port: {}]", properties.getHost(), properties.getPort());
client.connect(options, properties.getHost(), properties.getPort(), connectAttempt);
}
return connectAttempt.future().compose(unopenedConnection -> {
final Promise<ProtonConnection> con = Promise.promise();
unopenedConnection.openHandler(con);
unopenedConnection.open();
return con.future();
});
}
use of io.vertx.proton.ProtonClient in project hono by eclipse.
the class AmqpAdapterTestBase method connectToAdapter.
/**
* Connects to the AMQP protocol adapter using a username and password.
*
* @param tlsVersion The TLS protocol version to use for connecting to the adapter.
* @param cipherSuite The TLS cipher suite to use for connecting to the adapter or {@code null} if the
* cipher suite should not be restricted.
* @param username The username to use for authentication.
* @param password The password to use for authentication.
* @return A succeeded future containing the established connection.
*/
protected Future<ProtonConnection> connectToAdapter(final String tlsVersion, final String cipherSuite, final String username, final String password) {
final Promise<ProtonConnection> result = Promise.promise();
final ProtonClient client = ProtonClient.create(vertx);
final ProtonClientOptions options = new ProtonClientOptions(defaultOptions);
options.addEnabledSaslMechanism(ProtonSaslPlainImpl.MECH_NAME);
options.setEnabledSecureTransportProtocols(Set.of(tlsVersion));
Optional.ofNullable(cipherSuite).ifPresent(options::addEnabledCipherSuite);
client.connect(options, IntegrationTestSupport.AMQP_HOST, IntegrationTestSupport.AMQPS_PORT, username, password, result);
return result.future().compose(con -> handleConnectAttempt(con, IntegrationTestSupport.AMQP_HOST));
}
use of io.vertx.proton.ProtonClient in project hono by eclipse.
the class AmqpAdapterTestBase method connectToAdapter.
/**
* Connects to the AMQP protocol adapter using a client certificate.
*
* @param hostname The name of the host to connect to.
* @param clientCertificate The certificate to use for authentication.
* @param tlsProtocolVersion The TLS protocol version to use for connecting to the host.
* @return A succeeded future containing the established connection.
* @throws NullPointerException if any of the parameters are {@code null}.
*/
protected Future<ProtonConnection> connectToAdapter(final String hostname, final SelfSignedCertificate clientCertificate, final String tlsProtocolVersion) {
Objects.requireNonNull(hostname);
Objects.requireNonNull(clientCertificate);
Objects.requireNonNull(tlsProtocolVersion);
final Promise<ProtonConnection> result = Promise.promise();
final ProtonClient client = ProtonClient.create(vertx);
final ProtonClientOptions secureOptions = new ProtonClientOptions(defaultOptions);
secureOptions.setKeyCertOptions(clientCertificate.keyCertOptions());
secureOptions.addEnabledSaslMechanism(ProtonSaslExternalImpl.MECH_NAME);
secureOptions.setEnabledSecureTransportProtocols(Set.of(tlsProtocolVersion));
client.connect(secureOptions, hostname, IntegrationTestSupport.AMQPS_PORT, result);
return result.future().compose(con -> handleConnectAttempt(con, hostname));
}
Aggregations