-
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
Assert WebSession is not null #14977
Conversation
getAuthorizedClients(WebSession session)
getAuthorizedClients(WebSession session)
getAuthorizedClients(WebSession session)
Hi @dukbong, thanks for the PR! Just a heads up, I closed the original issue with this explanation. I appreciate what you're doing in this change by asserting the session cannot be null. I'm wondering though if this change is absolutely necessary?
Can you explain the situation in which this would occur (other than the invalid configuration referred to in the original issue)? |
Hi @sjohnr Initially, I planned to submit a pull request to address the issue, but as I reviewed the code, I found the structure to be questionable, prompting a change in direction. The Based on these observations, I created a pull request to address the issue.
|
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.
Thanks for the PR @dukbong. In addition to the feedback inline below, can you please add a test that asserts an IllegalArgumentException
is thrown when WebSession
is null?
...work/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java
Outdated
Show resolved
Hide resolved
...work/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java
Show resolved
Hide resolved
...work/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java
Outdated
Show resolved
Hide resolved
...work/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.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.
Thanks @dukbong. I added one minor comment below. Can you also please rebase your changes on main and squash commits? I will schedule this to be merged in the next minor so you won't see it merged for a few weeks.
...work/security/oauth2/client/web/server/WebSessionServerOAuth2AuthorizedClientRepository.java
Show resolved
Hide resolved
refactory NPE message & checkStyle & newline Remove Write Test Code Change test case name from Empty to Null SuppressWarnings unchecked apply
Hello. @sjohnr As you suggested, I rebased onto the main branch and squashed the commits into one. If there's anything I did wrong or need to correct, please let me know! |
getAuthorizedClients(WebSession session)
Original Code:
The getAuthorizedClients method retrieves a map of OAuth2 authorized clients from a WebSession. In the original code, if the session is null, the method assigns a default empty HashMap. This code does not explicitly assert that WebSession cannot be null, potentially leading to silent failures or unexpected behavior.
Closes #14975
Suggested Refactoring:
To ensure robustness and improve error handling, you can refactor the method by adding an assertion to prevent a null session. This approach uses Assert.notNull to raise an exception with a clear error message if the WebSession is null, helping developers quickly identify and fix the problem.