-
Notifications
You must be signed in to change notification settings - Fork 92
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
Remove equals & hashcode based on JWT, KafkaPrincipal ones will be in effect #60
Conversation
Signed-off-by: Michele Tibaldi <[email protected]>
54de20b
to
46a0d16
Compare
Can you add some tests that the |
You should also look at the spotbugs - it looks like you should have some equals imeplementation there.
|
Thanks for the headup about spotbug, i will also try to arrange a the test. There's a thing i would like to point out, in any case: If you have time, i suggest you to take a look at it, the behaviour of the oauth plugin, while seemingly fine from what i have experienced so far (apart the equality stuff), probably needs some checks and it should also be pointed out in the documentation the relevancy of specifying |
I'm a bit lost on the test. I see that there are in place test with various providers as integration/system tests. I'm afraid testing the effects of the equals implementation is really entangled with Kafka internals that are beyond my possibility of digging out. Also i'm not familiar with spotbugs, i tried mvn spotbugs:check to replicate Travis error, but to no avail. Is it the correct command? I changed the equals/hashcode to:
But that's really silly, and any other meaningful check on the JWT itself seems redundant with what's already in place on the |
I'm not sure if @mstruk has any ideas. But I think you should add. simple Unit test which would show that twoprincipals which should equal return true and two principals which should not equal should return false. |
@uwburn Thank you for a very valuable analysis. We had some discussion around equals() / hashCode() on initial PR of authz support with @tombentley and the intuitively safe no-op implementation like you suggested as silly was deemed as such back then. It wasn't quite clear to me at the time how this is used and where it might cause problems - e.g. is it or will it be one day used in a HashMap in what should it mean exactly ... It's clear now that the extra payload of jwt field should not be included in the equals() evaluation, and thus the safest approach really is for super.equals() to be used in case they add some relevant extra information. Another approach for the future is to store JWT completely separately from the principal object - into a cache. The override with just delegation to super has a benefit of telling everyone that we didn't forget about thinking about equals() and hashCode(), and that's the intent of the spotbugs - although it's very easy to brainlessly add it as a routine, and it does look a bit silly by itself. On the other hand if we just suppress the warning that also means that we had to think about it at least a little bit, so it's the same. I'd say we just remove equals() and hashCode(), add the warning suppresion annotation on the class, and add a comment that we delegate equals() / and hashCode() to super on purpose. We don't really have unit tests, just the integration tests. I'd have to think some more where exactly to put the test, let me look at that some more. |
Signed-off-by: Marko Strukelj <[email protected]>
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 added the test. See: uwburn#1
Add test for the JwtKafkaPrincipal equals() and hashCode()
@tombentley Could you have a look at this please if you have a minute? |
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
/** | ||
* This class uses the KafkaPrincipal object to store additional info obtained at sesion authentication time, |
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 class uses the KafkaPrincipal object to store additional info obtained at sesion authentication time, | |
* This class uses the KafkaPrincipal object to store additional info obtained at session authentication time, |
* | ||
* Any additional fields should not be included in equals / hashcode check. If they are, that will break re-authentication. | ||
*/ | ||
@SuppressFBWarnings("EQ_DOESNT_OVERRIDE_EQUALS") | ||
public class JwtKafkaPrincipal extends KafkaPrincipal { |
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 don't ever expect this class to be subclassed, but I guess if it were the subclass could override equals()/hashCode()
, breaking this contract. So I suppose we should either make this class final
, or do it as originally with overridden (but final
) equals()/hashCode()
delegating to super
.
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.
Seems like an overkill to me, but sure, we can make the class final
.
Not that it should be treated like a contract with third party devs that might get an impression that it's a good idea to extend our classes, and think that we won't one day completely change them. Everything in terms of classes, methods, and configuration that we don't explicitly document should be treated as an implementation detail that can change at any time.
This final
should only be considered a failsafe for a contributor to this project, to save them from inadvertently re-introducing the bug.
Signed-off-by: Marko Strukelj <[email protected]>
Make JwtKafkaPrincipal final + fix typo as suggested in strimzi#60
Sorry for the delay, i was away from home. |
Signed-off-by: Marko Strukelj <[email protected]>
…cation (#64) * Remove equals & hashcode based on JWT, KafkaPrincipal ones will apply Signed-off-by: Michele Tibaldi <[email protected]> * Add test for the JwtKafkaPrincipal equals() and hashCode() Signed-off-by: Marko Strukelj <[email protected]> * Make JwtKafkaPrincipal final + fix typo as suggested in #60 Signed-off-by: Marko Strukelj <[email protected]> Co-authored-by: Michele Tibaldi <[email protected]>
No description provided.