Quality: OAuth service cache key ignores callback port, reusing wrong service instance#801
Open
Nam0101 wants to merge 2 commits intonroduit:masterfrom
Conversation
…g service instance `services` is keyed only by `authMethod.getUid()`, but `createOAuth20Service(authMethod, port)` depends on `port` (used for localhost callback URL). If the port changes (config change, different runtime context), `computeIfAbsent` returns an old service bound to the previous port, causing OAuth callback mismatches and authentication failures. Affected files: OAuth2ServiceFactory.java, VectorUtils.java Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
…g service instance `services` is keyed only by `authMethod.getUid()`, but `createOAuth20Service(authMethod, port)` depends on `port` (used for localhost callback URL). If the port changes (config change, different runtime context), `computeIfAbsent` returns an old service bound to the previous port, causing OAuth callback mismatches and authentication failures. Affected files: OAuth2ServiceFactory.java, VectorUtils.java Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
Owner
|
Thank you for reporting this! There was a significant refactoring in this part of the code since the last release, so we haven't had a chance to test these changes yet. Testing is planned for the next few weeks as part of the upcoming 4.7 release. Please let us know if you find any other issues! |
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.
Hi there! 👋
While exploring the codebase, I noticed a minor opportunity for improvement in
weasis-core/src/main/java/org/weasis/core/api/net/auth/OAuth2ServiceFactory.java.Context:
servicesis keyed only byauthMethod.getUid(), butcreateOAuth20Service(authMethod, port)depends onport(used for localhost callback URL). If the port changes (config change, different runtime context),computeIfAbsentreturns an old service bound to the previous port, causing OAuth callback mismatches and authentication failures.Proposed fix:
Include
portin the cache key (or stop caching by UID alone). For example: change map toMap<String, OAuth20Service>with keyauthMethod.getUid() + ":" + port, or introduce a key record:private record ServiceKey(String uid, int port) {}andprivate static final Map<ServiceKey, OAuth20Service> services = new ConcurrentHashMap<>();then:return services.computeIfAbsent(new ServiceKey(authMethod.getUid(), port), k -> createOAuth20Service(authMethod, port));Files changed:
weasis-core/src/main/java/org/weasis/core/api/net/auth/OAuth2ServiceFactory.java(modified)weasis-dicom/weasis-dicom-codec/src/main/java/org/weasis/dicom/codec/geometry/VectorUtils.java(modified)(Note: Tested the changes locally to ensure everything works as expected. Let me know if you need any adjustments, happy to help!)
——
NamNV
📍 Hanoi, Vietnam
📧 nam.nv205106@gmail.com
Closes #800