-
Notifications
You must be signed in to change notification settings - Fork 56
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
MQTT topics with path parameters required to match guarded identity #1387
base: develop
Are you sure you want to change the base?
Conversation
...tt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/config/MqttPublishConfigBuilder.java
Outdated
Show resolved
Hide resolved
...tt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/config/MqttPublishConfigBuilder.java
Outdated
Show resolved
Hide resolved
...tt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/config/MqttPublishConfigBuilder.java
Show resolved
Hide resolved
.../src/main/java/io/aklivity/zilla/runtime/binding/mqtt/config/MqttSubscribeConfigBuilder.java
Outdated
Show resolved
Hide resolved
...a/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionConfigAdapterTest.java
Outdated
Show resolved
Hide resolved
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.
We often test via spec scripts to verify implementation behavior instead of tightly coupled unit tests.
The intent is to be able to refactor the code, but still have stable tests to verify new implementation. Tightly coupled tests are typically forced to change when the code is refactored, preventing the stable basis to verify consistency.
Let's discuss further over Slack community as needed on this feedback.
.../java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionConfigAdapter.java
Outdated
Show resolved
Hide resolved
.../java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionConfigAdapter.java
Outdated
Show resolved
Hide resolved
.../java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionConfigAdapter.java
Show resolved
Hide resolved
@@ -39,7 +39,7 @@ public MqttRouteConfig( | |||
this.id = route.id; | |||
this.when = route.when.stream() | |||
.map(MqttConditionConfig.class::cast) | |||
.map(MqttConditionMatcher::new) | |||
.map(conf -> new MqttConditionMatcher(conf, route.guarded)) |
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.
.map(conf -> new MqttConditionMatcher(conf, route.guarded)) | |
.map(c -> new MqttConditionMatcher(this, c)) |
So you can use route.identity(guard, authorization)
from MqttConditionMatcher
constructor (see below).
Add Map<String, LongFunction<String>> identities
private field and populate in constructor.
Add String identity(String guard, long authorization)
to MqttRouteConfig
.
String identity(
String guard,
long authorization)
{
return identities.getOrDefault(guard, a -> null).apply(authorization);
}
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.
Done, thanks!
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.
I am reopening this because this caused a bug while I was applying the last suggestions to the PR:
When we pass this
to the MqttConditionMatcher
constructor, it receives an instance of MqttRouteConfig
that is not completely initialized yet. This might produce unexpected behaviour when accessing uninitialized MqttRouteConfig
fields inside the MqttConditionMatcher
constructor.
In this specific case, the MqttConditionMatcher
constructor calls the route.identity()
method, but the route.identities
field is not yet initialized at this time, and this produces a NullPointerException.
To solve this I moved the when
field initialization at the bottom of the MqttRouteConfig
constructor, so that all the other fields are initialized when calling the MqttConditionMatcher
constructor with this
as an input. But this still feels kind of wierd, so maybe it is better to pass the route.identities
field to the MqttConditionMatcher
constructor, rather than the whole MqttRouteConfig
object which is not fully initialized? 🤔
Let me know!
2f9095f
to
d15893e
Compare
.../java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionConfigAdapter.java
Outdated
Show resolved
Hide resolved
.../java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionConfigAdapter.java
Outdated
Show resolved
Hide resolved
...c/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionMatcher.java
Outdated
Show resolved
Hide resolved
...c/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionMatcher.java
Outdated
Show resolved
Hide resolved
...c/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionMatcher.java
Outdated
Show resolved
Hide resolved
...c/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttConditionMatcher.java
Outdated
Show resolved
Hide resolved
...tt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/config/MqttRouteConfig.java
Outdated
Show resolved
Hide resolved
b9738b8
to
084e920
Compare
084e920
to
d0c53ea
Compare
d0c53ea
to
d526962
Compare
The goal of this PR is to allow secure access to some MQTT client specific topics for publish and/or subscribe.
For
publish
orsubscribe
routes:jwt
guard)Example configuration:
Fixes #1382