Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 102 additions & 79 deletions c_glib/arrow-flight-glib/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,65 @@ gaflight_record_batch_stream_new(GArrowRecordBatchReader *reader,
}


typedef struct GAFlightServerCallContextPrivate_ {
arrow::flight::ServerCallContext *call_context;
} GAFlightServerCallContextPrivate;

enum {
PROP_CALL_CONTEXT = 1,
};

G_DEFINE_TYPE_WITH_PRIVATE(GAFlightServerCallContext,
gaflight_server_call_context,
G_TYPE_OBJECT)

#define GAFLIGHT_SERVER_CALL_CONTEXT_GET_PRIVATE(obj) \
static_cast<GAFlightServerCallContextPrivate *>( \
gaflight_server_call_context_get_instance_private( \
GAFLIGHT_SERVER_CALL_CONTEXT(obj)))

static void
gaflight_server_call_context_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GAFLIGHT_SERVER_CALL_CONTEXT_GET_PRIVATE(object);

switch (prop_id) {
case PROP_CALL_CONTEXT:
priv->call_context =
static_cast<arrow::flight::ServerCallContext *>(
g_value_get_pointer(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
gaflight_server_call_context_init(GAFlightServerCallContext *object)
{
}

static void
gaflight_server_call_context_class_init(GAFlightServerCallContextClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->set_property = gaflight_server_call_context_set_property;

GParamSpec *spec;
spec = g_param_spec_pointer("call-context",
"Call context",
"The raw arrow::flight::ServerCallContext",
static_cast<GParamFlags>(G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(gobject_class, PROP_CALL_CONTEXT, spec);
}


struct GAFlightServerAuthSenderPrivate {
arrow::flight::ServerAuthSender *sender;
};
Expand Down Expand Up @@ -507,15 +566,18 @@ namespace gaflight {
}

arrow::Status
Authenticate(arrow::flight::ServerAuthSender *sender,
Authenticate(const arrow::flight::ServerCallContext &context,
arrow::flight::ServerAuthSender *sender,
arrow::flight::ServerAuthReader *reader) override {
auto klass = GAFLIGHT_SERVER_CUSTOM_AUTH_HANDLER_GET_CLASS(handler_);
auto gsender = gaflight_server_auth_sender_new_raw(sender);
auto greader = gaflight_server_auth_reader_new_raw(reader);
auto gacontext = gaflight_server_call_context_new_raw(&context);
auto gasender = gaflight_server_auth_sender_new_raw(sender);
auto gareader = gaflight_server_auth_reader_new_raw(reader);
GError *error = nullptr;
klass->authenticate(handler_, gsender, greader, &error);
g_object_unref(greader);
g_object_unref(gsender);
klass->authenticate(handler_, gacontext, gasender, gareader, &error);
g_object_unref(gareader);
g_object_unref(gasender);
g_object_unref(gacontext);
if (error) {
return garrow_error_to_status(error,
arrow::StatusCode::Invalid,
Expand All @@ -527,14 +589,17 @@ namespace gaflight {
}

arrow::Status
IsValid(const std::string &token,
IsValid(const arrow::flight::ServerCallContext &context,
const std::string &token,
std::string *peer_identity) override {
auto klass = GAFLIGHT_SERVER_CUSTOM_AUTH_HANDLER_GET_CLASS(handler_);
auto gacontext = gaflight_server_call_context_new_raw(&context);
auto gtoken = g_bytes_new_static(token.data(), token.size());
GBytes *gpeer_identity = nullptr;
GError *error = nullptr;
klass->is_valid(handler_, gtoken, &gpeer_identity, &error);
klass->is_valid(handler_, gacontext, gtoken, &gpeer_identity, &error);
g_bytes_unref(gtoken);
g_object_unref(gacontext);
if (gpeer_identity) {
gsize gpeer_identity_size;
auto gpeer_identity_data = g_bytes_get_data(gpeer_identity,
Expand Down Expand Up @@ -580,6 +645,7 @@ gaflight_server_custom_auth_handler_class_init(
/**
* gaflight_server_custom_auth_handler_authenticate:
* @handler: A #GAFlightServerCustomAuthHandler.
* @context: A #GAFlightServerCallContext.
* @sender: A #GAFlightServerAuthSender.
* @reader: A #GAFlightServerAuthReader.
* @error: (nullable): Return location for a #GError or %NULL.
Expand All @@ -592,16 +658,20 @@ gaflight_server_custom_auth_handler_class_init(
void
gaflight_server_custom_auth_handler_authenticate(
GAFlightServerCustomAuthHandler *handler,
GAFlightServerCallContext *context,
GAFlightServerAuthSender *sender,
GAFlightServerAuthReader *reader,
GError **error)
{
auto flight_handler =
gaflight_server_auth_handler_get_raw(
GAFLIGHT_SERVER_AUTH_HANDLER(handler));
auto flight_context = gaflight_server_call_context_get_raw(context);
auto flight_sender = gaflight_server_auth_sender_get_raw(sender);
auto flight_reader = gaflight_server_auth_reader_get_raw(reader);
auto status = flight_handler->Authenticate(flight_sender, flight_reader);
auto status = flight_handler->Authenticate(*flight_context,
flight_sender,
flight_reader);
garrow::check(error,
status,
"[flight-server-custom-auth-handler][authenticate]");
Expand All @@ -610,6 +680,7 @@ gaflight_server_custom_auth_handler_authenticate(
/**
* gaflight_server_custom_auth_handler_is_valid:
* @handler: A #GAFlightServerCustomAuthHandler.
* @context: A #GAFlightServerCallContext.
* @token: The client token. May be the empty string if the client does not
* provide a token.
* @peer_identity: (out): The identity of the peer, if this authentication
Expand All @@ -623,6 +694,7 @@ gaflight_server_custom_auth_handler_authenticate(
void
gaflight_server_custom_auth_handler_is_valid(
GAFlightServerCustomAuthHandler *handler,
GAFlightServerCallContext *context,
GBytes *token,
GBytes **peer_identity,
GError **error)
Expand All @@ -632,9 +704,12 @@ gaflight_server_custom_auth_handler_is_valid(
GAFLIGHT_SERVER_AUTH_HANDLER(handler));
gsize token_size;
auto token_data = g_bytes_get_data(token, &token_size);
auto flight_context = gaflight_server_call_context_get_raw(context);
std::string flight_token(static_cast<const char *>(token_data), token_size);
std::string flight_peer_identity;
auto status = flight_handler->IsValid(flight_token, &flight_peer_identity);
auto status = flight_handler->IsValid(*flight_context,
flight_token,
&flight_peer_identity);
if (garrow::check(error,
status,
"[flight-server-custom-auth-handler]"
Expand Down Expand Up @@ -815,65 +890,6 @@ gaflight_server_options_new(GAFlightLocation *location)
}


typedef struct GAFlightServerCallContextPrivate_ {
arrow::flight::ServerCallContext *call_context;
} GAFlightServerCallContextPrivate;

enum {
PROP_CALL_CONTEXT = 1,
};

G_DEFINE_TYPE_WITH_PRIVATE(GAFlightServerCallContext,
gaflight_server_call_context,
G_TYPE_OBJECT)

#define GAFLIGHT_SERVER_CALL_CONTEXT_GET_PRIVATE(obj) \
static_cast<GAFlightServerCallContextPrivate *>( \
gaflight_server_call_context_get_instance_private( \
GAFLIGHT_SERVER_CALL_CONTEXT(obj)))

static void
gaflight_server_call_context_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GAFLIGHT_SERVER_CALL_CONTEXT_GET_PRIVATE(object);

switch (prop_id) {
case PROP_CALL_CONTEXT:
priv->call_context =
static_cast<arrow::flight::ServerCallContext *>(
g_value_get_pointer(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
gaflight_server_call_context_init(GAFlightServerCallContext *object)
{
}

static void
gaflight_server_call_context_class_init(GAFlightServerCallContextClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->set_property = gaflight_server_call_context_set_property;

GParamSpec *spec;
spec = g_param_spec_pointer("call-context",
"Call context",
"The raw arrow::flight::ServerCallContext",
static_cast<GParamFlags>(G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(gobject_class, PROP_CALL_CONTEXT, spec);
}


G_DEFINE_INTERFACE(GAFlightServable,
gaflight_servable,
G_TYPE_OBJECT)
Expand Down Expand Up @@ -1199,6 +1215,23 @@ gaflight_data_stream_get_raw(GAFlightDataStream *stream)
return priv->stream;
}

GAFlightServerCallContext *
gaflight_server_call_context_new_raw(
const arrow::flight::ServerCallContext *flight_call_context)
{
return GAFLIGHT_SERVER_CALL_CONTEXT(
g_object_new(GAFLIGHT_TYPE_SERVER_CALL_CONTEXT,
"call-context", flight_call_context,
NULL));
}

const arrow::flight::ServerCallContext *
gaflight_server_call_context_get_raw(GAFlightServerCallContext *call_context)
{
auto priv = GAFLIGHT_SERVER_CALL_CONTEXT_GET_PRIVATE(call_context);
return priv->call_context;
}

GAFlightServerAuthSender *
gaflight_server_auth_sender_new_raw(
arrow::flight::ServerAuthSender *flight_sender)
Expand Down Expand Up @@ -1247,16 +1280,6 @@ gaflight_server_options_get_raw(GAFlightServerOptions *options)
return &(priv->options);
}

GAFlightServerCallContext *
gaflight_server_call_context_new_raw(
const arrow::flight::ServerCallContext *call_context)
{
return GAFLIGHT_SERVER_CALL_CONTEXT(
g_object_new(GAFLIGHT_TYPE_SERVER_CALL_CONTEXT,
"call-context", call_context,
NULL));
}

arrow::flight::FlightServerBase *
gaflight_servable_get_raw(GAFlightServable *servable)
{
Expand Down
30 changes: 17 additions & 13 deletions c_glib/arrow-flight-glib/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ gaflight_record_batch_stream_new(GArrowRecordBatchReader *reader,
GArrowWriteOptions *options);


#define GAFLIGHT_TYPE_SERVER_CALL_CONTEXT \
(gaflight_server_call_context_get_type())
G_DECLARE_DERIVABLE_TYPE(GAFlightServerCallContext,
gaflight_server_call_context,
GAFLIGHT,
SERVER_CALL_CONTEXT,
GObject)
struct _GAFlightServerCallContextClass
{
GObjectClass parent_class;
};


#define GAFLIGHT_TYPE_SERVER_AUTH_SENDER \
(gaflight_server_auth_sender_get_type())
G_DECLARE_DERIVABLE_TYPE(GAFlightServerAuthSender,
Expand Down Expand Up @@ -124,10 +137,12 @@ struct _GAFlightServerCustomAuthHandlerClass
GAFlightServerAuthHandlerClass parent_class;

void (*authenticate)(GAFlightServerCustomAuthHandler *handler,
GAFlightServerCallContext *context,
GAFlightServerAuthSender *sender,
GAFlightServerAuthReader *reader,
GError **error);
void (*is_valid)(GAFlightServerCustomAuthHandler *handler,
GAFlightServerCallContext *context,
GBytes *token,
GBytes **peer_identity,
GError **error);
Expand All @@ -137,6 +152,7 @@ GARROW_AVAILABLE_IN_12_0
void
gaflight_server_custom_auth_handler_authenticate(
GAFlightServerCustomAuthHandler *handler,
GAFlightServerCallContext *context,
GAFlightServerAuthSender *sender,
GAFlightServerAuthReader *reader,
GError **error);
Expand All @@ -145,6 +161,7 @@ GARROW_AVAILABLE_IN_12_0
void
gaflight_server_custom_auth_handler_is_valid(
GAFlightServerCustomAuthHandler *handler,
GAFlightServerCallContext *context,
GBytes *token,
GBytes **peer_identity,
GError **error);
Expand All @@ -166,19 +183,6 @@ GAFlightServerOptions *
gaflight_server_options_new(GAFlightLocation *location);


#define GAFLIGHT_TYPE_SERVER_CALL_CONTEXT \
(gaflight_server_call_context_get_type())
G_DECLARE_DERIVABLE_TYPE(GAFlightServerCallContext,
gaflight_server_call_context,
GAFLIGHT,
SERVER_CALL_CONTEXT,
GObject)
struct _GAFlightServerCallContextClass
{
GObjectClass parent_class;
};


#define GAFLIGHT_TYPE_SERVABLE (gaflight_servable_get_type())
G_DECLARE_INTERFACE(GAFlightServable,
gaflight_servable,
Expand Down
10 changes: 6 additions & 4 deletions c_glib/arrow-flight-glib/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
arrow::flight::FlightDataStream *
gaflight_data_stream_get_raw(GAFlightDataStream *stream);

GAFlightServerCallContext *
gaflight_server_call_context_new_raw(
const arrow::flight::ServerCallContext *flight_call_context);
const arrow::flight::ServerCallContext *
gaflight_server_call_context_get_raw(GAFlightServerCallContext *call_context);

GAFlightServerAuthSender *
gaflight_server_auth_sender_new_raw(
arrow::flight::ServerAuthSender *flight_sender);
Expand All @@ -45,10 +51,6 @@ gaflight_server_auth_handler_get_raw(GAFlightServerAuthHandler *handler);
arrow::flight::FlightServerOptions *
gaflight_server_options_get_raw(GAFlightServerOptions *options);

GAFlightServerCallContext *
gaflight_server_call_context_new_raw(
const arrow::flight::ServerCallContext *flight_context);


struct _GAFlightServableInterface
{
Expand Down
4 changes: 2 additions & 2 deletions c_glib/test/helper/flight-server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class FlightAuthHandler < ArrowFlight::ServerCustomAuthHandler
type_register

private
def virtual_do_authenticate(sender, reader)
def virtual_do_authenticate(context, sender, reader)
true
end

def virtual_do_is_valid(token)
def virtual_do_is_valid(context, token)
"identity"
end
end
Expand Down
Loading