use of org.apache.arrow.flight.FlightClient in project arrow-flight-client-examples by dremio-hub.
the class AdhocFlightClient method getClientHelper.
private static AdhocFlightClient getClientHelper(BufferAllocator allocator, String host, int port, String user, String pass, String patOrAuthToken, HeaderCallOption clientProperties, FlightClient.Builder builder) {
if (Strings.isNullOrEmpty(patOrAuthToken) && Strings.isNullOrEmpty(pass)) {
throw new IllegalArgumentException("No authentication method chosen.");
}
if (!Strings.isNullOrEmpty(pass) && Strings.isNullOrEmpty(user)) {
throw new IllegalArgumentException("Username must be defined for password authentication.");
}
if (!Strings.isNullOrEmpty(patOrAuthToken) && !Strings.isNullOrEmpty(pass)) {
throw new IllegalArgumentException("Provide exactly one of: [pass, patOrAuthToken]");
}
final ClientCookieMiddleware.Factory cookieFactory = new ClientCookieMiddleware.Factory();
builder.allocator(allocator).intercept(cookieFactory);
ClientIncomingAuthHeaderMiddleware.Factory authHeaderFactory = null;
if (!Strings.isNullOrEmpty(pass)) {
// Create a new instance of ClientIncomingAuthHeaderMiddleware.Factory. This factory creates
// new instances of ClientIncomingAuthHeaderMiddleware. The middleware processes
// username/password and bearer token authorization header authentication for this Flight Client.
authHeaderFactory = new ClientIncomingAuthHeaderMiddleware.Factory(new ClientBearerHeaderHandler());
// Adds ClientIncomingAuthHeaderMiddleware.Factory instance to the FlightClient builder.
builder.intercept(authHeaderFactory);
}
final FlightClient flightClient = builder.build();
final CredentialCallOption credentials;
if (!Strings.isNullOrEmpty(patOrAuthToken)) {
credentials = authenticatePatOrAuthToken(flightClient, patOrAuthToken, clientProperties);
} else {
credentials = authenticateUsernamePassword(flightClient, user, pass, authHeaderFactory, clientProperties);
}
return new AdhocFlightClient(flightClient, allocator, credentials);
}
Aggregations