public IActionResult GateNotFound(string username, AccessLogAction ala, string objectType, string objectValue) { LogUserAction(username, ala, objectValue, objectType, false); _logger.LogDebug((int)ala, "Failed to find '{0}' with identifier '{1}' for user '{2}'", objectType, objectValue, username); SaveChanges(); return(new NotFoundObjectResult(objectValue)); }
public IActionResult GateUnathorised(string username, AccessLogAction ala, string objectType, string objectValue) { LogUserAction(username, ala, objectValue, objectType, false); _logger.LogDebug((int)ala, "Unathorised to access '{0}' with identifier '{1}' for user '{2}'", objectType, objectValue, username); SaveChanges(); return(new UnauthorizedResult()); }
public AccessLogEntity(string user, AccessLogAction actionId, string targetId, string targetType, bool wasSucessfull) { this.User = user ?? throw new ArgumentNullException(nameof(user)); this.ActionId = actionId; this.TargetId = targetId; this.TargetType = targetType ?? throw new ArgumentNullException(nameof(targetType)); this.WasSucessfull = wasSucessfull; this.LoggedAt = DateTime.UtcNow; }
public IActionResult Gate(GateType gate, AccessLogAction logAction, string username, string objectType, string objectValue) { switch (gate) { case GateType.LockedByAnotherUser: LogUserAction(username, logAction, objectValue, objectType, false); SaveChanges(); _logger.LogDebug((int)logAction, "Failed to update '{0}' with identifier '{1}' for user '{2}'", objectType, objectValue, username); var res = new ContentResult { StatusCode = 409, ContentType = "text/plain", Content = "Document is Locked by another User" }; return(res); case GateType.CannotLock: LogUserAction(username, logAction, objectValue, objectType, false); SaveChanges(); _logger.LogDebug((int)logAction, "Failed to lock '{0}' with identifier '{1}' for user '{2}'", objectType, objectValue, username); return(new UnauthorizedResult()); case GateType.CannotUnlock: LogUserAction(username, logAction, objectValue, objectType, false); SaveChanges(); _logger.LogDebug((int)logAction, "Failed to unlock '{0}' with identifier '{1}' for user '{2}'", objectType, objectValue, username); return(new UnauthorizedResult()); case GateType.NotFound: LogUserAction(username, logAction, objectValue, objectType, false); SaveChanges(); _logger.LogDebug((int)logAction, "Failed to find '{0}' with identifier '{1}' for user '{2}'", objectType, objectValue, username); return(new NotFoundObjectResult(objectValue)); case GateType.Unathorised: LogUserAction(username, logAction, objectValue, objectType, false); SaveChanges(); _logger.LogDebug((int)logAction, "Unathorised to access '{0}' with identifier '{1}' for user '{2}'", objectType, objectValue, username); return(new UnauthorizedResult()); default: throw new NotImplementedException(); } }
public void LogUserAction(HttpContext context, AccessLogAction actionId, string targetId, string targetType, bool success) { _context.AccessLogEntities.Add(new AccessLogEntity(context.User.Identity.Name, actionId, targetId, targetType, success)); }
public void LogUserAction(string user, AccessLogAction actionId, string targetId, string targetType, bool success) { _context.AccessLogEntities.Add(new AccessLogEntity(user, actionId, targetId, targetType, success)); }