@@ -179,9 +179,10 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
179
179
LDAP_LOG_D (" start TLS" );
180
180
result = NKikimrLdap::StartTLS (*ld);
181
181
if (!NKikimrLdap::IsSuccess (result)) {
182
- LDAP_LOG_D (" Could not start TLS. " << NKikimrLdap::ErrorToString (result));
182
+ TStringBuilder logErrorMessage;
183
+ logErrorMessage << " Could not start TLS. " << NKikimrLdap::ErrorToString (result);
183
184
TEvLdapAuthProvider::TError error {
184
- .Message = ERROR_MESSAGE, .Retryable = NKikimrLdap::IsRetryableError (result)
185
+ .Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = NKikimrLdap::IsRetryableError (result)
185
186
};
186
187
// The Unbind operation is not the antithesis of the Bind operation as the name implies.
187
188
// Close the LDAP connection, free the resources contained in the LDAP structure
@@ -193,10 +194,11 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
193
194
LDAP_LOG_D (" bind: bindDn: " << Settings.GetBindDn ());
194
195
result = NKikimrLdap::Bind (*ld, Settings.GetBindDn (), Settings.GetBindPassword ());
195
196
if (!NKikimrLdap::IsSuccess (result)) {
196
- LDAP_LOG_D (" Could not perform initial LDAP bind for dn " << Settings.GetBindDn () << " on server " + UrisCreator.GetUris () << " . "
197
- << NKikimrLdap::ErrorToString (result));
197
+ TStringBuilder logErrorMessage;
198
+ logErrorMessage << " Could not perform initial LDAP bind for dn " << Settings.GetBindDn () << " on server " + UrisCreator.GetUris () << " . "
199
+ << NKikimrLdap::ErrorToString (result);
198
200
TEvLdapAuthProvider::TError error {
199
- .Message = ERROR_MESSAGE, .Retryable = NKikimrLdap::IsRetryableError (result)
201
+ .Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = NKikimrLdap::IsRetryableError (result)
200
202
};
201
203
// The Unbind operation is not the antithesis of the Bind operation as the name implies.
202
204
// Close the LDAP connection, free the resources contained in the LDAP structure
@@ -216,37 +218,41 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
216
218
const TString& caCertificateFile = Settings.GetUseTls ().GetCaCertFile ();
217
219
result = NKikimrLdap::SetOption (*ld, NKikimrLdap::EOption::TLS_CACERTFILE, caCertificateFile.c_str ());
218
220
if (!NKikimrLdap::IsSuccess (result)) {
219
- LDAP_LOG_D (" Could not set LDAP ca certificate file \" " << caCertificateFile + " \" : " << NKikimrLdap::ErrorToString (result));
221
+ TStringBuilder logErrorMessage;
222
+ logErrorMessage << " Could not set LDAP ca file \" " << caCertificateFile + " \" : " << NKikimrLdap::ErrorToString (result);
220
223
NKikimrLdap::Unbind (*ld);
221
224
return {{NKikimrLdap::ErrorToStatus (result),
222
- {.Message = ERROR_MESSAGE, .Retryable = NKikimrLdap::IsRetryableError (result)}}};
225
+ {.Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = NKikimrLdap::IsRetryableError (result)}}};
223
226
}
224
227
}
225
228
226
229
LDAP_LOG_D (" init: scheme: " << Settings.GetScheme () << " , uris: " << UrisCreator.GetUris () << " , port: " << UrisCreator.GetConfiguredPort ());
227
230
result = NKikimrLdap::Init (ld, Settings.GetScheme (), UrisCreator.GetUris (), UrisCreator.GetConfiguredPort ());
228
231
if (!NKikimrLdap::IsSuccess (result)) {
229
- LDAP_LOG_D (" Could not initialize LDAP connection for uris: " << UrisCreator.GetUris () << " . " << NKikimrLdap::LdapError (*ld));
232
+ TStringBuilder logErrorMessage;
233
+ logErrorMessage << " Could not initialize LDAP connection for uris: " << UrisCreator.GetUris () << " . " << NKikimrLdap::LdapError (*ld);
230
234
return {{TEvLdapAuthProvider::EStatus::UNAVAILABLE,
231
- {.Message = ERROR_MESSAGE, .Retryable = false }}};
235
+ {.Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = false }}};
232
236
}
233
237
234
238
result = NKikimrLdap::SetProtocolVersion (*ld);
235
239
if (!NKikimrLdap::IsSuccess (result)) {
236
240
NKikimrLdap::Unbind (*ld);
237
- LDAP_LOG_D (" Could not set LDAP protocol version: " << NKikimrLdap::ErrorToString (result));
241
+ TStringBuilder logErrorMessage;
242
+ logErrorMessage << " Could not set LDAP protocol version: " << NKikimrLdap::ErrorToString (result);
238
243
return {{NKikimrLdap::ErrorToStatus (result),
239
- {.Message = ERROR_MESSAGE, .Retryable = NKikimrLdap::IsRetryableError (result)}}};
244
+ {.Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = NKikimrLdap::IsRetryableError (result)}}};
240
245
}
241
246
242
247
if (Settings.GetScheme () == NKikimrLdap::LDAPS_SCHEME || Settings.GetUseTls ().GetEnable ()) {
243
248
int requireCert = NKikimrLdap::ConvertRequireCert (Settings.GetUseTls ().GetCertRequire ());
244
249
result = NKikimrLdap::SetOption (*ld, NKikimrLdap::EOption::TLS_REQUIRE_CERT, &requireCert);
245
250
if (!NKikimrLdap::IsSuccess (result)) {
246
251
NKikimrLdap::Unbind (*ld);
247
- LDAP_LOG_D (" Could not set require certificate option: " << NKikimrLdap::ErrorToString (result));
252
+ TStringBuilder logErrorMessage;
253
+ logErrorMessage << " Could not set require certificate option: " << NKikimrLdap::ErrorToString (result);
248
254
return {{NKikimrLdap::ErrorToStatus (result),
249
- {.Message = ERROR_MESSAGE, .Retryable = NKikimrLdap::IsRetryableError (result)}}};
255
+ {.Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = NKikimrLdap::IsRetryableError (result)}}};
250
256
}
251
257
}
252
258
@@ -256,23 +262,27 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
256
262
TAuthenticateUserResponse AuthenticateUser (const TAuthenticateUserRequest& request) {
257
263
char * dn = NKikimrLdap::GetDn (*request.Ld , request.Entry );
258
264
if (dn == nullptr ) {
259
- LDAP_LOG_D (" Could not get dn for the first entry matching " << FilterCreator.GetFilter (request.Login ) << " on server " << UrisCreator.GetUris () << " . "
260
- << NKikimrLdap::LdapError (*request.Ld ));
265
+ TStringBuilder logErrorMessage;
266
+ logErrorMessage << " Could not get dn for the first entry matching " << FilterCreator.GetFilter (request.Login )
267
+ << " on server " << UrisCreator.GetUris () << " . " << NKikimrLdap::LdapError (*request.Ld );
261
268
return {{TEvLdapAuthProvider::EStatus::UNAUTHORIZED,
262
- {.Message = ERROR_MESSAGE, .Retryable = false }}};
269
+ {.Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = false }}};
263
270
}
264
271
if (request.Password .empty ()) {
265
- LDAP_LOG_D (" LDAP login failed for user " << TString (dn) << " . Empty password" );
272
+ TStringBuilder logErrorMessage;
273
+ logErrorMessage << " LDAP login failed for user " << TString (dn) << " . Empty password" ;
266
274
NKikimrLdap::MemFree (dn);
267
- return {{.Status = TEvLdapAuthProvider::EStatus::UNAUTHORIZED, .Error = {.Message = TString ( ERROR_MESSAGE) + " . Empty password " , .Retryable = false }}};
275
+ return {{.Status = TEvLdapAuthProvider::EStatus::UNAUTHORIZED, .Error = {.Message = ERROR_MESSAGE, . LogMessage = logErrorMessage , .Retryable = false }}};
268
276
}
269
277
TEvLdapAuthProvider::TError error;
270
278
LDAP_LOG_D (" bind: bindDn: " << dn);
271
279
int result = NKikimrLdap::Bind (*request.Ld , dn, request.Password );
272
280
if (!NKikimrLdap::IsSuccess (result)) {
273
- LDAP_LOG_D (" LDAP login failed for user " << TString (dn) << " on server " << UrisCreator.GetUris () << " . "
274
- << NKikimrLdap::ErrorToString ((result)));
281
+ TStringBuilder logErrorMessage;
282
+ logErrorMessage << " LDAP login failed for user " << TString (dn) << " on server " << UrisCreator.GetUris () << " . "
283
+ << NKikimrLdap::ErrorToString ((result));
275
284
error.Message = ERROR_MESSAGE;
285
+ error.LogMessage = logErrorMessage;
276
286
error.Retryable = NKikimrLdap::IsRetryableError (result);
277
287
}
278
288
NKikimrLdap::MemFree (dn);
@@ -296,22 +306,24 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
296
306
&searchMessage);
297
307
TSearchUserResponse response;
298
308
if (!NKikimrLdap::IsSuccess (result)) {
299
- LDAP_LOG_D (" Could not search for filter " << searchFilter << " on server " << UrisCreator.GetUris () << " . "
300
- << NKikimrLdap::ErrorToString (result));
309
+ TStringBuilder logErrorMessage;
310
+ logErrorMessage << " Could not perform search for filter " << searchFilter << " on server " << UrisCreator.GetUris () << " . "
311
+ << NKikimrLdap::ErrorToString (result);
301
312
response.Status = NKikimrLdap::ErrorToStatus (result);
302
- response.Error = {.Message = ERROR_MESSAGE, .Retryable = NKikimrLdap::IsRetryableError (result)};
313
+ response.Error = {.Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = NKikimrLdap::IsRetryableError (result)};
303
314
return response;
304
315
}
305
316
const int countEntries = NKikimrLdap::CountEntries (request.Ld , searchMessage);
306
317
if (countEntries != 1 ) {
318
+ TStringBuilder logErrorMessage;
307
319
if (countEntries == 0 ) {
308
- LDAP_LOG_D ( " LDAP user " << request.User << " does not exist. "
309
- " LDAP search for filter " << searchFilter << " on server " << UrisCreator.GetUris () << " return no entries" ) ;
320
+ logErrorMessage << " LDAP user " << request.User << " does not exist. "
321
+ " LDAP search for filter " << searchFilter << " on server " << UrisCreator.GetUris () << " return no entries" ;
310
322
} else {
311
- LDAP_LOG_D ( " LDAP user " << request.User << " is not unique. "
312
- " LDAP search for filter " << searchFilter << " on server " << UrisCreator.GetUris () << " return " << countEntries << " entries" ) ;
323
+ logErrorMessage << " LDAP user " << request.User << " is not unique. "
324
+ " LDAP search for filter " << searchFilter << " on server " << UrisCreator.GetUris () << " return " << countEntries << " entries" ;
313
325
}
314
- response.Error = {.Message = ERROR_MESSAGE, .Retryable = false };
326
+ response.Error = {.Message = ERROR_MESSAGE, .LogMessage = logErrorMessage, . Retryable = false };
315
327
response.Status = TEvLdapAuthProvider::EStatus::UNAUTHORIZED;
316
328
NKikimrLdap::MsgFree (searchMessage);
317
329
return response;
@@ -411,16 +423,16 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
411
423
412
424
TInitializeLdapConnectionResponse CheckRequiredSettingsParameters () const {
413
425
if (Settings.GetHosts ().empty () && Settings.GetHost ().empty ()) {
414
- return {TEvLdapAuthProvider::EStatus::UNAVAILABLE, {.Message = " List of ldap server hosts is empty" , .Retryable = false }};
426
+ return {TEvLdapAuthProvider::EStatus::UNAVAILABLE, {.Message = ERROR_MESSAGE, . LogMessage = " List of ldap server hosts is empty" , .Retryable = false }};
415
427
}
416
428
if (Settings.GetBaseDn ().empty ()) {
417
- return {TEvLdapAuthProvider::EStatus::UNAVAILABLE, {.Message = " Parameter BaseDn is empty" , .Retryable = false }};
429
+ return {TEvLdapAuthProvider::EStatus::UNAVAILABLE, {.Message = ERROR_MESSAGE, . LogMessage = " Parameter BaseDn is empty" , .Retryable = false }};
418
430
}
419
431
if (Settings.GetBindDn ().empty ()) {
420
- return {TEvLdapAuthProvider::EStatus::UNAVAILABLE, {.Message = " Parameter BindDn is empty" , .Retryable = false }};
432
+ return {TEvLdapAuthProvider::EStatus::UNAVAILABLE, {.Message = ERROR_MESSAGE, . LogMessage = " Parameter BindDn is empty" , .Retryable = false }};
421
433
}
422
434
if (Settings.GetBindPassword ().empty ()) {
423
- return {TEvLdapAuthProvider::EStatus::UNAVAILABLE, {.Message = " Parameter BindPassword is empty" , .Retryable = false }};
435
+ return {TEvLdapAuthProvider::EStatus::UNAVAILABLE, {.Message = ERROR_MESSAGE, . LogMessage = " Parameter BindPassword is empty" , .Retryable = false }};
424
436
}
425
437
return {TEvLdapAuthProvider::EStatus::SUCCESS, {}};
426
438
}
@@ -452,7 +464,7 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
452
464
}
453
465
454
466
private:
455
- static constexpr const char * ERROR_MESSAGE = " User is unauthorized in LDAP server " ;
467
+ static constexpr const char * ERROR_MESSAGE = " Could not login via LDAP" ;
456
468
457
469
const NKikimrProto::TLdapAuthentication Settings;
458
470
const TSearchFilterCreator FilterCreator;
0 commit comments