diff --git a/src/ActiveDirectoryToRestApi/ActiveDirectoryToRestApi.csproj b/src/ActiveDirectoryToRestApi/ActiveDirectoryToRestApi.csproj
index 7541e7b..e17b833 100644
--- a/src/ActiveDirectoryToRestApi/ActiveDirectoryToRestApi.csproj
+++ b/src/ActiveDirectoryToRestApi/ActiveDirectoryToRestApi.csproj
@@ -9,7 +9,7 @@
d52504e9-ea6e-4152-a52e-467ca002e47c
$(PackageVersion)
$(PackageVersion)
- 1.0.0.1
+ 1.0.0.2
diff --git a/src/ActiveDirectoryToRestApi/Controllers/HealthController.cs b/src/ActiveDirectoryToRestApi/Controllers/HealthController.cs
new file mode 100644
index 0000000..8fe0305
--- /dev/null
+++ b/src/ActiveDirectoryToRestApi/Controllers/HealthController.cs
@@ -0,0 +1,23 @@
+namespace ActiveDirectoryToRestApi.Controllers;
+
+[ApiController]
+[Route("/")]
+public class HealthController : ControllerBase
+{
+ private readonly ILogger _logger;
+ private readonly LdapService _ldapService;
+
+ public HealthController(ILogger logger, LdapService ldapService)
+ {
+ _logger = logger;
+ _ldapService = ldapService;
+ }
+
+ [HttpGet]
+ public ActionResult Get()
+ {
+ var connection = _ldapService.CheckLdapConnection();
+ if (connection) return Ok(new Health());
+ return StatusCode(500, new Health { Data = new HealthData { Health = false } });
+ }
+}
diff --git a/src/ActiveDirectoryToRestApi/Models/Health.cs b/src/ActiveDirectoryToRestApi/Models/Health.cs
new file mode 100644
index 0000000..9b46613
--- /dev/null
+++ b/src/ActiveDirectoryToRestApi/Models/Health.cs
@@ -0,0 +1,11 @@
+namespace ActiveDirectoryToRestApi.Models;
+
+public class Health
+{
+ public HealthData Data { get; set; } = new();
+}
+
+public class HealthData
+{
+ public bool Health { get; set; } = true;
+}
\ No newline at end of file
diff --git a/src/ActiveDirectoryToRestApi/Services/LdapService.cs b/src/ActiveDirectoryToRestApi/Services/LdapService.cs
index beec255..71398ca 100644
--- a/src/ActiveDirectoryToRestApi/Services/LdapService.cs
+++ b/src/ActiveDirectoryToRestApi/Services/LdapService.cs
@@ -2,15 +2,18 @@
public class LdapService
{
+ private readonly ILogger _logger;
private readonly LdapConfigs _ldapConfigs;
private readonly LdapConnection _connection;
private readonly IConfiguration _configuration;
- public LdapService(LdapConnection connection, IConfiguration configuration)
+ public LdapService(ILogger logger, LdapConnection connection, IConfiguration configuration)
{
+ _logger = logger;
_connection = connection;
_configuration = configuration;
_ldapConfigs = _configuration.GetSection(nameof(LdapConfigs)).Get();
+ _logger = logger;
}
public User GetUserByUserName(string username)
{
@@ -174,4 +177,18 @@ public class LdapService
return 42;
}
}
+
+ public bool CheckLdapConnection()
+ {
+ try
+ {
+ _connection.Bind();
+ return true;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError("LDAP connection failed: {ex.StackTrace}", ex.StackTrace);
+ return false;
+ }
+ }
}