gnodet-bot commented on code in PR #2372:
URL: https://github.com/apache/maven-resolver/pull/2372#discussion_r4728642885
##########
maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationContext.java:
##########
@@ -70,6 +70,16 @@ public final class AuthenticationContext implements
Closeable {
*/
public static final String PASSWORD = "password";
+ /**
+ * The key used to store the bearer token. The corresponding
authentication data should be of type {@code char[]}
+ * or {@link String}. HTTP transports (except Wagon) send it preemptively
as {@code Authorization: Bearer <token>}
+ * header, scoped to the repository origin, and when present, it takes
precedence over {@link #USERNAME} and
+ * {@link #PASSWORD}.
+ *
+ * @since 2.0.27
+ */
+ public static final String BEARER_TOKEN = "bearerToken";
Review Comment:
🔍 **Nit — naming inconsistency:** The key value `"bearerToken"` (camelCase)
doesn't follow the dotted-namespace convention used by all other multi-word
keys in this class:
| Constant | Value |
|---|---|
| `NTLM_DOMAIN` | `"ntlm.domain"` |
| `PRIVATE_KEY_PATH` | `"privateKey.path"` |
| `SSL_CONTEXT` | `"ssl.context"` |
| `SSL_HOSTNAME_VERIFIER` | `"ssl.hostnameVerifier"` |
Not blocking — users should reference the `BEARER_TOKEN` constant, not the
string value directly. But `"bearer.token"` would match the existing convention.
```suggestion
public static final String BEARER_TOKEN = "bearer.token";
```
##########
maven-resolver-transport-jdk-parent/maven-resolver-transport-jdk11/src/main/java/org/eclipse/aether/transport/jdk/JdkTransporter.java:
##########
@@ -237,6 +235,14 @@ static boolean isExpectContinueSupported(Runtime.Version
version) {
if (configuredHeaders != null) {
headers.putAll(configuredHeaders);
}
+ String bearerToken;
+ try (AuthenticationContext repoAuthContext =
AuthenticationContext.forRepository(session, repository)) {
+ bearerToken = repoAuthContext != null ?
repoAuthContext.get(AuthenticationContext.BEARER_TOKEN) : null;
+ }
Review Comment:
🔍 **Minor inefficiency — `AuthenticationContext` opened twice:** This new
`try (AuthenticationContext …)` block opens and decrypts credentials here in
the constructor, then `createClient()` (called at the end of the same
constructor) opens it a second time for SSL context and username/password. All
three other transports (Apache, Jetty, URL) open it only once.
Consider passing `bearerToken` into `createClient()` and opening the context
a single time there — it already receives `bearerToken != null` as a `boolean`.
This would avoid decrypting secrets twice per transporter instance creation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]