aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Web/Controllers
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-02-20 22:55:15 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-02-20 22:55:15 +0200
commit9447a8a09f87d6ea2cb62860021c595386668eec (patch)
treea02db15a1247587f14fedb6ccae76f79bd63afb3 /Software/Visual_Studio/Tango.Web/Controllers
parent17446569ca8d8dd00331da5926b938593c4b117f (diff)
downloadTango-9447a8a09f87d6ea2cb62860021c595386668eec.tar.gz
Tango-9447a8a09f87d6ea2cb62860021c595386668eec.zip
A lot of work !!!
Diffstat (limited to 'Software/Visual_Studio/Tango.Web/Controllers')
-rw-r--r--Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs (renamed from Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs)61
1 files changed, 55 insertions, 6 deletions
diff --git a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs b/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs
index 1fae9cccc..854d1cf96 100644
--- a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs
+++ b/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs
@@ -10,14 +10,16 @@ using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
using Tango.Logging;
+using Tango.Transport.Web;
+using Tango.Web.Authentication;
namespace Tango.Web.Controllers
{
- public class JsonController : ApiController
+ public class TangoController : ApiController
{
protected LogManager LogManager { get; private set; }
- public JsonController()
+ public TangoController()
{
LogManager = LogManager.Default;
}
@@ -43,10 +45,12 @@ namespace Tango.Web.Controllers
{
request = context.Request.Content.ReadAsStringAsync().Result;
}
- catch {}
+ catch { }
LogManager.Log($"Request Received on {controllerName + "/" + actionName}: \n{request}");
+ OnRequestArrived(context.Request);
+
var result = await base.ExecuteAsync(context, cancellationToken);
return result;
}
@@ -60,16 +64,61 @@ namespace Tango.Web.Controllers
{
code = HttpStatusCode.BadRequest;
}
- else if (ex is AuthenticationException)
+ else if (ex is AuthenticationException || ex is TokenExpiredException)
{
code = HttpStatusCode.Unauthorized;
}
+ var httpException = new HttpResponseException(Request.CreateErrorResponse(code, ex));
+
#if DEBUG
- throw new HttpResponseException(Request.CreateErrorResponse(code, ex.ToString()));
+ throw httpException;
#else
- throw new HttpResponseException(Request.CreateErrorResponse(code, ex.FlattenMessage()));
+ //Remove Stack trace
+ var expandedException = httpException.Response.Content as System.Net.Http.ObjectContent<System.Web.Http.HttpError>;
+
+ if (expandedException != null)
+ {
+ var expandedExceptionValues = expandedException.Value as HttpError;
+
+ if (expandedExceptionValues != null)
+ {
+ expandedExceptionValues["StackTrace"] = "StackTrace not provided.";
+ }
+ }
#endif
+
+
+ throw httpException;
+ }
+ }
+
+ protected virtual void OnRequestArrived(HttpRequestMessage request)
+ {
+ //Do nothing.
+ }
+ }
+
+ public class TangoController<T> : TangoController where T : class
+ {
+ public WebToken<T> RequestToken { get; set; }
+
+ protected override void OnRequestArrived(HttpRequestMessage request)
+ {
+ base.OnRequestArrived(request);
+
+ var authorizationHeader = request.Headers.Authorization;
+
+ if (authorizationHeader != null && authorizationHeader.Parameter != null)
+ {
+ try
+ {
+ RequestToken = WebToken<T>.FromToken(authorizationHeader.Parameter);
+ }
+ catch (Exception ex)
+ {
+ throw new HttpParseException("Could not parse the provided token embedded object.", ex);
+ }
}
}
}