From e84ba17b9f48a3bc8811b1a89c54c25bc6607599 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 10 Aug 2014 18:13:17 -0400 Subject: add activity log feature --- .../Session/SessionManager.cs | 51 ++++++++++++---------- 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Session/SessionManager.cs') diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 61c65cfd6c..7db6d01919 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -14,11 +14,13 @@ using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Events; using MediaBrowser.Model.Library; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Session; using MediaBrowser.Model.Users; +using MediaBrowser.Server.Implementations.Security; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -27,7 +29,6 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Server.Implementations.Security; namespace MediaBrowser.Server.Implementations.Session { @@ -76,6 +77,10 @@ namespace MediaBrowser.Server.Implementations.Session private readonly ConcurrentDictionary _activeConnections = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + public event EventHandler> AuthenticationFailed; + + public event EventHandler> AuthenticationSucceeded; + /// /// Occurs when [playback start]. /// @@ -399,6 +404,11 @@ namespace MediaBrowser.Server.Implementations.Session Id = Guid.NewGuid().ToString("N") }; + sessionInfo.DeviceName = deviceName; + sessionInfo.UserId = userId; + sessionInfo.UserName = username; + sessionInfo.RemoteEndPoint = remoteEndPoint; + OnSessionStarted(sessionInfo); return sessionInfo; @@ -1191,44 +1201,37 @@ namespace MediaBrowser.Server.Implementations.Session /// /// Authenticates the new session. /// - /// The username. - /// The password. - /// Type of the client. - /// The application version. - /// The device identifier. - /// Name of the device. - /// The remote end point. + /// The request. /// if set to true [is local]. /// Task{SessionInfo}. + /// Invalid user or password entered. /// Invalid user or password entered. /// Invalid user or password entered. - public async Task AuthenticateNewSession(string username, - string password, - string clientType, - string appVersion, - string deviceId, - string deviceName, - string remoteEndPoint, + public async Task AuthenticateNewSession(AuthenticationRequest request, bool isLocal) { - var result = (isLocal && string.Equals(clientType, "Dashboard", StringComparison.OrdinalIgnoreCase)) || - await _userManager.AuthenticateUser(username, password).ConfigureAwait(false); + var result = (isLocal && string.Equals(request.App, "Dashboard", StringComparison.OrdinalIgnoreCase)) || + await _userManager.AuthenticateUser(request.Username, request.Password).ConfigureAwait(false); if (!result) { + EventHelper.FireEventIfNotNull(AuthenticationFailed, this, new GenericEventArgs(request), _logger); + throw new AuthenticationException("Invalid user or password entered."); } var user = _userManager.Users - .First(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase)); + .First(i => string.Equals(request.Username, i.Name, StringComparison.OrdinalIgnoreCase)); - var token = await GetAuthorizationToken(user.Id.ToString("N"), deviceId, clientType, deviceName).ConfigureAwait(false); + var token = await GetAuthorizationToken(user.Id.ToString("N"), request.DeviceId, request.App, request.DeviceName).ConfigureAwait(false); - var session = await LogSessionActivity(clientType, - appVersion, - deviceId, - deviceName, - remoteEndPoint, + EventHelper.FireEventIfNotNull(AuthenticationSucceeded, this, new GenericEventArgs(request), _logger); + + var session = await LogSessionActivity(request.App, + request.AppVersion, + request.DeviceId, + request.DeviceName, + request.RemoteEndPoint, user) .ConfigureAwait(false); -- cgit v1.2.3