Skip to content

feat(java/driver/flight-sql): add OAuth2 support#4290

Open
lxyzxx wants to merge 1 commit intoapache:mainfrom
lxyzxx:java-OAuth2
Open

feat(java/driver/flight-sql): add OAuth2 support#4290
lxyzxx wants to merge 1 commit intoapache:mainfrom
lxyzxx:java-OAuth2

Conversation

@lxyzxx
Copy link
Copy Markdown
Contributor

@lxyzxx lxyzxx commented May 2, 2026

This change follows the earlier discussion in #4272.

Now that Arrow Java 19.0.0 has been merged, Java ADBC Flight SQL can reuse the OAuth2 support already implemented in Arrow Java. This commit wires that existing Arrow Java OAuth2 implementation into the Java ADBC Flight SQL driver, instead of introducing a separate OAuth implementation on the ADBC side.

What changed

  • add OAuth2 support for Java ADBC Flight SQL
  • support client_credentials
  • support token_exchange
  • align exposed OAuth parameter semantics with Arrow Java
  • preserve driver-thrown AdbcException status codes during connection setup
  • close FlightClient on failed authentication / handshake paths
  • add regression coverage for OAuth configuration validation
  • add HTTPS token endpoint coverage using JVM trustStore semantics

Usage notes

For client_credentials, configure:

  • adbc.flight.sql.oauth.flow
  • adbc.flight.sql.oauth.token_uri
  • adbc.flight.sql.oauth.client_id
  • adbc.flight.sql.oauth.client_secret

For token_exchange, use the corresponding adbc.flight.sql.oauth.exchange.* properties.

OAuth token endpoint HTTPS validation follows the Arrow Java / JVM SSL behavior and uses the JVM SSL configuration, such as:

  • javax.net.ssl.trustStore
  • javax.net.ssl.trustStorePassword
  • javax.net.ssl.trustStoreType

Flight server TLS continues to use the existing ADBC Flight SQL TLS connection properties.

Token refresh / re-acquisition is delegated to the reused Arrow Java OAuth provider and happens on demand when a valid token is needed for a request.

Validation

  • added / updated OAuth regression tests
  • manually verified client_credentials against a local Keycloak setup
  • verified token acquisition and successful Flight SQL connection
  • verified token re-acquisition after expiry on subsequent requests

@lxyzxx lxyzxx requested a review from lidavidm as a code owner May 2, 2026 06:25
Copy link
Copy Markdown
Contributor

@xborder xborder left a comment

Choose a reason for hiding this comment

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

I think arrow-java has all the primitives required to implement this. If we can leave most of the resposabilities to arrow-java, it would be great.
It already knows how to create the configurations, client creation, managing oauth.

Maybe ArrowFlightSqlClientHandler.Builder is too focused on JDBC so it could be worth decoupling it a bit


import org.checkerframework.checker.nullness.qual.Nullable;

public enum OAuthFlowType {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nimbus already had this in its API. Maybe we could add nimbus as a dependency and use GrantType.CLIENT_CREDENTIALS/GrantType.TOKEN_EXCHANGE instead of creating our own


package org.apache.arrow.adbc.driver.flightsql.oauth;

public enum OAuthTokenType {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarly to GrantType comment, we can use nimbusds TokenTypeURI

Comment on lines +282 to +307
String authorizationHeader = null;
String username = null;
String password = null;
String oauthFlow = null;
if (parameters != null) {
for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
if (parameter.getKey().startsWith(FlightSqlConnectionProperties.RPC_CALL_HEADER_PREFIX)) {
String userHeaderName =
parameter
.getKey()
.substring(FlightSqlConnectionProperties.RPC_CALL_HEADER_PREFIX.length());

if (parameter.getValue() instanceof String) {
callHeaders.insert(userHeaderName, (String) parameter.getValue());
} else if (parameter.getValue() instanceof byte[]) {
callHeaders.insert(userHeaderName, (byte[]) parameter.getValue());
} else {
throw new AdbcException(
String.format(
"Header values must be String or byte[]. The header failing was %s.",
parameter.getKey()),
null,
AdbcStatusCode.INVALID_ARGUMENT,
null,
0);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we use ArrowFlightSqlClientHandler.Builder to create the flight client with all the configurations?
I think it would simplify the configuration, creating and managing the flight client

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.

2 participants