|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Jellyfin.Data.Entities;
|
|
|
|
|
using Jellyfin.Data.Events;
|
|
|
|
|
using MediaBrowser.Controller.Authentication;
|
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
using MediaBrowser.Model.Activity;
|
|
|
|
|
using MediaBrowser.Model.Globalization;
|
|
|
|
|
|
|
|
|
|
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>>
|
|
|
|
|
{
|
|
|
|
|
private readonly ILocalizationManager _localizationManager;
|
|
|
|
|
private readonly IActivityManager _activityManager;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="AuthenticationSucceededLogger"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="localizationManager">The localization manager.</param>
|
|
|
|
|
/// <param name="activityManager">The activity manager.</param>
|
|
|
|
|
public AuthenticationSucceededLogger(ILocalizationManager localizationManager, IActivityManager activityManager)
|
|
|
|
|
{
|
|
|
|
|
_localizationManager = localizationManager;
|
|
|
|
|
_activityManager = activityManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task OnEvent(GenericEventArgs<AuthenticationResult> eventArgs)
|
|
|
|
|
{
|
|
|
|
|
await _activityManager.CreateAsync(new ActivityLog(
|
|
|
|
|
string.Format(
|
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
|
_localizationManager.GetLocalizedString("AuthenticationSucceededWithUserName"),
|
|
|
|
|
eventArgs.Argument.User.Name),
|
|
|
|
|
"AuthenticationSucceeded",
|
|
|
|
|
eventArgs.Argument.User.Id)
|
|
|
|
|
{
|
|
|
|
|
ShortOverview = string.Format(
|
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
|
_localizationManager.GetLocalizedString("LabelIpAddressValue"),
|
|
|
|
|
eventArgs.Argument.SessionInfo.RemoteEndPoint),
|
|
|
|
|
}).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|