mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added retry logic to ConnectAndBind
This commit is contained in:
@@ -13,4 +13,5 @@ public class LdapConfig
|
|||||||
public string UsersOu { get; set; } = "ou=users";
|
public string UsersOu { get; set; } = "ou=users";
|
||||||
public string GroupsOu { get; set; } = "ou=groups";
|
public string GroupsOu { get; set; } = "ou=groups";
|
||||||
public string MigrationsOu { get; set; } = "ou=migrations";
|
public string MigrationsOu { get; set; } = "ou=migrations";
|
||||||
|
public int ConnectionRetryCount { get; set; } = 10;
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,11 @@ public partial class LdapService : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task ConnectAndBind()
|
private async Task ConnectAndBind()
|
||||||
|
{
|
||||||
|
int retries = 0;
|
||||||
|
while (retries++ < _opts.ConnectionRetryCount)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (!_conn.Connected)
|
if (!_conn.Connected)
|
||||||
{
|
{
|
||||||
@@ -31,11 +36,26 @@ public partial class LdapService : IDisposable
|
|||||||
}
|
}
|
||||||
catch (SystemException ex)
|
catch (SystemException ex)
|
||||||
{
|
{
|
||||||
_logger.LogCritical("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
|
_logger.LogWarning("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await _conn.BindAsync(_opts.BindDn, _opts.BindPassword);
|
await _conn.BindAsync(_opts.BindDn, _opts.BindPassword);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (retries == _opts.ConnectionRetryCount)
|
||||||
|
{
|
||||||
|
_logger.LogError("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Unable to connect to LDAP: {ex.Message}\n{ex.StackTrace}", [ex.Message, ex.StackTrace]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string AssetsBaseDn => string.IsNullOrEmpty(_opts.AssetsOu) ? _opts.BaseDn : $"{_opts.AssetsOu},{_opts.BaseDn}";
|
public string AssetsBaseDn => string.IsNullOrEmpty(_opts.AssetsOu) ? _opts.BaseDn : $"{_opts.AssetsOu},{_opts.BaseDn}";
|
||||||
|
|||||||
Reference in New Issue
Block a user