diff --git a/Microservicios/MsLdap/.config/dotnet-tools.json b/Microservicios/MsLdap/.config/dotnet-tools.json new file mode 100644 index 0000000..d9d129c --- /dev/null +++ b/Microservicios/MsLdap/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "8.0.3", + "commands": [ + "dotnet-ef" + ] + } + } +} \ No newline at end of file diff --git a/Microservicios/MsLdap/Controllers/LdapController.cs b/Microservicios/MsLdap/Controllers/LdapController.cs new file mode 100644 index 0000000..5d2a73e --- /dev/null +++ b/Microservicios/MsLdap/Controllers/LdapController.cs @@ -0,0 +1,66 @@ +using LdapLoginLib; +using LdapLoginLib.Models; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace MsLdap.Controllers +{ + [Route("[controller]")] + [ApiController] + public class LdapController : ControllerBase + { + [HttpGet("users/by-id/{userID}")] + public IActionResult GetUserById(string userID) + { + try + { + UserInfo userInfo = LDAP.GetUserInfo(document: userID); + + + return Ok(userInfo); + + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + + [HttpGet("users/by-username/{username}")] + public IActionResult GetUserByUsername(string username) + { + try + { + UserInfo userInfo = LDAP.GetUserInfo(username: username); + + + return Ok(userInfo); + + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + + + [HttpGet("users/by-mail/{mail}")] + public IActionResult GetUserByMail(string mail) + { + try + { + UserInfo userInfo = LDAP.GetUserInfo(email: mail); + + + return Ok(userInfo); + + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + + + } +} diff --git a/Microservicios/MsLdap/Dockerfile b/Microservicios/MsLdap/Dockerfile new file mode 100644 index 0000000..036d1b5 --- /dev/null +++ b/Microservicios/MsLdap/Dockerfile @@ -0,0 +1,23 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["Microservicios/MsLdap/MsLdap.csproj", "Microservicios/MsLdap/"] +RUN dotnet restore "./Microservicios/MsLdap/./MsLdap.csproj" +COPY . . +WORKDIR "/src/Microservicios/MsLdap" +RUN dotnet build "./MsLdap.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./MsLdap.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "MsLdap.dll"] \ No newline at end of file diff --git a/Microservicios/MsLdap/MsLdap.csproj b/Microservicios/MsLdap/MsLdap.csproj new file mode 100644 index 0000000..ada2b70 --- /dev/null +++ b/Microservicios/MsLdap/MsLdap.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + Linux + ..\.. + + + + + + + + + + + + + + + + diff --git a/Microservicios/MsLdap/Program.cs b/Microservicios/MsLdap/Program.cs new file mode 100644 index 0000000..7c0ddc8 --- /dev/null +++ b/Microservicios/MsLdap/Program.cs @@ -0,0 +1,42 @@ +using Microsoft.OpenApi.Models; + +namespace MsLdap +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "LDAP Api", Version = "v1" }); + }); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment() || app.Environment + .IsProduction()) + { + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "LDAP Api V1"); + }); + } + + app.UseAuthorization(); + + + app.MapControllers(); + + app.Run(); + } + } +} diff --git a/Microservicios/MsLdap/Properties/launchSettings.json b/Microservicios/MsLdap/Properties/launchSettings.json new file mode 100644 index 0000000..86bfb3e --- /dev/null +++ b/Microservicios/MsLdap/Properties/launchSettings.json @@ -0,0 +1,40 @@ +{ + "profiles": { + "MsLdap": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5034" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_URLS": "http://+:80" + }, + "publishAllPorts": true + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:42244", + "sslPort": 0 + } + } +} \ No newline at end of file diff --git a/Microservicios/MsLdap/appsettings.Development.json b/Microservicios/MsLdap/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Microservicios/MsLdap/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Microservicios/MsLdap/appsettings.json b/Microservicios/MsLdap/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Microservicios/MsLdap/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}