The Free Software Media System - Server Backend & API
Migrate ActivityLogEntryPoint.OnAuthenticationFailed to IEventConsumer
Patrick Barronbff05d71861b
diff --git a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.csindex 0000195d86..8279503ec8 100644--- a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs+++ b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs@@ -12,7 +12,6 @@ using MediaBrowser.Model.Activity;using MediaBrowser.Model.Globalization;using MediaBrowser.Model.Notifications;using MediaBrowser.Model.Updates;-using Microsoft.Extensions.Logging;namespace Emby.Server.Implementations.Activity{@@ -54,7 +53,6 @@ namespace Emby.Server.Implementations.Activity_installationManager.PackageInstallationFailed += OnPackageInstallationFailed;_sessionManager.SessionStarted += OnSessionStarted;- _sessionManager.AuthenticationFailed += OnAuthenticationFailed;_sessionManager.AuthenticationSucceeded += OnAuthenticationSucceeded;_sessionManager.SessionEnded += OnSessionEnded;@@ -105,24 +103,6 @@ namespace Emby.Server.Implementations.Activity}).ConfigureAwait(false);}- private async void OnAuthenticationFailed(object sender, GenericEventArgs<AuthenticationRequest> e)- {- await CreateLogEntry(new ActivityLog(- string.Format(- CultureInfo.InvariantCulture,- _localization.GetLocalizedString("FailedLoginAttemptWithUserName"),- e.Argument.Username),- "AuthenticationFailed",- Guid.Empty)- {- LogSeverity = LogLevel.Error,- ShortOverview = string.Format(- CultureInfo.InvariantCulture,- _localization.GetLocalizedString("LabelIpAddressValue"),- e.Argument.RemoteEndPoint),- }).ConfigureAwait(false);- }-private async void OnSessionStarted(object sender, SessionEventArgs e){var session = e.SessionInfo;@@ -227,7 +207,6 @@ namespace Emby.Server.Implementations.Activity_installationManager.PackageInstallationFailed -= OnPackageInstallationFailed;_sessionManager.SessionStarted -= OnSessionStarted;- _sessionManager.AuthenticationFailed -= OnAuthenticationFailed;_sessionManager.AuthenticationSucceeded -= OnAuthenticationSucceeded;_sessionManager.SessionEnded -= OnSessionEnded;}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationFailedLogger.cs b/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationFailedLogger.csnew file mode 100644index 0000000000..f899b4497a--- /dev/null+++ b/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationFailedLogger.cs@@ -0,0 +1,52 @@+using System;+using System.Globalization;+using System.Threading.Tasks;+using Jellyfin.Data.Entities;+using Jellyfin.Data.Events;+using MediaBrowser.Controller.Events;+using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Activity;+using MediaBrowser.Model.Globalization;+using Microsoft.Extensions.Logging;++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>>+ {+ private readonly ILocalizationManager _localizationManager;+ private readonly IActivityManager _activityManager;++ /// <summary>+ /// Initializes a new instance of the <see cref="AuthenticationFailedLogger"/> class.+ /// </summary>+ /// <param name="localizationManager">The localization manager.</param>+ /// <param name="activityManager">The activity manager.</param>+ public AuthenticationFailedLogger(ILocalizationManager localizationManager, IActivityManager activityManager)+ {+ _localizationManager = localizationManager;+ _activityManager = activityManager;+ }++ /// <inheritdoc />+ public async Task OnEvent(GenericEventArgs<AuthenticationRequest> eventArgs)+ {+ await _activityManager.CreateAsync(new ActivityLog(+ string.Format(+ CultureInfo.InvariantCulture,+ _localizationManager.GetLocalizedString("FailedLoginAttemptWithUserName"),+ eventArgs.Argument.Username),+ "AuthenticationFailed",+ Guid.Empty)+ {+ LogSeverity = LogLevel.Error,+ ShortOverview = string.Format(+ CultureInfo.InvariantCulture,+ _localizationManager.GetLocalizedString("LabelIpAddressValue"),+ eventArgs.Argument.RemoteEndPoint),+ }).ConfigureAwait(false);+ }+ }+}