@FloLi additional question about authentication and topic permissions (continuation of Store massages in MsSQL)
currently in onConnect
I’m using below code to set permissions per user:
final ArrayList<TopicPermission> topicPermissions = new ArrayList<>();
for (String deviceId: user.get().getDevices()) {
final TopicPermission publishPermission = Builders.topicPermission()
.topicFilter(deviceId+"/settings")
.activity(TopicPermission.MqttActivity.PUBLISH)
.type(TopicPermission.PermissionType.ALLOW)
.build();
topicPermissions.add(publishPermission);
final TopicPermission subscribePermission = Builders.topicPermission()
.topicFilter(deviceId+"/values")
.activity(TopicPermission.MqttActivity.SUBSCRIBE)
.type(TopicPermission.PermissionType.ALLOW)
.build();
topicPermissions.add(subscribePermission);
}
output.getDefaultPermissions().addAll(topicPermissions);
output.getDefaultPermissions().setDefaultBehaviour(DefaultAuthorizationBehaviour.DENY);
output.authenticateSuccessfully();
this works great in basic scenario, but I want to add support for subscribing to +/values
topic.
Idea is that when user1 subscribes to that topic he will only get messages from devices 1,2 and 3 (because he owns them).
In the linked response you showed that this can be done in authorizeSubscribe
, but can I set topic permissions in onConnect
? This way user could subscribe to get values from all devices and the broker would handle sending values from device to correct user.
This would be an awesome feature to have!