The Free Software Media System - Server Backend & API
Add wrapper object for authentication event information
Shadowghost958f8f71e817
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.csindex 5f6dc93fb3..f26cc56636 100644--- a/Emby.Server.Implementations/Session/SessionManager.cs+++ b/Emby.Server.Implementations/Session/SessionManager.cs@@ -24,6 +24,7 @@ using MediaBrowser.Controller.Drawing;using MediaBrowser.Controller.Dto;using MediaBrowser.Controller.Entities;using MediaBrowser.Controller.Events;+using MediaBrowser.Controller.Events.Authentication;using MediaBrowser.Controller.Events.Session;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Net;@@ -1462,7 +1463,7 @@ namespace Emby.Server.Implementations.Sessionif (user is null){- await _eventManager.PublishAsync(new GenericEventArgs<AuthenticationRequest>(request)).ConfigureAwait(false);+ await _eventManager.PublishAsync(new GenericEventArgs<AuthenticationRequestEventArgs>(new AuthenticationRequestEventArgs(request))).ConfigureAwait(false);throw new AuthenticationException("Invalid username or password entered.");}@@ -1498,7 +1499,7 @@ namespace Emby.Server.Implementations.SessionServerId = _appHost.SystemId};- await _eventManager.PublishAsync(new GenericEventArgs<AuthenticationResult>(returnResult)).ConfigureAwait(false);+ await _eventManager.PublishAsync(new GenericEventArgs<AuthenticationResultEventArgs>(new AuthenticationResultEventArgs(returnResult))).ConfigureAwait(false);return returnResult;}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationFailedLogger.cs b/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationFailedLogger.csindex f899b4497a..f4835a585f 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationFailedLogger.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationFailedLogger.cs@@ -4,7 +4,7 @@ using System.Threading.Tasks;using Jellyfin.Data.Entities;using Jellyfin.Data.Events;using MediaBrowser.Controller.Events;-using MediaBrowser.Controller.Session;+using MediaBrowser.Controller.Events.Authentication;using MediaBrowser.Model.Activity;using MediaBrowser.Model.Globalization;using Microsoft.Extensions.Logging;@@ -14,7 +14,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Security/// <summary>/// Creates an entry in the activity log when there is a failed login attempt./// </summary>- public class AuthenticationFailedLogger : IEventConsumer<GenericEventArgs<AuthenticationRequest>>+ public class AuthenticationFailedLogger : IEventConsumer<GenericEventArgs<AuthenticationRequestEventArgs>>{private readonly ILocalizationManager _localizationManager;private readonly IActivityManager _activityManager;@@ -31,7 +31,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Security}/// <inheritdoc />- public async Task OnEvent(GenericEventArgs<AuthenticationRequest> eventArgs)+ public async Task OnEvent(GenericEventArgs<AuthenticationRequestEventArgs> eventArgs){await _activityManager.CreateAsync(new ActivityLog(string.Format(diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationSucceededLogger.cs b/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationSucceededLogger.csindex 8b0bd84c66..fe2737bafc 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationSucceededLogger.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationSucceededLogger.cs@@ -2,8 +2,8 @@using System.Threading.Tasks;using Jellyfin.Data.Entities;using Jellyfin.Data.Events;-using MediaBrowser.Controller.Authentication;using MediaBrowser.Controller.Events;+using MediaBrowser.Controller.Events.Authentication;using MediaBrowser.Model.Activity;using MediaBrowser.Model.Globalization;@@ -12,7 +12,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Security/// <summary>/// Creates an entry in the activity log when there is a successful login attempt./// </summary>- public class AuthenticationSucceededLogger : IEventConsumer<GenericEventArgs<AuthenticationResult>>+ public class AuthenticationSucceededLogger : IEventConsumer<GenericEventArgs<AuthenticationResultEventArgs>>{private readonly ILocalizationManager _localizationManager;private readonly IActivityManager _activityManager;@@ -29,7 +29,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Security}/// <inheritdoc />- public async Task OnEvent(GenericEventArgs<AuthenticationResult> eventArgs)+ public async Task OnEvent(GenericEventArgs<AuthenticationResultEventArgs> eventArgs){await _activityManager.CreateAsync(new ActivityLog(string.Format(@@ -42,7 +42,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.SecurityShortOverview = string.Format(CultureInfo.InvariantCulture,_localizationManager.GetLocalizedString("LabelIpAddressValue"),- eventArgs.Argument.SessionInfo.RemoteEndPoint),+ eventArgs.Argument.SessionInfo?.RemoteEndPoint),}).ConfigureAwait(false);}}diff --git a/Jellyfin.Server.Implementations/Events/EventingServiceCollectionExtensions.cs b/Jellyfin.Server.Implementations/Events/EventingServiceCollectionExtensions.csindex 5d558189b1..93ab15e24b 100644--- a/Jellyfin.Server.Implementations/Events/EventingServiceCollectionExtensions.cs+++ b/Jellyfin.Server.Implementations/Events/EventingServiceCollectionExtensions.cs@@ -8,12 +8,11 @@ using Jellyfin.Server.Implementations.Events.Consumers.System;using Jellyfin.Server.Implementations.Events.Consumers.Updates;using Jellyfin.Server.Implementations.Events.Consumers.Users;using MediaBrowser.Common.Updates;-using MediaBrowser.Controller.Authentication;using MediaBrowser.Controller.Events;+using MediaBrowser.Controller.Events.Authentication;using MediaBrowser.Controller.Events.Session;using MediaBrowser.Controller.Events.Updates;using MediaBrowser.Controller.Library;-using MediaBrowser.Controller.Session;using MediaBrowser.Controller.Subtitles;using MediaBrowser.Model.Tasks;using Microsoft.Extensions.DependencyInjection;@@ -35,8 +34,8 @@ namespace Jellyfin.Server.Implementations.Eventscollection.AddScoped<IEventConsumer<SubtitleDownloadFailureEventArgs>, SubtitleDownloadFailureLogger>();// Security consumers- collection.AddScoped<IEventConsumer<GenericEventArgs<AuthenticationRequest>>, AuthenticationFailedLogger>();- collection.AddScoped<IEventConsumer<GenericEventArgs<AuthenticationResult>>, AuthenticationSucceededLogger>();+ collection.AddScoped<IEventConsumer<GenericEventArgs<AuthenticationRequestEventArgs>>, AuthenticationFailedLogger>();+ collection.AddScoped<IEventConsumer<GenericEventArgs<AuthenticationResultEventArgs>>, AuthenticationSucceededLogger>();// Session consumerscollection.AddScoped<IEventConsumer<PlaybackStartEventArgs>, PlaybackStartLogger>();diff --git a/MediaBrowser.Controller/Events/Authentication/AuthenticationRequestEventArgs.cs b/MediaBrowser.Controller/Events/Authentication/AuthenticationRequestEventArgs.csnew file mode 100644index 0000000000..c0d8a277bd--- /dev/null+++ b/MediaBrowser.Controller/Events/Authentication/AuthenticationRequestEventArgs.cs@@ -0,0 +1,60 @@+using System;+using MediaBrowser.Controller.Session;++namespace MediaBrowser.Controller.Events.Authentication;++/// <summary>+/// A class representing an authentication result event.+/// </summary>+public class AuthenticationRequestEventArgs+{+ /// <summary>+ /// Initializes a new instance of the <see cref="AuthenticationRequestEventArgs"/> class.+ /// </summary>+ /// <param name="request">The <see cref="AuthenticationRequest"/>.</param>+ public AuthenticationRequestEventArgs(AuthenticationRequest request)+ {+ Username = request.Username;+ UserId = request.UserId;+ App = request.App;+ AppVersion = request.AppVersion;+ DeviceId = request.DeviceId;+ DeviceName = request.DeviceName;+ RemoteEndPoint = request.RemoteEndPoint;+ }++ /// <summary>+ /// Gets or sets the user name.+ /// </summary>+ public string? Username { get; set; }++ /// <summary>+ /// Gets or sets the user id.+ /// </summary>+ public Guid? UserId { get; set; }++ /// <summary>+ /// Gets or sets the app.+ /// </summary>+ public string? App { get; set; }++ /// <summary>+ /// Gets or sets the app version.+ /// </summary>+ public string? AppVersion { get; set; }++ /// <summary>+ /// Gets or sets the device id.+ /// </summary>+ public string? DeviceId { get; set; }++ /// <summary>+ /// Gets or sets the device name.+ /// </summary>+ public string? DeviceName { get; set; }++ /// <summary>+ /// Gets or sets the remote endpoint.+ /// </summary>+ public string? RemoteEndPoint { get; set; }+}diff --git a/MediaBrowser.Controller/Events/Authentication/AuthenticationResultEventArgs.cs b/MediaBrowser.Controller/Events/Authentication/AuthenticationResultEventArgs.csnew file mode 100644index 0000000000..5564fa1cef--- /dev/null+++ b/MediaBrowser.Controller/Events/Authentication/AuthenticationResultEventArgs.cs@@ -0,0 +1,37 @@+using MediaBrowser.Controller.Authentication;+using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Dto;++namespace MediaBrowser.Controller.Events.Authentication;++/// <summary>+/// A class representing an authentication result event.+/// </summary>+public class AuthenticationResultEventArgs+{+ /// <summary>+ /// Initializes a new instance of the <see cref="AuthenticationResultEventArgs"/> class.+ /// </summary>+ /// <param name="result">The <see cref="AuthenticationResult"/>.</param>+ public AuthenticationResultEventArgs(AuthenticationResult result)+ {+ User = result.User;+ SessionInfo = result.SessionInfo;+ ServerId = result.ServerId;+ }++ /// <summary>+ /// Gets or sets the user.+ /// </summary>+ public UserDto User { get; set; }++ /// <summary>+ /// Gets or sets the session information.+ /// </summary>+ public SessionInfo? SessionInfo { get; set; }++ /// <summary>+ /// Gets or sets the server id.+ /// </summary>+ public string? ServerId { get; set; }+}