public async Task Invoke(HttpContext httpContext) { Context context = contextProvider.GetContext(); if (context == null) { context = new Context(); contextProvider.SetContext(context); } await requestDelegate.Invoke(httpContext); }
public static void Main(string[] args) { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); DefaultLogger.Info("Application initializing..."); IWebHost webHost = CreateWebHostBuilder(args).Build(); IContextProvider contextProvider = webHost.Services.GetRequiredService <IContextProvider>(); //Set Temporary Context contextProvider.SetContext(new Context()); MainStaticDataProvider.Initialize(webHost.Services); DefaultLogger.Info("Application initialized!"); webHost.Run(); }
public LoginResponse Post([FromBody] LoginRequest request) { LoginResponse response = authenticationProvider.Authenticate(request); if (response.Result != Entities.UserManagement.LoginResultEnum.Successful) { throw new JMException(response.Result.ToString()); } else { //issue token response.Token = tokenProvider.IssueToken(request.Username.ToPlainString()); Context context = contextProvider.GetContext(); context.User = response.User; contextProvider.SetContext(context); } return(response); }
public string Post([FromBody] RequestPayload requestMessage) { try { contextProvider.SetContext(requestMessage.Context); FlowConfiguration configuration = flowConfigurationProvider.GetConfiguration(requestMessage.Action); ValidationHelper.ExecuteValidations(configuration, requestMessage.Request); BaseResponse response = flowProvider.ExecuteFlow(serviceProvider, requestMessage.Action, requestMessage.Request); ResponsePayload responseMessage = new ResponsePayload { Context = contextProvider.GetContext(), Response = response }; return(responseMessage.ToJson()); } catch (Exception e) { try { JMResult result = serviceProvider.GetRequiredService <IExceptionHandler>().HandleException(e); Context context = contextProvider.GetContext(); context.ActiveResult = result; return(new ResponsePayload { Context = context, Response = null }.ToJson()); } catch (Exception innerException) { DefaultLogger.Error(innerException); return(new ResponsePayload().ToJson()); } } }
protected override void OnStartProcessingRequest(ProcessRequestArgs args) { // If already logged in via Forms Auth, just return if (ContextProvider.CurrentUserProfile != null) { return; } if (!args.OperationContext.RequestHeaders.AllKeys.Contains("Authorization")) { CreateNotAuthorizedResponse(401, 1, "Authorization headers missing."); HttpContext.Current.ApplicationInstance.Response.End(); return; } var credentials = GetCredentialsFromHeader(args.OperationContext.RequestHeaders["Authorization"]); if (credentials == null) { CreateNotAuthorizedResponse(403, 1, "Wrong credentials header."); HttpContext.Current.ApplicationInstance.Response.End(); return; } // UserName can be in the form of just UserName, UserName\CustomerNumber or UserName\CustomerNumber\CustomerSequence var loginInfo = credentials[0].Split('\\'); var userName = loginInfo[0]; var customerNumber = ""; var customerSequence = ""; if (loginInfo.Length > 1) { customerNumber = loginInfo[1]; } if (loginInfo.Length > 2) { customerSequence = loginInfo[2]; } var password = credentials[1]; if (!AuthenticationService.ValidateUser(ContextProvider.CurrentApplicationName, userName, password)) { CreateNotAuthorizedResponse(403, 1, "Wrong credentials."); HttpContext.Current.ApplicationInstance.Response.End(); return; } var userProfile = UserProfile.GetByUserName(userName); if (userProfile == null) { CreateNotAuthorizedResponse(403, 1, "UserProfile record missing."); HttpContext.Current.ApplicationInstance.Response.End(); return; } if (!string.IsNullOrEmpty(customerNumber)) { if (!CustomerUserProfile.GetTable().Any(cup => cup.UserProfile.Id == userProfile.Id && cup.Customer.CustomerNumber == customerNumber)) { CreateNotAuthorizedResponse(403, 1, "The supplied CustomerNumber is not associated with the supplied UserName."); HttpContext.Current.ApplicationInstance.Response.End(); return; } var customer = Customer.GetByNumber(customerNumber); ContextProvider.SetContext(customer); if (!string.IsNullOrEmpty(customerSequence)) { var shipTo = Customer.GetByNumberSequence(customerNumber, customerSequence); if (!CustomerInfo.GetTable().Any(c => c.CustomerNumber == customerNumber && c.CustomerSequence == customerSequence)) { CreateNotAuthorizedResponse(403, 1, "The supplied CustomerSequence is not associated with the supplied CustomerNumber."); HttpContext.Current.ApplicationInstance.Response.End(); return; } ContextProvider.SetContext(customer, shipTo); } } FormsAuthentication.SetAuthCookie(userName, true); HttpContext.Current.ApplicationInstance.Context.User = new GenericPrincipal(new GenericIdentity(userName), Roles.GetRolesForUser(userName)); }