Added audit logging. Added admin view for audit log
This commit is contained in:
@@ -4,7 +4,9 @@ using JWT.Builder;
|
||||
using JWT.Exceptions;
|
||||
using Logging.Net;
|
||||
using Moonlight.App.Database.Entities;
|
||||
using Moonlight.App.Models.Misc;
|
||||
using Moonlight.App.Repositories;
|
||||
using Moonlight.App.Services.LogServices;
|
||||
using UAParser;
|
||||
|
||||
namespace Moonlight.App.Services.Sessions;
|
||||
@@ -13,6 +15,8 @@ public class IdentityService
|
||||
{
|
||||
private readonly UserRepository UserRepository;
|
||||
private readonly CookieService CookieService;
|
||||
private readonly SecurityLogService SecurityLogService;
|
||||
private readonly ErrorLogService ErrorLogService;
|
||||
private readonly IHttpContextAccessor HttpContextAccessor;
|
||||
private readonly string Secret;
|
||||
|
||||
@@ -22,11 +26,15 @@ public class IdentityService
|
||||
CookieService cookieService,
|
||||
UserRepository userRepository,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
ConfigService configService)
|
||||
ConfigService configService,
|
||||
SecurityLogService securityLogService,
|
||||
ErrorLogService errorLogService)
|
||||
{
|
||||
CookieService = cookieService;
|
||||
UserRepository = userRepository;
|
||||
HttpContextAccessor = httpContextAccessor;
|
||||
SecurityLogService = securityLogService;
|
||||
ErrorLogService = errorLogService;
|
||||
|
||||
Secret = configService
|
||||
.GetSection("Moonlight")
|
||||
@@ -81,14 +89,12 @@ public class IdentityService
|
||||
}
|
||||
catch (SignatureVerificationException)
|
||||
{
|
||||
//TODO: Heavy warn and write it to the logs
|
||||
Logger.Warn("Someone tried to modify his data: " + token);
|
||||
await SecurityLogService.Log(SecurityLogType.ManipulatedJwt, token);
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Warn("Error parsing and validating token");
|
||||
Logger.Warn(e);
|
||||
await ErrorLogService.Log(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -117,19 +123,14 @@ public class IdentityService
|
||||
var issuedAt = DateTimeOffset.FromUnixTimeSeconds(iat).DateTime;
|
||||
|
||||
if (issuedAt < user.TokenValidTime.ToUniversalTime())
|
||||
{
|
||||
//TODO: Remove at publish
|
||||
//Logger.Debug($"Old token found: {issuedAt.ToShortDateString()} {issuedAt.ToShortTimeString()} Current valid token time {userData.TokenValidTime.ToUniversalTime().ToShortDateString()} {userData.TokenValidTime.ToUniversalTime().ToShortTimeString()}");
|
||||
return null;
|
||||
}
|
||||
|
||||
UserCache = user;
|
||||
return UserCache;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Warn("Error loading user");
|
||||
Logger.Warn(e);
|
||||
await ErrorLogService.Log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user