cstamas opened a new pull request, #2372:
URL: https://github.com/apache/maven-resolver/pull/2372

   Adds bearer token authentication. `AuthenticationBuilder` gets 
`addBearerToken(String)` and `addBearerToken(char[])`, and the Apache, JDK, 
Jetty and URL transports send the token as `Authorization: Bearer <token>`.
   
   ### API
   
   - **`AuthenticationContext.BEARER_TOKEN`**: new key (`"bearerToken"`), 
`char[]` or `String`, like `PASSWORD`.
   - **`AuthenticationBuilder#addBearerToken`**: stores the token through 
`addSecret`. It is kept scrambled in memory, prints as `bearerToken=***`, and 
is part of the authentication digest, the same as passwords.
   
   ### Transport behavior
   
   All four HTTP transports follow the same rules, and the shared 
`HttpTransporterTest` checks them on each one:
   
   - **Always preemptive:** the token is sent on every request, without waiting 
for a 401. Some servers answer 404 instead of a challenge to unauthenticated 
requests.
   - **Precedence:** a bearer token takes precedence over username/password and 
over a configured `Authorization` header, in any letter case.
   - **Kept on the origin:** the token is never sent to a cross-origin redirect 
target (scheme, host and port), **even when `HTTP_ORIGIN_SCOPED_HEADERS` is 
disabled**. It is authentication, not a configured header. In detail:
     - **Apache:** `OriginScopedHeadersInterceptor` is also installed when 
origin scoping is off, stripping only `Authorization`.
     - **JDK:** with a token set, the transporter always follows redirects 
itself (`Redirect.NEVER`) and drops `Authorization` on cross-origin hops. It 
does not rely on the JDK client.
     - **Jetty:** `OriginScopedHeadersListener` is also installed when origin 
scoping is off.
     - **URL:** the 401 retry with credentials is never done against another 
origin when a token is set.
   
   **Not affected:** Wagon, and Minio, which signs its own `Authorization` 
header for S3. Proxy authentication stays username/password only.
   
   ### Tests
   
   `HttpServer#setBearerAuthentication` added; new tests in 
`HttpTransporterTest`:
   
   - `testGet_BearerAuthenticated`: token only, one request.
   - `testGet_BearerTakesPrecedenceOverBasic`: username/password plus a 
lowercase `authorization` configured header; only the bearer token is accepted.
   - `testGet_BearerUnauthenticated`: a wrong token gets a 401.
   - `testGet_Redirect_BearerNotReplayed` and 
`testGet_Redirect_BearerNotReplayedWhenOriginScopedHeadersDisabled`: a 
cross-origin redirect does not get the token.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [ ] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
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]

Reply via email to