-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
NimbusJwtDecoder
should remove its setters in favor of its builders
#13366
Comments
Hi @ThomasKasene, I don't think returning
I did not check the code, but you are right, sometimes we have to make the exact change in multiple places. That said, if you are willing to add a |
Thanks for your response! I absolutely recognize that this is different from how things have traditionally been done (hence the "controversial" disclaimer at the top 😄 ). But I saw #13266 and figured, since usability improvements is already such a big thing, maybe it's worth enabling an arguably more modern programming style too. Anyway, take it or leave it - I can still add a |
Hi @ThomasKasene, sorry for the delay. From my point of view, I see no issue with adding additional methods to the builders (and duplicating some code when necessary). However, I have not had much impact on the Having said that, I don't think it makes sense to simply start adding chainability to setters, as this would potentially set a precedent that should be discussed more thoroughly, and further may not be desired at all. I think for consistency, focusing on the builder pattern and enhancing builders would be the preferred route. If adding Regarding gh-13266, we're quite early days on that and we want to be strategic in approaching big changes. I think it's awesome to get suggestions like this though, as these conversations are great for gathering feedback and ideas! |
The setters are a primary way for XML-based applications to get configured. While quite old-school, Spring Security still supports that, which means, at least for the time being, that the setters should stay there. Further, changing to Regarding a new builder method, we also don't want to introduce multiple ways to do the same thing for the sake of satisfying stylistic preferences. While I recognize that adding Possibly in 7, we could make the constructor package-private, change it to take a @ThomasKasene, would you be okay with changing your issue title to be "NimbusJwtDecoder should remove its setters in favor of its builders" and describe the needed changes? Then we can schedule it for 7 and see if enough folks vote for it. |
@jzheaux I could do that if you think it's okay to repurpose this issue, or I can submit a new one with a more narrow scope so you can close this one if you want (the But what changes are you referring to? It seems like you got most of the required changes in your reply 😄 Or do you mean listing them in even more detail than that? |
this
from commonly used setter methods instead of void
NimbusJwtDecoder
should remove its setters in favor of its builders
This is perhaps a little controversial, but I've sometimes wondered about the possibility of converting some of the more commonly used setters to return
this
rather thanvoid
.Case in point, I recently wanted to be able to do something like this:
But I was thwarted by the limitations of the
JwkSetUriReactiveJwtDecoderBuilder
not allowing me to specify ajwtValidator
, so I had to resort to an ugly detour via a variable:For a little while I was considering submitting a PR to add
jwtValidator(...)
to the builder, but soon realized that this class contains 4 such builders, and I'd have to duplicate the functionality between them all (and then double that for the non-reactive variant.)An option, which I believe is becoming more and more common, is to enable developers to chain setters by returning
this
. If thesetJwtValidator(...)
method I used above returned theNimbusReactiveJwtDecoder
instance, I could at the very least get a compromise going:It should be backwards compatible, and as an added benefit, the validation that already exists within
setJwtValidator(...)
will be applied so we wouldn't have to duplicate that as well.This is just one example, but it's a common theme perhaps especially in Spring Security.
Thanks for listening to my TED talk! 😄
The text was updated successfully, but these errors were encountered: