-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[fix][broker] Fix MultiRoles token provider NPE when using anonymous clients #21429
Conversation
Codecov Report
@@ Coverage Diff @@
## master #21429 +/- ##
=============================================
+ Coverage 30.15% 73.26% +43.10%
- Complexity 324 32575 +32251
=============================================
Files 1709 1888 +179
Lines 130685 140292 +9607
Branches 14245 15417 +1172
=============================================
+ Hits 39414 102781 +63367
+ Misses 85327 29424 -55903
- Partials 5944 8087 +2143
Flags with carried forward coverage won't be shown. Click here to find out more.
|
relates to #21338 |
@@ -71,4 +71,8 @@ public boolean hasSubscription() { | |||
public String getSubscription() { | |||
return subscription; | |||
} | |||
|
|||
public AuthenticationDataSource getAuthData() { |
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.
Why not you check the authData in the constructor or override methods?
@Override
public boolean hasDataFromTls() {
return authData != null && authData.hasDataFromTls();
}
We should avoid type checking.
(authData instanceof AuthenticationDataSubscription && ((AuthenticationDataSubscription) authData).getAuthData() == 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.
But the getRoles method will return empty
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 have communicated with @Technoboy- T offline. I don't suggest that add getAuthData()
method, and makes the code difficult to maintain.
The following are my ideas:
-
idea 1
Add a newAuthenticationDataSource
for the anonymous role, and then check theauthData
type. -
idea 2
Change theorg.apache.pulsar.broker.authorization.MultiRolesTokenAuthorizationProvider#getRoles
logic to quickly returnrole
whenrole
equals anonymous role:
private Set<String> getRoles(String role, AuthenticationDataSource authData) {
if (authData == null || role.equals(conf.getAnonymousUserRole())) {
return Collections.singleton(role);
}
There will be a pitfall here, if the client role is equal to the anonymous role, the real roles cannot be obtained from authData
.
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.
idea 1
is more pretty, I will create a issue to track this.
Motivation
Modification
Documentation
doc
doc-required
doc-not-needed
doc-complete