You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generalize the httpAuthentication infrastructure and remove SPNEGO-specific design
Following the review feedback, this change updates the proposed SPNEGO-specific
implementation into a more generic authentication flow that can support various
HTTP authentication mechanisms.
Signed-off-by: raccoonback <[email protected]>
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
## Project Overview
6
+
7
+
Reactor-Netty is a reactive networking library providing non-blocking TCP/HTTP/UDP/QUIC clients and servers based on Netty. It's part of the Project Reactor ecosystem and requires Java 8+ to run.
8
+
9
+
## Build System
10
+
11
+
**Gradle-based** multi-module project using Gradle 8.14.2:
12
+
13
+
```bash
14
+
# Build and test
15
+
./gradlew build # Build all modules
16
+
./gradlew check # Run all checks including tests
17
+
./gradlew test# Run tests
18
+
./gradlew clean # Clean build artifacts
19
+
20
+
# Module-specific testing
21
+
./gradlew reactor-netty-core:test # Test core module
22
+
./gradlew reactor-netty-http:test # Test HTTP module
23
+
24
+
# Code quality
25
+
./gradlew spotlessCheck # Check code formatting
26
+
./gradlew spotlessApply # Apply code formatting
27
+
./gradlew checkstyle # Run checkstyle
28
+
29
+
# Documentation
30
+
./gradlew javadoc # Generate Javadoc
31
+
./gradlew antora # Build Antora documentation
32
+
33
+
# Publishing
34
+
./gradlew publishToMavenLocal # Publish to local Maven repository
<1> The timeout of each DNS query performed by this resolver will be 500ms.
745
745
746
-
[[http-client-spnego]]
747
-
== SPNEGO Authentication
748
-
Reactor Netty HttpClient supports SPNEGO (Kerberos) authentication, which is widely used in enterprise environments.
749
-
SPNEGO (Simple and Protected GSSAPI Negotiation Mechanism) provides secure authentication over HTTP using Kerberos.
746
+
[[http-authentication]]
747
+
== HTTP Authentication
748
+
Reactor Netty `HttpClient` provides a flexible HTTP authentication framework that allows you to implement
749
+
custom authentication mechanisms such as SPNEGO/Negotiate, OAuth, Bearer tokens, or any other HTTP-based authentication scheme.
750
750
751
-
==== How It Works
752
-
SPNEGO authentication follows this HTTP authentication flow:
751
+
The {javadoc}/reactor/netty/http/client/HttpClient.html#httpAuthentication-java.util.function.BiPredicate-java.util.function.BiFunction-[`httpAuthentication`]
752
+
method accepts two parameters:
753
753
754
-
. The client sends an HTTP request to a protected resource.
755
-
. The server responds with `401 Unauthorized` and a `WWW-Authenticate: Negotiate` header.
756
-
. The client generates a SPNEGO token based on its Kerberos ticket, and resends the request with an `Authorization: Negotiate <base64-encoded-token>` header.
757
-
. The server validates the token and, if authentication is successful, returns 200 OK.
758
-
759
-
If further negotiation is required, the server may return another 401 with additional data in the `WWW-Authenticate` header.
754
+
* A predicate that determines when authentication should be applied (typically by checking the HTTP status code and headers)
755
+
* An authenticator function that applies authentication credentials to the request
<1> Configures the `jaas.conf`. A JAAS configuration file in Java for integrating with authentication backends such as Kerberos.
767
-
<2> Configures the `krb5.conf`. krb5.conf is a Kerberos client configuration file used to define how the client locates and communicates with the Kerberos Key Distribution Center (KDC) for authentication.
768
-
<3> Configures the SPNEGO jaas.conf. A JVM system property that enables detailed debug logging for Kerberos operations in Java.
769
-
<4> `JaasAuthenticator` performs Kerberos authentication using a JAAS configuration (jaas.conf).
770
-
<5> `SpnegoAuthProvider.Builder` supports the following configuration methods. Please refer to <<spnegoauthprovider-config>>.
771
-
<6> `SpnegoAuthProvider` generates a SPNEGO token from the Kerberos ticket. It automatically adds the `Authorization: Negotiate ...` header to HTTP requests. If the server responds with `401 Unauthorized` and includes `WWW-Authenticate: Negotiate`, the client will automatically reauthenticate and retry the request once.
757
+
This approach gives you complete control over the authentication flow while Reactor Netty handles the retry mechanism.
772
758
773
-
===== Example JAAS Configuration
774
-
Specify the path to your JAAS configuration file using the `java.security.auth.login.config` system property.
<1> Obtain the `GSSCredential` through other means.
822
-
<2> Configure the GSSCredential-based authenticator for SPNEGO authentication.
778
+
<1> The predicate checks if the response status is `401 Unauthorized`.
779
+
<2> The authenticator adds the `Authorization` header with a Bearer token.
823
780
824
-
This approach is useful when:
825
-
- You want to reuse existing credentials
826
-
- You need more control over credential management
827
-
- JAAS configuration is not available or preferred
781
+
=== SPNEGO/Negotiate Authentication Example
828
782
829
-
==== Custom Authenticator Implementation
830
-
For advanced scenarios where the provided authenticators don't meet your specific requirements, you can implement the `SpnegoAuthenticator` interface directly:
783
+
For SPNEGO (Kerberos) authentication, you can implement a custom authenticator using Java's GSS-API:
<1> The predicate checks if the response status is `401 Unauthorized`.
824
+
<2> The authenticator adds Basic authentication credentials to the `Authorization` header.
861
825
862
-
This approach is useful when you need:
863
-
- Custom credential acquisition logic
864
-
- Integration with third-party authentication systems
865
-
- Special handling for token caching or refresh
866
-
- Environment-specific authentication flows
867
-
868
-
[[spnegoauthprovider-config]]
869
-
==== SpnegoAuthProvider Configuration Options
870
-
The `SpnegoAuthProvider.Builder` supports the following configuration Options:
871
-
872
-
[width="100%",options="header"]
873
-
|=======
874
-
| Method | Default | Description | Example
875
-
| `serviceName(String)` | "HTTP" | Service name for constructing service principal names (serviceName/hostname) | "HTTP", "LDAP"
876
-
| `unauthorizedStatusCode(int)` | 401 | HTTP status code that triggers authentication retry | 401, 407
877
-
| `resolveCanonicalHostname(boolean)` | false | Whether to use canonical hostname resolution via reverse DNS lookup | true for FQDN requirements
878
-
|=======
879
-
880
-
==== Notes
881
-
- SPNEGO authentication is fully supported on Java 1.6 and above.
882
-
- If authentication fails, check the server logs and client exception messages, and verify your Kerberos environment settings (realm, KDC, ticket, etc.).
883
-
- `JaasAuthenticator` performs authentication through JAAS login configuration.
0 commit comments