use of org.eclipse.hono.adapter.auth.device.AuthHandler in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testUnauthenticatedConnectionMetrics.
/**
* Verifies the connection metrics for unauthenticated connections.
* <p>
* This test should check if the metrics receive a call to increment and decrement when a connection is being
* established and then closed.
*/
@Test
public void testUnauthenticatedConnectionMetrics() {
properties.setAuthenticationRequired(false);
givenAnAdapter(properties);
final MqttEndpoint endpoint = mockEndpoint();
adapter.handleEndpointConnection(endpoint);
// THEN the adapter does not try to authenticate the device
verify(authHandler, never()).authenticateDevice(any(MqttConnectContext.class));
// and increments the number of unauthenticated connections
verify(metrics).incrementUnauthenticatedConnections();
// and when the device closes the connection
final ArgumentCaptor<Handler<Void>> closeHandlerCaptor = VertxMockSupport.argumentCaptorHandler();
verify(endpoint, times(2)).closeHandler(closeHandlerCaptor.capture());
closeHandlerCaptor.getValue().handle(null);
// the number of unauthenticated connections is decremented again
verify(metrics).decrementUnauthenticatedConnections();
}
use of org.eclipse.hono.adapter.auth.device.AuthHandler in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapter method doStart.
@Override
protected final void doStart(final Promise<Void> startPromise) {
registerDeviceAndTenantChangeNotificationConsumers();
log.info("limiting size of inbound message payload to {} bytes", getConfig().getMaxPayloadSize());
if (!getConfig().isAuthenticationRequired()) {
log.warn("authentication of devices turned off");
}
final ConnectionLimitManager connectionLimitManager = Optional.ofNullable(getConnectionLimitManager()).orElseGet(this::createConnectionLimitManager);
setConnectionLimitManager(connectionLimitManager);
checkPortConfiguration().compose(ok -> CompositeFuture.all(bindSecureMqttServer(), bindInsecureMqttServer())).compose(ok -> {
if (authHandler == null) {
authHandler = createAuthHandler();
}
return Future.succeededFuture((Void) null);
}).onComplete(startPromise);
}
Aggregations