-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed mqtt connection expired behavior #3529
Changed mqtt connection expired behavior #3529
Conversation
mattkaem
commented
Aug 10, 2023
- Changed the exception in case a mqtt connection is expired to an AuthorizationException to have the correct error code in the error message to the device, if it subscribes the error topic (500 -> 401).
- Extended the list of terminal errors for mqtt and amqp messages with unauthorized error.
Sonatype Lift is retiringSonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems to address a bug in the MQTT adapter, right? If so, could you please add a corresponding issue and refer to it in the commit message?
@@ -859,6 +859,7 @@ The error message's *code* field may contain the following HTTP status codes: | |||
| Code | Description | | |||
| :---- | :---------- | | |||
| *400* | Bad Request, the request cannot be processed. A possible reason for this is an invalid *PUBLISH* topic. | | |||
| *401* | Unauthorized, the device connection is not authorized (e.g. the connection expired). | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it the credentials (token) that expire?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you are right. I changed it.
@@ -1318,7 +1319,7 @@ private boolean disconnectOnExpired() { | |||
|
|||
private Future<Void> checkExpiration(final MqttContext context) { | |||
if (context.authenticatedDevice() != null && context.authenticatedDevice().expired()) { | |||
return Future.failedFuture(new MqttConnectionException(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED)); | |||
return Future.failedFuture(new AuthorizationException(context.tenant(), "Connection expired.", null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Credentials/Token expired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
@@ -1062,6 +1062,7 @@ public static ConnectionAttemptOutcome getOutcome(final Throwable e) { | |||
* <li>The adapter is disabled for the tenant that the client belongs to.</li> | |||
* <li>The authenticated device or gateway is disabled or not registered.</li> | |||
* <li>The tenant is disabled or does not exist.</li> | |||
* <li>The authenticated device is not authorized anymore (e.g. the connection expired).</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
credentials/token expired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
@@ -1310,6 +1310,7 @@ private Future<Void> checkTopic(final MqttContext context) { | |||
|
|||
private boolean disconnectOnExpired() { | |||
if (authenticatedDevice != null && authenticatedDevice.expired()) { | |||
log.debug("Connection with device {} has expired - Disconnecting device.", authenticatedDevice.getDeviceId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Credentials/Token has expired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
* Changed the exception that is used in case a mqtt device tries to send a message with expired credentials to an AuthorizationException to have the correct error code in the error message to the device. * Extended the list of terminal errors for mqtt and amqp messages with unauthorized error. Signed-off-by: Matthias Kaemmer <[email protected]>
5f71a1d
to
f8ffa97
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Can you please also merge this fix to the 2.3.x branch? I have added the issue to the 2.3.2 board already ...