private static async Task logException(TempLogSession sessionLog, Exception ex) { AppEventSeverity severity; string caption; if (ex is ValidationFailedException) { severity = AppEventSeverity.Values.ValidationFailed; caption = "Validation Failed"; } else if (ex is AccessDeniedException accessDeniedException) { severity = AppEventSeverity.Values.AccessDenied; caption = accessDeniedException.DisplayMessage; } else if (ex is AppException appException) { severity = AppEventSeverity.Values.AppError; caption = appException.DisplayMessage; } else { severity = AppEventSeverity.Values.CriticalError; caption = "An unexpected error occurred"; } await sessionLog.LogException(severity, ex, caption); }
private async Task handleError(HttpContext context, TempLogSession sessionLog, IHostEnvironment hostEnv, Exception ex) { await logException(sessionLog, ex); context.Response.StatusCode = getErrorStatusCode(ex); context.Response.ContentType = "application/json"; var errors = new ResultContainer <ErrorModel[]>(getErrors(hostEnv, ex)); var serializedErrors = JsonSerializer.Serialize(errors); await context.Response.WriteAsync(serializedErrors); }
public Authentication ( TempLogSession tempLog, UnverifiedUser unverifiedUser, IAccess access, IHashedPasswordFactory hashedPasswordFactory, CachedUserContext userContext ) { this.tempLog = tempLog; this.unverifiedUser = unverifiedUser; this.access = access; this.hashedPasswordFactory = hashedPasswordFactory; this.userContext = userContext; }
public LogoutAction(AccessForLogin access, TempLogSession tempLogSession, IHttpContextAccessor httpContextAccessor) { this.access = access; this.tempLogSession = tempLogSession; this.httpContextAccessor = httpContextAccessor; }
public async Task InvokeAsync(HttpContext context, CurrentSession currentSession, TempLogSession sessionLog, IAnonClient anonClient, IClock clock, IHostEnvironment hostEnv) { anonClient.Load(); if (isAnonSessionExpired(anonClient, clock)) { expireAnonSession(anonClient); } if (context.User.Identity?.IsAuthenticated == true) { currentSession.SessionKey = new XtiClaims(context).SessionKey(); } else { currentSession.SessionKey = anonClient.SessionKey; } var session = await sessionLog.StartSession(); if (anonClient.SessionKey != session.SessionKey) { anonClient.Persist(session.SessionKey, clock.Now().AddHours(4), session.RequesterKey); } await sessionLog.StartRequest($"{context.Request.PathBase}{context.Request.Path}"); try { await _next(context); } catch (Exception ex) { await handleError(context, sessionLog, hostEnv, ex); } finally { await sessionLog.EndRequest(); } }