Skip to content

Add trust-only SSL HttpClient to oltu-jdk21 to prevent OAuth2 client-cert dual-auth - #1398

Open
YasasRangika wants to merge 4 commits into
wso2:masterfrom
YasasRangika:yasas-master
Open

Add trust-only SSL HttpClient to oltu-jdk21 to prevent OAuth2 client-cert dual-auth#1398
YasasRangika wants to merge 4 commits into
wso2:masterfrom
YasasRangika:yasas-master

Conversation

@YasasRangika

Copy link
Copy Markdown
Contributor

Description

Outbound OAuth2/OIDC token calls made via Oltu's stock URLConnectionClient use the JVM's default SSLContext/SSLSocketFactory, with no explicit client identity. If the JVM-wide default happens to carry a client certificate (e.g. because some other component in the process set javax.net.ssl.keyStore* and something touched SSLContext.getDefault() before it did), that certificate gets presented on the connection even though the caller only intends to authenticate via client_secret. Some identity providers reject this as an invalid dual client-authentication attempt (invalid_request, The client MUST NOT use more than one authentication method).

This adds org.wso2.carbon.oltu.sslTrustOnlyURLConnectionClient (an Oltu HttpClient SPI implementation) and TrustOnlySslUtils — which apply a trust-only (no client KeyManager) SSLSocketFactory scoped to a single connection. Consumers opt in by using TrustOnlyURLConnectionClient instead of the stock URLConnectionClient; nothing about the existing org.apache.oltu.oauth2.client.URLConnectionClient class or any other upstream class changes, so this has no effect on any existing consumer that doesn't explicitly adopt it.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c61a71b-7a83-4764-bb9b-f35104b1958b

📥 Commits

Reviewing files that changed from the base of the PR and between d2c80fb and 48ea4dd.

📒 Files selected for processing (2)
  • oltu-jdk21/1.0.0.wso2v2/pom.xml
  • oltu-jdk21/1.0.0.wso2v2/src/main/java/org/wso2/carbon/oltu/ssl/TrustOnlyURLConnectionClient.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oltu-jdk21/1.0.0.wso2v2/pom.xml
  • oltu-jdk21/1.0.0.wso2v2/src/main/java/org/wso2/carbon/oltu/ssl/TrustOnlyURLConnectionClient.java

📝 Walkthrough

Summary

  • Added the oltu-jdk21 Maven bundle with Apache OLTU dependencies and package metadata.
  • Added TrustOnlySslUtils for per-connection HTTPS configuration.
  • Added opt-in TrustOnlyURLConnectionClient for OAuth request execution.
  • Added support for headers, request methods, request bodies, error responses, timeouts, and OAuth response creation.

Walkthrough

Added the oltu-jdk21 Maven bundle with optional Apache OLTU dependencies and OSGi package metadata. Added TrustOnlySslUtils for cached, trust-only TLS contexts applied per HTTPS connection. Added TrustOnlyURLConnectionClient for OAuth requests with configurable methods, headers, bodies, response handling, exception translation, and no-op shutdown.

Sequence Diagram(s)

sequenceDiagram
  participant OAuthCaller
  participant TrustOnlyURLConnectionClient
  participant TrustOnlySslUtils
  participant OAuthEndpoint
  OAuthCaller->>TrustOnlyURLConnectionClient: execute OAuth request
  TrustOnlyURLConnectionClient->>TrustOnlySslUtils: apply trust-only SSL for HTTPS
  TrustOnlyURLConnectionClient->>OAuthEndpoint: send request
  OAuthEndpoint-->>TrustOnlyURLConnectionClient: return response stream
  TrustOnlyURLConnectionClient-->>OAuthCaller: return OAuthClientResponse
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem and solution but omits most required template sections, including goals, tests, security checks, release note, documentation, and migration details. Complete the required template sections and mark non-applicable items as N/A with brief explanations.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states that the PR adds a trust-only SSL HTTP client to prevent unintended OAuth2 client-certificate dual authentication.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
oltu-jdk21/1.0.0.wso2v2/pom.xml (2)

110-116: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add an explicit compiler release setting.

The module declares no maven.compiler.release (or source/target). The produced bytecode level then depends on the local JDK and the inherited default. For a module named oltu-jdk21, set the level explicitly to keep builds reproducible.

♻️ Proposed change
     <properties>
+        <maven.compiler.release>21</maven.compiler.release>
         <oltu.version>1.0.0</oltu.version>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oltu-jdk21/1.0.0.wso2v2/pom.xml` around lines 110 - 116, Update the Maven
properties in the module POM to define an explicit maven.compiler.release value
of 21, ensuring ol​​tu-jdk21 consistently produces Java 21 bytecode regardless
of the build environment.

81-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Upgrade maven-bundle-plugin to a JDK 21-compatible version.

oltu-jdk21 builds as a bundle but still pins org.apache.felix:maven-bundle-plugin:1.4.0; the JDK 21 tomcat-el-api-jdk21 modules use 5.1.2 or 2.4.0. A newer bundle plugin is required to avoid parsing JDK 21 bytecode during packaging.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oltu-jdk21/1.0.0.wso2v2/pom.xml` around lines 81 - 85, Update the
maven-bundle-plugin configuration in the Maven build to use a JDK 21-compatible
newer version, matching the established compatible version used by the
tomcat-el-api-jdk21 modules where appropriate, and replace the outdated 1.4.0
declaration.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oltu-jdk21/1.0.0.wso2v2/src/main/java/org/wso2/carbon/oltu/ssl/TrustOnlyURLConnectionClient.java`:
- Around line 62-70: Update TrustOnlyURLConnectionClient’s connection setup to
apply configurable connect and read timeouts before connect() is invoked, using
sensible defaults that prevent indefinite blocking. Preserve the existing
URLConnectionClient behavior and HTTPS trust handling, and expose timeout
configuration through the constructor if required for parity and caller opt-in.
- Around line 118-125: Update the request-body writing logic in
TrustOnlyURLConnectionClient to use an OutputStreamWriter with
StandardCharsets.UTF_8 instead of the platform-default
PrintWriter(OutputStream), and wrap the writer in try-with-resources so it is
always closed. Preserve the existing POST/PUT behavior and requestBody output.
- Around line 93-100: In the response handling around responseCode and
inputStream, guard the nullable result of httpURLConnection.getErrorStream() for
SC_BAD_REQUEST and SC_UNAUTHORIZED before passing it to
OAuthUtils.saveStreamAsString. Preserve normal input-stream processing and
ensure responses without an error body produce an appropriate empty or fallback
response body instead of invoking the helper with null.

---

Nitpick comments:
In `@oltu-jdk21/1.0.0.wso2v2/pom.xml`:
- Around line 110-116: Update the Maven properties in the module POM to define
an explicit maven.compiler.release value of 21, ensuring ol​​tu-jdk21
consistently produces Java 21 bytecode regardless of the build environment.
- Around line 81-85: Update the maven-bundle-plugin configuration in the Maven
build to use a JDK 21-compatible newer version, matching the established
compatible version used by the tomcat-el-api-jdk21 modules where appropriate,
and replace the outdated 1.4.0 declaration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ec8658c7-ed29-4261-863a-f8b91258d0da

📥 Commits

Reviewing files that changed from the base of the PR and between be54088 and b6dc178.

📒 Files selected for processing (3)
  • oltu-jdk21/1.0.0.wso2v2/pom.xml
  • oltu-jdk21/1.0.0.wso2v2/src/main/java/org/wso2/carbon/oltu/ssl/TrustOnlySslUtils.java
  • oltu-jdk21/1.0.0.wso2v2/src/main/java/org/wso2/carbon/oltu/ssl/TrustOnlyURLConnectionClient.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oltu-jdk21/1.0.0.wso2v2/src/main/java/org/wso2/carbon/oltu/ssl/TrustOnlyURLConnectionClient.java`:
- Around line 65-69: Update the TrustOnlyURLConnectionClient constructor to
validate connectTimeoutMillis and readTimeoutMillis before assigning them,
rejecting negative values immediately while preserving zero if it represents the
supported infinite-timeout behavior. Ensure invalid arguments fail during
construction rather than when execute() configures the URLConnection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d9c1a62-fe15-4a77-a205-6ebec11a51ed

📥 Commits

Reviewing files that changed from the base of the PR and between b6dc178 and d2c80fb.

📒 Files selected for processing (2)
  • oltu-jdk21/1.0.0.wso2v2/pom.xml
  • oltu-jdk21/1.0.0.wso2v2/src/main/java/org/wso2/carbon/oltu/ssl/TrustOnlyURLConnectionClient.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oltu-jdk21/1.0.0.wso2v2/pom.xml

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.

1 participant