Skip to content

Commit 4f473e8

Browse files
committed
WL14711: Support OCI IAM authentication
1 parent d5d0ee3 commit 4f473e8

10 files changed

+271
-68
lines changed

cppconn/connection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@
132132
#define OPT_READ_DEFAULT_GROUP "readDefaultGroup"
133133
#define OPT_READ_DEFAULT_FILE "readDefaultFile"
134134

135+
/*
136+
Auth plugin options
137+
*/
138+
#define OPT_OCI_CONFIG_FILE "OPT_OCI_CONFIG_FILE"
139+
135140

136141
namespace sql
137142
{

driver/mysql_connection.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,21 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
925925
proxy->options(MYSQL_OPT_SSL_MODE, &ssl_mode_val);
926926

927927
#endif
928+
} else if (!it->first.compare(OPT_OCI_CONFIG_FILE)) {
929+
try {
930+
p_s= (it->second).get<sql::SQLString>();
931+
} catch (sql::InvalidArgumentException&) {
932+
throw sql::InvalidArgumentException("Wrong type passed for OPT_OCI_CONFIG_FILE. Expected sql::SQLString.");
933+
}
928934

935+
try {
936+
proxy->plugin_option(MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
937+
"authentication_oci_client",
938+
"oci-config-file",
939+
*p_s);
940+
} catch (sql::InvalidArgumentException &e) {
941+
throw ::sql::SQLUnsupportedOptionException(e.what(), OPT_OCI_CONFIG_FILE);
942+
}
929943

930944
/* If you need to add new integer connection option that should result in
931945
calling mysql_optiong - add its mapping to the intOptions array

driver/nativeapi/libmysql_dynamic_proxy.cpp

Lines changed: 125 additions & 68 deletions
Large diffs are not rendered by default.

driver/nativeapi/libmysql_dynamic_proxy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ class LibmysqlDynamicProxy : public sql::mysql::util::LibraryLoader, public IMyS
123123

124124
int get_option (MYSQL *, enum mysql_option, const void *) override;
125125

126+
st_mysql_client_plugin* client_find_plugin(MYSQL *, const char *plugin_name, int plugin_type) override;
127+
128+
int plugin_options(st_mysql_client_plugin*, const char *option, const void *value) override;
129+
130+
int plugin_get_option(st_mysql_client_plugin*, const char *option, void *value) override;
131+
126132
int ping(MYSQL *) override;
127133

128134
int query(MYSQL *, const char *) override;

driver/nativeapi/libmysql_static_proxy.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,48 @@ LibmysqlStaticProxy::get_option(MYSQL * mysql, enum mysql_option option, const v
338338
/* }}} */
339339

340340

341+
/* {{{ LibmysqlStaticProxy::client_find_plugin() */
342+
st_mysql_client_plugin*
343+
LibmysqlStaticProxy::client_find_plugin(MYSQL *mysql, const char *plugin_name, int plugin_type)
344+
{
345+
auto *plugin = ::mysql_client_find_plugin(mysql, plugin_name, plugin_type);
346+
if(!plugin)
347+
{
348+
std::string err("Couldn't load plugin ");
349+
err+=plugin_name;
350+
throw sql::MethodNotImplementedException(err);
351+
}
352+
return plugin;
353+
}
354+
/* }}} */
355+
356+
357+
/* {{{ LibmysqlStaticProxy::plugin_options() */
358+
int
359+
LibmysqlStaticProxy::plugin_options(st_mysql_client_plugin *plugin, const char *option, const void *value)
360+
{
361+
if (::mysql_plugin_options(plugin, option, value)) {
362+
throw sql::InvalidArgumentException("Unsupported option provided to mysql_plugin_options()");
363+
} else {
364+
return 0;
365+
}
366+
}
367+
/* }}} */
368+
369+
370+
/* {{{ LibmysqlStaticProxy::plugin_get_option() */
371+
int
372+
LibmysqlStaticProxy::plugin_get_option(st_mysql_client_plugin *plugin, const char *option, void *value)
373+
{
374+
if (::mysql_plugin_get_option(plugin, option, value)) {
375+
throw sql::InvalidArgumentException("Unsupported option provided to mysql_plugin_get_option()");
376+
} else {
377+
return 0;
378+
}
379+
}
380+
/* }}} */
381+
382+
341383
/* {{{ LibmysqlStaticProxy::query() */
342384
int
343385
LibmysqlStaticProxy::query(MYSQL * mysql, const char *stmt_str)

driver/nativeapi/libmysql_static_proxy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ class LibmysqlStaticProxy : public IMySQLCAPI, public ::sql::mysql::util::Single
140140

141141
int get_option(MYSQL *, enum mysql_option, const void *) override;
142142

143+
st_mysql_client_plugin* client_find_plugin(MYSQL *, const char *plugin_name, int plugin_type) override;
144+
145+
int plugin_options(st_mysql_client_plugin*, const char *option, const void *value) override;
146+
147+
int plugin_get_option(st_mysql_client_plugin*, const char *option, void *value) override;
148+
143149
int ping(MYSQL *) override;
144150

145151
int query(MYSQL *, const char *) override;

driver/nativeapi/mysql_client_api.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ typedef int (STDCALL *ptr2mysql_options4)(MYSQL *, enum mysql_option, const void
103103

104104
typedef int (STDCALL *ptr2mysql_get_option)(MYSQL *, enum mysql_option, const void *);
105105

106+
typedef st_mysql_client_plugin* (*ptr2mysql_client_find_plugin)(MYSQL *, const char *, int);
107+
108+
typedef int (*ptr2mysql_plugin_options)(st_mysql_client_plugin*, const char *, const void *);
109+
110+
typedef int (*ptr2mysql_plugin_get_option)(st_mysql_client_plugin*, const char *, void *);
111+
106112
typedef int (STDCALL *ptr2mysql_query)(MYSQL *, const char *);
107113

108114
typedef int (STDCALL *ptr2mysql_ping)(MYSQL *);
@@ -242,6 +248,12 @@ class IMySQLCAPI
242248

243249
virtual int get_option(MYSQL *, enum mysql_option option , const void *arg) = 0;
244250

251+
virtual st_mysql_client_plugin* client_find_plugin(MYSQL *, const char *plugin_name, int plugin_type) = 0;
252+
253+
virtual int plugin_options(st_mysql_client_plugin*, const char *option, const void *value) = 0;
254+
255+
virtual int plugin_get_option(st_mysql_client_plugin*, const char *option, void *value) =0;
256+
245257
virtual int ping(MYSQL *) = 0;
246258

247259
virtual int query(MYSQL *, const char *) = 0;

driver/nativeapi/mysql_native_connection_wrapper.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,46 @@ MySQL_NativeConnectionWrapper::get_option(::sql::mysql::MySQL_Connection_Options
412412
}
413413
/* }}} */
414414

415+
int
416+
MySQL_NativeConnectionWrapper::plugin_option(
417+
int plugin_type,
418+
const ::sql::SQLString & plugin_name,
419+
const ::sql::SQLString & option,
420+
const ::sql::SQLString & value)
421+
try{
422+
423+
/* load client authentication plugin if required */
424+
struct st_mysql_client_plugin *plugin =
425+
api->client_find_plugin(mysql, plugin_name.c_str(), plugin_type);
426+
427+
/* set option value in plugin */
428+
return api->plugin_options(plugin, option.c_str(), value.c_str());
429+
430+
}
431+
catch(sql::InvalidArgumentException &e)
432+
{
433+
std::string err(e.what());
434+
err+= " for plugin " + plugin_name;
435+
throw sql::InvalidArgumentException(err);
436+
}
437+
438+
int MySQL_NativeConnectionWrapper::get_plugin_option(
439+
int plugin_type,
440+
const ::sql::SQLString & plugin_name,
441+
const ::sql::SQLString & option,
442+
const ::sql::SQLString & value)
443+
{
444+
445+
446+
/* load client authentication plugin if required */
447+
struct st_mysql_client_plugin *plugin =
448+
api->client_find_plugin(mysql, plugin_name.c_str(),
449+
plugin_type);
450+
451+
/* get option value from plugin */
452+
return api->plugin_get_option(plugin, option.c_str(), (void*)value.c_str());
453+
}
454+
415455

416456
/* {{{ MySQL_NativeConnectionWrapper::has_query_attributes() */
417457
bool MySQL_NativeConnectionWrapper::has_query_attributes()

driver/nativeapi/mysql_native_connection_wrapper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ struct st_mysql* mysql;
136136
int get_option(::sql::mysql::MySQL_Connection_Options, const bool &) override;
137137
int get_option(::sql::mysql::MySQL_Connection_Options, const int &) override;
138138

139+
int plugin_option(int plugin_type,
140+
const ::sql::SQLString & plugin_name,
141+
const ::sql::SQLString & option,
142+
const ::sql::SQLString & value) override;
143+
144+
int get_plugin_option(int plugin_type,
145+
const ::sql::SQLString & plugin_name,
146+
const ::sql::SQLString & option,
147+
const ::sql::SQLString & value) override;
148+
139149
bool has_query_attributes() override;
140150

141151
bool query_attr(unsigned number, const char **names, MYSQL_BIND *) override;

driver/nativeapi/native_connection_wrapper.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ class NativeConnectionWrapper : public boost::noncopyable
139139
virtual int get_option(::sql::mysql::MySQL_Connection_Options,
140140
const int &) = 0;
141141

142+
virtual int plugin_option(int plugin_type,
143+
const ::sql::SQLString & plugin_name,
144+
const ::sql::SQLString & option,
145+
const ::sql::SQLString & value) = 0;
146+
147+
virtual int get_plugin_option(int plugin_type,
148+
const ::sql::SQLString & plugin_name,
149+
const ::sql::SQLString & option,
150+
const ::sql::SQLString & value) = 0;
151+
142152
virtual bool has_query_attributes() = 0;
143153

144154
virtual bool query_attr(unsigned nrAttr, const char** names ,::MYSQL_BIND* binds) = 0;
@@ -170,6 +180,7 @@ class NativeConnectionWrapper : public boost::noncopyable
170180
virtual NativeStatementWrapper & stmt_init() = 0;
171181

172182
virtual unsigned int warning_count() = 0;
183+
173184
};
174185

175186
} /* namespace NativeAPI */

0 commit comments

Comments
 (0)