Fix GrantedAuthority.authority null in AuthoritiesAuthorizationManager#18544
Fix GrantedAuthority.authority null in AuthoritiesAuthorizationManager#18544rwinch merged 2 commits intospring-projects:6.5.xfrom
Conversation
02aea40 to
616ab45
Compare
|
|
||
| private boolean isAuthorized(Authentication authentication, Collection<String> authorities) { | ||
| for (GrantedAuthority grantedAuthority : getGrantedAuthorities(authentication)) { | ||
| if (grantedAuthority == null) { |
There was a problem hiding this comment.
It's not about the grantedAuthority itself, but the result of grantedAuthority.getAuthority() can be null.
I don't think that getGrantedAuthorities may contain a null itself, so the check should be:
if (grantedAuthority.getAuthority() == null) { continue; }
There was a problem hiding this comment.
Thank you for the sharp feedback. You're right—it wasn't the grantedAuthority object itself, but the null return value of getAuthority() that caused the NPE.
I've updated the logic to check grantedAuthority.getAuthority() == null as you suggested. Additionally, I've refactored the test case to use a lambda-based GrantedAuthority that returns null, ensuring the issue is accurately reproduced without unnecessary Mockito mocks. Everything is verified with a successful local build. Please take another look
420a217 to
18a38a8
Compare
ffray
left a comment
There was a problem hiding this comment.
👍 Thanks for this fix. Let's see if it gets merged.
This prevents NPE when GrantedAuthority.getAuthority() returns null. Closes spring-projectsgh-18543 Signed-off-by: Khyojae <khjae201@gmail.com>
- Fix checkstyle - Fix the test to use Collection that throws NullPointerException on .contains(null) to replicate the reported issue Closes spring-projectsgh-18544 Signed-off-by: Robert Winch <362503+rwinch@users.noreply.github.com>
|
Thanks for the PR! I've:
|
|
This is now merged into 6.5.x, 7.0.x, and main. Thanks again for the PR! |
Check if GrantedAuthority is null before accessing it in
isAuthorized method to prevent NullPointerException.
Closes gh-18543
Signed-off-by: Khyojae khjae201@gmail.com