Use user guid for token cache#1642
Merged
Merged
Conversation
18a9c4e to
059979c
Compare
|
|
||
| /** | ||
| * Returns a client for the specified user name and space id by either getting it from the clients cache or creating a new one. | ||
| * Returns a client for the specified username and space id by either getting it from the clients cache or creating a new one. |
Contributor
There was a problem hiding this comment.
maybe rename to "specified user guid"? as the username will be removed soon?
|
|
||
| <include file="/org/cloudfoundry/multiapps/controller/persistence/db/changelog/db-changelog-1.183.0-persistence.xml"/> | ||
|
|
||
| <include file="/org/cloudfoundry/multiapps/controller/persistence/db/changelog/db-changelog-1.191.0-persistence.xml"/> |
Contributor
There was a problem hiding this comment.
reminder: align with the latest release
| public static String determineCurrentUserGuid(VariableScope scope) { | ||
| String userGuid = VariableHandling.get(scope, Variables.USER_GUID); | ||
| if (userGuid == null) { | ||
| throw new SLException(Messages.CANT_DETERMINE_CURRENT_USER_GUID); |
Contributor
There was a problem hiding this comment.
is it possible not to have the user guid?
what will happen with the running processes during the blue green deploy service update?
will this variable be set?
059979c to
151359d
Compare
IvanBorislavovDimitrov
previously approved these changes
Jun 2, 2025
| 3, | ||
| 30, | ||
| TimeUnit.SECONDS, | ||
| private final ExecutorService threadPoolForTokensDeletion = new ThreadPoolExecutor(1, 3, 30, TimeUnit.SECONDS, |
Contributor
There was a problem hiding this comment.
Magic numbers can be extracted (not mandatory)
| OAuth2AccessTokenWithAdditionalInfo cachedAccessToken = cachedTokens.get(username); | ||
| if (shouldUseCachedToken(cachedAccessToken)) { | ||
| return cachedAccessToken; | ||
| public OAuth2AccessTokenWithAdditionalInfo getToken(String username, String userGuid) { |
Contributor
There was a problem hiding this comment.
Code suggestion:
if (userGuid != null) {
OAuth2AccessTokenWithAdditionalInfo cached = cachedTokens.get(userGuid);
if (shouldUseCachedToken(cached)) {
return cached;
}
List<AccessToken> tokensByGuid = getSortedAccessTokensByUserGuid(userGuid);
if (!tokensByGuid.isEmpty()) {
return cacheAndReturnLatest(tokensByGuid);
}
}
List<AccessToken> tokensByUsername = getSortedAccessTokensByUsername(username);
if (tokensByUsername.isEmpty()) {
throw new IllegalStateException(MessageFormat.format(Messages.NO_VALID_TOKEN_FOUND, userGuid));
}
return cacheAndReturnLatest(tokensByUsername);
}
private OAuth2AccessTokenWithAdditionalInfo cacheAndReturnLatest(List<AccessToken> tokens) {
OAuth2AccessTokenWithAdditionalInfo latest = getLatestToken(tokens);
String userId = (String) latest.getAdditionalInfo().get(TokenProperties.USER_ID_KEY);
cachedTokens.put(userId, latest);
if (tokens.size() > 1) {
deleteTokens(tokens.subList(1, tokens.size()));
}
return latest;
}
s-yonkov-yonkov
approved these changes
Jun 5, 2025
IvanBorislavovDimitrov
approved these changes
Jun 5, 2025
JIRA:LMCROSSITXSADEPLOY-3207
c300edb to
968cad0
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


JIRA:LMCROSSITXSADEPLOY-3207
Description:
Issue: