Search in sources :

Example 1 with FlightClient

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);
}
Also used : ClientIncomingAuthHeaderMiddleware(org.apache.arrow.flight.auth2.ClientIncomingAuthHeaderMiddleware) FlightClient(org.apache.arrow.flight.FlightClient) ClientBearerHeaderHandler(org.apache.arrow.flight.auth2.ClientBearerHeaderHandler) ClientCookieMiddleware(org.apache.arrow.flight.client.ClientCookieMiddleware) CredentialCallOption(org.apache.arrow.flight.grpc.CredentialCallOption)

Aggregations

FlightClient (org.apache.arrow.flight.FlightClient)1 ClientBearerHeaderHandler (org.apache.arrow.flight.auth2.ClientBearerHeaderHandler)1 ClientIncomingAuthHeaderMiddleware (org.apache.arrow.flight.auth2.ClientIncomingAuthHeaderMiddleware)1 ClientCookieMiddleware (org.apache.arrow.flight.client.ClientCookieMiddleware)1 CredentialCallOption (org.apache.arrow.flight.grpc.CredentialCallOption)1