[JENKINS-60200] Clear user team and organization caches on fresh OAuth logins #171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Per: https://issues.jenkins.io/browse/JENKINS-60200
Sometimes the 1-hour cache of teams and organizations can cause issues. In particular, it causes problems when you have SSO turned on for an organization and the person logging in needs to remember to authorize SSO for a given organization and forgets.
The user story is this:

I log into a Jenkins with team-level permissions in my SSO enabled organization. I see this screen:
and I forget to click the
Authorize
button. I then get permission denied. I then click logout to try and fix that, but when I come back in after authorizing my organization; I still get permission denied because of the cache.This PR invalidate the cache on fresh logins. This both solves the reported issue, and allows a user to have an active way to refresh their personal cache of teams and organizations by logging out and logging in while leaving caching in place for token flows and session accesses for performance and to minimize GitHub API calls.
Notes: I didn't see a logout hook in the Security Realm or I'd prefer to clear the caches there instead of during the fresh OAuth flow. If someone with more expertise knows how to hook there, I'm happy to move the user cache clearing to that hook.