Skip to content

Quality: OAuth service cache key ignores callback port, reusing wrong service instance#801

Open
Nam0101 wants to merge 2 commits intonroduit:masterfrom
Nam0101:contribai/improve/quality/oauth-service-cache-key-ignores-callback
Open

Quality: OAuth service cache key ignores callback port, reusing wrong service instance#801
Nam0101 wants to merge 2 commits intonroduit:masterfrom
Nam0101:contribai/improve/quality/oauth-service-cache-key-ignores-callback

Conversation

@Nam0101
Copy link
Copy Markdown

@Nam0101 Nam0101 commented Mar 30, 2026

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:
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.

Proposed fix:
Include port in the cache key (or stop caching by UID alone). For example: change map to Map<String, OAuth20Service> with key authMethod.getUid() + ":" + port, or introduce a key record: private record ServiceKey(String uid, int port) {} and private 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

Nam0101 added 2 commits March 31, 2026 01:05
…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>
@nroduit
Copy link
Copy Markdown
Owner

nroduit commented Mar 31, 2026

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: oauth service cache key ignores callback port, reusing wrong service instance

2 participants