Skip to content

Commit

Permalink
chore(0.1.0): added new soap gateway (#25)
Browse files Browse the repository at this point in the history
* ✨feat: added new soap gateway (#24)

* feat: update inteface gateway #18

* feat!: added exception handler for all controllers #19 & create env #22

* BREAKING CHANGE: change routing /proxy #21

* docs: update with new features

* fix: deleted git makers
  • Loading branch information
SantiagoGaonaC authored Oct 4, 2023
1 parent 2bc83f2 commit fcd4aaf
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 75 deletions.
21 changes: 17 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 0.0.6 (2023-10-01)
## 0.1.0 (2023-10-04)


### ⚠ BREAKING CHANGES

* change routing /proxy #21

* docs: update with new features

* fix: deleted git makers

* ✨feat: added new soap gateway (#24) ([5947cf8](https://github.com/hawks-atlanta/proxy-net/commit/5947cf87dff20992aac7de0395d5090417f5563d)), closes [#24](https://github.com/hawks-atlanta/proxy-net/issues/24) [#18](https://github.com/hawks-atlanta/proxy-net/issues/18) [#19](https://github.com/hawks-atlanta/proxy-net/issues/19) [#22](https://github.com/hawks-atlanta/proxy-net/issues/22)

### 0.0.7 (2023-10-04)

### 0.0.6 (2023-10-01)

### Features

* response clean for endpoints register & login ([#16](https://github.com/hawks-atlanta/proxy-net/issues/16)) ([ab1572e](https://github.com/hawks-atlanta/proxy-net/commit/ab1572e58d4838445a953eb99d5637fa8675d38e))
- response clean for endpoints register & login ([#16](https://github.com/hawks-atlanta/proxy-net/issues/16)) ([ab1572e](https://github.com/hawks-atlanta/proxy-net/commit/ab1572e58d4838445a953eb99d5637fa8675d38e))

### 0.0.5 (2023-09-29)

### 0.0.4 (2023-09-27)


### Features

* new gateway implementation for [#9](https://github.com/hawks-atlanta/proxy-net/issues/9) & [#10](https://github.com/hawks-atlanta/proxy-net/issues/10) ([#12](https://github.com/hawks-atlanta/proxy-net/issues/12)) ([451de95](https://github.com/hawks-atlanta/proxy-net/commit/451de950887b2ed2f27e5803600a2afa81433d3e)), closes [#8](https://github.com/hawks-atlanta/proxy-net/issues/8) [#7](https://github.com/hawks-atlanta/proxy-net/issues/7)
- new gateway implementation for [#9](https://github.com/hawks-atlanta/proxy-net/issues/9) & [#10](https://github.com/hawks-atlanta/proxy-net/issues/10) ([#12](https://github.com/hawks-atlanta/proxy-net/issues/12)) ([451de95](https://github.com/hawks-atlanta/proxy-net/commit/451de950887b2ed2f27e5803600a2afa81433d3e)), closes [#8](https://github.com/hawks-atlanta/proxy-net/issues/8) [#7](https://github.com/hawks-atlanta/proxy-net/issues/7)

### 0.0.3 (2023-09-27)

Expand Down
6 changes: 2 additions & 4 deletions Controllers/Auth/LoginController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using proxy_net.Controllers.Adapters;
using proxy_net.Models.Auth.Entities;
using ServiceReference;
using System;
using System.Threading.Tasks;

namespace proxy_net.Controllers.Auth
{
Expand Down Expand Up @@ -33,6 +30,7 @@ public async Task<IActionResult> Post([FromBody] User user)
{
using (var client = new ServiceClient())
{
client.InnerChannel.OperationTimeout = TimeSpan.FromSeconds(50);
auth_loginResponse response = await client.auth_loginAsync(credentials);

if (response?.@return == null)
Expand All @@ -56,7 +54,7 @@ public async Task<IActionResult> Post([FromBody] User user)
catch (Exception ex)
{
_logger.LogError(ex, "Error en la llamada SOAP.");
return StatusCode(StatusCodes.Status500InternalServerError, "Error en la llamada SOAP: " + ex.Message);
throw;
}
}
}
Expand Down
51 changes: 13 additions & 38 deletions Controllers/Auth/RefreshTokenController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using proxy_net.Models.Auth.Entities;
using ServiceReference;
using System.Net;
using System.ServiceModel.Channels;
using System.ServiceModel;
using Newtonsoft.Json.Linq;
using Microsoft.AspNetCore.Authentication;
using proxy_net.Controllers.Adapters;

namespace proxy_net.Controllers.Auth
{
Expand All @@ -22,41 +15,23 @@ public RefreshTokenController(ILogger<LoginController> logger)
}

[HttpPost(Name = "RefreshToken")]
public async Task<IActionResult> Post()
//When using NEW refreshToken/Challenge change to:
//TODO:
//public async Task<IActionResult> Post([FromBody] User token)
public IActionResult Post([FromBody] User token)
{
string authorizationHeader = Request.Headers["Authorization"]!;
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
if (string.IsNullOrEmpty(token.Token))
{
return BadRequest("El cuerpo de la solicitud no es valido");
return BadRequest("El cuerpo de la solicitud es nulo o incompleto.");
}

var token = authorizationHeader.Substring("Bearer ".Length);
var authorization = AdaptersToSoap.ConvertToAuthorization(token);
Console.WriteLine("Token: " + token);
Console.WriteLine("Adapter: " + authorization);

var httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[HttpRequestHeader.Authorization] = authorizationHeader;
await using(var client = new ServiceClient())
try
{
return Ok(new { token = token.Token });
}
catch (Exception ex)
{
try
{
using (new OperationContextScope(client.InnerChannel))
{
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
auth_refreshResponse response = await client.auth_refreshAsync(authorization);
Console.WriteLine("auth_refreshResponse: " + response);
if (response == null || response.@return == null)
{
return StatusCode(StatusCodes.Status404NotFound, "La respuesta del servicio SOAP es nula o la propiedad 'return' es nula.");
}
return StatusCode(StatusCodes.Status200OK, response);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, "Error en la llamada SOAP: " + ex.Message);
}
_logger.LogError(ex, "Error en la llamada SOAP.");
throw;
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions Controllers/Auth/RegisterController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Mvc;
using proxy_net.Controllers.Adapters;
using proxy_net.Models.Auth.Entities;
using ServiceReference;
using System;

namespace proxy_net.Controllers.Auth
{
Expand Down Expand Up @@ -56,7 +53,7 @@ public async Task<IActionResult> Post([FromBody] User user)
catch (Exception ex)
{
_logger.LogError(ex, "Error en la llamada SOAP.");
return StatusCode(StatusCodes.Status500InternalServerError, "Error en la llamada SOAP: " + ex.Message);
throw;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["proxy-net.csproj", "."]
#ENV: Use the build arguments passed from Docker Compose as environment variables
ARG ASPNETCORE_URLS
ARG SERVICE_URL
ENV ASPNETCORE_URLS=$ASPNETCORE_URLS
ENV SERVICE_URL=$SERVICE_URL
RUN dotnet restore "./proxy-net.csproj"
COPY . .
WORKDIR "/src/."
Expand Down
44 changes: 44 additions & 0 deletions Handler/GlobalHandlerExceptionFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.ServiceModel;

public class GlobalExceptionFilter : IExceptionFilter
{
private readonly ILogger<GlobalExceptionFilter> _logger;

public GlobalExceptionFilter(ILogger<GlobalExceptionFilter> logger)
{
_logger = logger;
}
//OnException similar to Handler
public void OnException(ExceptionContext context)
{
_logger.LogError(context.Exception, "Error global de la aplicación.");

if (context.Exception is InvalidOperationException)
{
context.Result = new ObjectResult("Error en la operación") { StatusCode = 500 };
}
else if (context.Exception is TimeoutException)
{
context.Result = new ObjectResult("Error de tiempo de espera") { StatusCode = 500 };
}
else if (context.Exception is FaultException<MissingFieldException>)
{
context.Result = new ObjectResult("FaultException (MissingFieldException | Library has been removed or renamed)") { StatusCode = 500 };
}
else if (context.Exception is FaultException)
{
context.Result = new ObjectResult("FaultException (Error en la llamada SOAP)") { StatusCode = 500 };
}
else if (context.Exception is CommunicationException)
{
context.Result = new ObjectResult("CommunicationException (Error en la llamada SOAP)") { StatusCode = 500 };
}
else
{
context.Result = new ObjectResult("Excepción no controlada") { StatusCode = 500 };
}
context.ExceptionHandled = true;
}
}
15 changes: 6 additions & 9 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddMvc(options =>
{
options.Filters.Add<GlobalExceptionFilter>();
});

var app = builder.Build();

// Configure the HTTP request pipeline.
Expand All @@ -22,16 +27,8 @@

//Temporaly disabled HTTP -> HTTPS redirection
//app.UseHttpsRedirection();

//app.UseAuthorization();

app.Map("/proxy", app =>
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
});
app.MapControllers();

app.Run();
65 changes: 57 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ Proxy service intended to forward traffic between clients and `gateway-java` so

## Features

- [ ] LoginController
_Coming Soon added OpenAPI update_ #14 & #20

- [ ] RegisterController

- [ ] ChallengeController

Each API functionality could be access as listed in the table below:
- [ ] Each API functionality could be access as listed in the table below:

<table>
<tbody>
Expand Down Expand Up @@ -43,12 +39,13 @@ Proxy service intended to forward traffic between clients and `gateway-java` so
<td>POST</td>
<td>/refreshtoken</td>
<td class='text-align:center'>No</td>
<td>Validate Token User (Bearer Authentication)</td>
<td>Validate Token User (send "token": token)</td>
<td>Validate token/user and return a JWT.</td>
</tr>
</tbody>
</table>


## Step for running the PROXY-NET

Clone the repo:
Expand All @@ -71,10 +68,39 @@ docker compose up -d

Services port & route:

`http://localhost:8084/proxy`
`http://localhost:8084/ROUTES`

Note: In the [Docker-Compose FILE](https://github.com/hawks-atlanta/proxy-net/blob/main/docker-compose.yaml) edit the service you want to test with, for development use the same service that the gateway container provides and for production the URL of your ONLINE service.

### **Example:**

In Docker-Compose:

``````yaml
# Proxy-net
# Local/Docker http://gateway:8080/service (Gateway Container)
# Remote http://URL-YOUR-SOAP-PR/service
....
environment:
- SERVICE_URL=http://gateway:8080/service
``````

`Note: It is not necessary to add ?WSDL | connect to Localhost with using name "gateway" container`

With this config of Docker-Compose is auto impl in DockerFile:
``````yaml
...more lines
ARG ASPNETCORE_URLS
ARG SERVICE_URL
ENV ASPNETCORE_URLS=$ASPNETCORE_URLS
ENV SERVICE_URL=$SERVICE_URL
...more lines
``````

## For Development

---

#### Opening the project

1. Double click on the solution file. It will open the solution in your current version of the Visual Studio 2022.
Expand Down Expand Up @@ -103,3 +129,26 @@ dotnet build
```sh
dotnet run
```

## ⚠️WARNING! for updates in [Gateway-SOAP](https://github.com/hawks-atlanta/gateway-java):

To add the service either localhost or remote from the SOAP GATEWAY, the ENV `SERVICE_URL` reading is created, in the file [References.cs](https://github.com/hawks-atlanta/proxy-net/blob/main/ServiceReference/Reference.cs) implement this code:

``````c#
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.ServiceImpPort))
{
string serviceUrl = Environment.GetEnvironmentVariable("SERVICE_URL");
if (string.IsNullOrEmpty(serviceUrl))
{
throw new ApplicationException("SERVICE_URL env not found!");
}
return new System.ServiceModel.EndpointAddress(serviceUrl);
}
throw new System.InvalidOperationException(string.Format("No se pudo encontrar un punto de conexión con el nombre \"{0}\".", endpointConfiguration));
}
``````

🚨**NOTE!: **When you want to make a new update to the interface provided in the References file you need to add this line of code, be careful not to touch other lines of code!

Loading

0 comments on commit fcd4aaf

Please sign in to comment.