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
SPNEGO authentication follows this HTTP authentication flow:
753
-
1. The client sends an HTTP request to a protected resource.
754
-
2. The server responds with `401 Unauthorized` and a `WWW-Authenticate: Negotiate` header.
755
-
3. The client generates a SPNEGO token based on its Kerberos ticket, and resends the request with an `Authorization: Negotiate <base64-encoded-token>` header.
756
-
4. The server validates the token and, if authentication is successful, returns 200 OK.
757
753
758
-
If further negotiation is required, the server may return another 401 with additional data in the WWW-Authenticate header.
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.
759
758
760
-
{examples-link}/spnego/Application.java
759
+
If further negotiation is required, the server may return another 401 with additional data in the `WWW-Authenticate` header.
<1> Configures the `jaas.conf`. A JAAS configuration file in Java for integrating with authentication backends such as Kerberos.
765
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.
766
768
<3> Configures the SPNEGO jaas.conf. A JVM system property that enables detailed debug logging for Kerberos operations in Java.
767
769
<4> `JaasAuthenticator` performs Kerberos authentication using a JAAS configuration (jaas.conf).
768
-
<5> `SpnegoAuthProvider` generates a SPNEGO token from the Kerberos ticket and 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.
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.
769
772
770
-
==== Environment Configuration
771
773
===== Example JAAS Configuration
772
774
Specify the path to your JAAS configuration file using the `java.security.auth.login.config` system property.
773
775
@@ -809,6 +811,75 @@ Specify Kerberos realm and KDC information using the `java.security.krb5.conf` s
809
811
-Djava.security.krb5.conf=/path/to/krb5.conf
810
812
----
811
813
814
+
==== GSSCredential-based Authenticator
815
+
For scenarios where you already have a `GSSCredential` available or want to avoid JAAS configuration, you can use `GssCredentialAuthenticator`:
<1> Obtain the `GSSCredential` through other means.
822
+
<2> Configure the GSSCredential-based authenticator for SPNEGO authentication.
823
+
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
828
+
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:
.unauthorizedStatusCode(401) // Custom status code
857
+
.resolveCanonicalHostname(true) // Use canonical hostname
858
+
.build()
859
+
);
860
+
----
861
+
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
+
812
880
==== Notes
813
881
- SPNEGO authentication is fully supported on Java 1.6 and above.
814
-
- If authentication fails, check the server logs and client exception messages, and verify your Kerberos environment settings (realm, KDC, ticket, etc.).
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.
Copy file name to clipboardExpand all lines: reactor-netty-examples/src/main/java/reactor/netty/examples/documentation/http/client/spnego/jaas/Application.java
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@
13
13
* See the License for the specific language governing permissions and
0 commit comments