95 lines
4.7 KiB
C#
95 lines
4.7 KiB
C#
//using HRM.BO;
|
|
//using Microsoft.AspNetCore.Http;
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Linq;
|
|
//using System.Net;
|
|
//using System.Net.Http;
|
|
//using System.Security.Principal;
|
|
//using System.Text;
|
|
//using System.Threading;
|
|
//using System.Threading.Tasks;
|
|
//using System.Web;
|
|
|
|
//namespace HRM.UI.Components
|
|
//{
|
|
// public class AuthenticationHandler : DelegatingHandler
|
|
// {
|
|
// private readonly IEmpMobileService _EmpMobileService;
|
|
// IEnumerable<string> authHeaderValues = null;
|
|
// protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
// {
|
|
// try
|
|
// {
|
|
// request.Headers.TryGetValues("Authorization", out authHeaderValues);
|
|
// if (authHeaderValues == null)
|
|
// {
|
|
// var response = request.CreateResponse(HttpStatusCode.Forbidden, new CustomMessage() { Caption = EnumExceptionType.Error.ToFriendlyString(), Message = "Access Forbidden.Contact to system Administrator." });
|
|
// var tsc = new TaskCompletionSource<HttpResponseMessage>();
|
|
// tsc.SetResult(response);
|
|
// return tsc.Task;
|
|
// }
|
|
|
|
// var tokens = authHeaderValues.FirstOrDefault();
|
|
// tokens = tokens.Replace("Basic", "").Trim();
|
|
|
|
// if (!string.IsNullOrEmpty(tokens))
|
|
// {
|
|
// byte[] data = Convert.FromBase64String(tokens);
|
|
// string decodedString = Encoding.UTF8.GetString(data);
|
|
|
|
// if (!decodedString.Equals("CEL1@3$5"))
|
|
// {
|
|
// string[] tokensValues = decodedString.Split(new char[] { ':' }, 2);
|
|
// if (tokensValues.Length != 2)
|
|
// {
|
|
// var response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
|
|
// var tsc = new TaskCompletionSource<HttpResponseMessage>();
|
|
// tsc.SetResult(response);
|
|
// return tsc.Task;
|
|
// }
|
|
// int EmployeeID;
|
|
// int.TryParse(tokensValues[0], out EmployeeID);
|
|
// ServiceInitializer.Initialize(EmployeeID);
|
|
// EmpMobile oEmpMobile = _EmpMobileService.Get(EmployeeID, tokensValues[1]);
|
|
// if (oEmpMobile != null)
|
|
// {
|
|
// IPrincipal principal = new CustomPrincipal(oEmpMobile);
|
|
// Thread.CurrentPrincipal = principal;
|
|
// HttpContext.Current.User = principal;
|
|
// }
|
|
// else // Unauthorized access - wrong crededentials
|
|
// {
|
|
// // { for hosting purpose }
|
|
// //oEmpMobile = EmpMobile.GetByEmployeeID(ID.FromInteger(EmployeeID)).First();
|
|
// //IPrincipal principal = new CustomPrincipal(oEmpMobile);
|
|
// //Thread.CurrentPrincipal = principal;
|
|
// //HttpContext.Current.User = principal;
|
|
|
|
// var response = request.CreateResponse(HttpStatusCode.Forbidden, new CustomMessage() { Caption = EnumExceptionType.Error.ToFriendlyString(), Message = "Access Forbidden.Contact to system Administrator." });
|
|
// var tsc = new TaskCompletionSource<HttpResponseMessage>();
|
|
// tsc.SetResult(response);
|
|
// return tsc.Task;
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// var response = request.CreateResponse(HttpStatusCode.Forbidden, new CustomMessage() { Caption = EnumExceptionType.Error.ToFriendlyString(), Message = "Access Forbidden.Contact to system Administrator." });
|
|
// var tsc = new TaskCompletionSource<HttpResponseMessage>();
|
|
// tsc.SetResult(response);
|
|
// return tsc.Task;
|
|
// }
|
|
// return base.SendAsync(request, cancellationToken);
|
|
// }
|
|
// catch
|
|
// {
|
|
// var response = request.CreateResponse(HttpStatusCode.Forbidden, new CustomMessage() { Caption = EnumExceptionType.Error.ToFriendlyString(), Message = "Access Forbidden.Contact to system Administrator." });
|
|
// var tsc = new TaskCompletionSource<HttpResponseMessage>();
|
|
// tsc.SetResult(response);
|
|
// return tsc.Task;
|
|
// }
|
|
// }
|
|
// }
|
|
//} |