@@ -66,6 +66,7 @@ int main(int argc, const char **argv)
66
66
const char * mysql_user = getenv (" MYSQL_USER" );
67
67
const char * mysql_password = getenv (" MYSQL_PASSWORD" );
68
68
const char * ldap_user = getenv (" LDAP_USER" );
69
+ const char * ldap_user_dn = getenv (" LDAP_USER_DN" );
69
70
const char * ldap_simple_pwd = getenv (" LDAP_SIMPLE_PWD" );
70
71
const char * ldap_scram_pwd = getenv (" LDAP_SCRAM_PWD" );
71
72
const char * plugin_dir = getenv (" PLUGIN_DIR" );
@@ -225,6 +226,37 @@ int main(int argc, const char **argv)
225
226
cout << " #" << endl;
226
227
cout << " #\t Demo of connection URL syntax" << endl;
227
228
229
+ // Lets first create ldap and sasl users
230
+ if (ldap_user || ldap_user_dn)
231
+ {
232
+ if (ldap_user_dn)
233
+ {
234
+ stringstream user_create;
235
+ stmt.reset (con->createStatement ());
236
+ user_create << " CREATE USER ldap_simple IDENTIFIED WITH "
237
+ " authentication_ldap_simple AS \" "
238
+ << ldap_user_dn
239
+ << " \" " ;
240
+ try {
241
+ stmt->execute (user_create.str ());
242
+ }catch (...)
243
+ {}
244
+ }
245
+
246
+ if (ldap_user)
247
+ {
248
+ stringstream user_create;
249
+ stmt.reset (con->createStatement ());
250
+ user_create << " CREATE USER "
251
+ << ldap_user
252
+ << " @'%' IDENTIFIED WITH authentication_ldap_sasl" ;
253
+ try {
254
+ stmt->execute (user_create.str ());
255
+ }catch (...)
256
+ {}
257
+ }
258
+ }
259
+
228
260
if (ldap_simple_pwd)
229
261
{
230
262
// AUTH USING SASL client side plugin
@@ -234,9 +266,10 @@ int main(int argc, const char **argv)
234
266
plugin
235
267
*/
236
268
269
+
270
+
237
271
sql::ConnectOptionsMap opts;
238
272
opts[OPT_HOSTNAME] = url;
239
- // We expect ldap_simple is the mysql user
240
273
opts[OPT_USERNAME] = " ldap_simple" ;
241
274
opts[OPT_PASSWORD] = ldap_simple_pwd;
242
275
@@ -294,7 +327,7 @@ int main(int argc, const char **argv)
294
327
con->close ();
295
328
296
329
} catch (sql::SQLException &e) {
297
- cout << " #\t\t " << url << " caused expected exception when connecting using " << user << endl;
330
+ cout << " #\t\t " << url << " caused expected exception when connecting using " << ldap_user << endl;
298
331
cout << " #\t\t " << e.what () << " (MySQL error code: " << e.getErrorCode ();
299
332
cout << " , SQLState: " << e.getSQLState () << " )" << endl;
300
333
throw ;
0 commit comments