2014-07-02 04:57:18 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.Services;
|
2014-07-02 04:57:18 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Net
|
|
|
|
|
{
|
2016-10-26 06:01:42 +00:00
|
|
|
|
public class LoggedAttribute : IRequestFilter
|
2014-07-02 04:57:18 +00:00
|
|
|
|
{
|
2016-10-26 06:01:42 +00:00
|
|
|
|
public LoggedAttribute(ILogger logger, IUserManager userManager, ISessionManager sessionManager, IAuthorizationContext authorizationContext)
|
|
|
|
|
{
|
|
|
|
|
Logger = logger;
|
|
|
|
|
UserManager = userManager;
|
|
|
|
|
SessionManager = sessionManager;
|
|
|
|
|
AuthorizationContext = authorizationContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ILogger Logger { get; private set; }
|
|
|
|
|
public IUserManager UserManager { get; private set; }
|
|
|
|
|
public ISessionManager SessionManager { get; private set; }
|
|
|
|
|
public IAuthorizationContext AuthorizationContext { get; private set; }
|
2014-07-02 04:57:18 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The request filter is executed before the service.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The http request wrapper</param>
|
|
|
|
|
/// <param name="response">The http response wrapper</param>
|
|
|
|
|
/// <param name="requestDto">The request DTO</param>
|
2016-10-26 06:01:42 +00:00
|
|
|
|
public void Filter(IRequest request, IResponse response, object requestDto)
|
2014-07-02 04:57:18 +00:00
|
|
|
|
{
|
|
|
|
|
//This code is executed before the service
|
2017-09-03 18:38:26 +00:00
|
|
|
|
var auth = AuthorizationContext.GetAuthorizationInfo(request);
|
2014-07-02 04:57:18 +00:00
|
|
|
|
|
|
|
|
|
if (auth != null)
|
|
|
|
|
{
|
|
|
|
|
User user = null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(auth.UserId))
|
|
|
|
|
{
|
|
|
|
|
var userId = auth.UserId;
|
|
|
|
|
|
2014-09-14 15:10:51 +00:00
|
|
|
|
user = UserManager.GetUserById(userId);
|
2014-07-02 04:57:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string deviceId = auth.DeviceId;
|
|
|
|
|
string device = auth.Device;
|
|
|
|
|
string client = auth.Client;
|
|
|
|
|
string version = auth.Version;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(client) && !string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(device) && !string.IsNullOrEmpty(version))
|
|
|
|
|
{
|
|
|
|
|
var remoteEndPoint = request.RemoteIp;
|
|
|
|
|
|
|
|
|
|
SessionManager.LogSessionActivity(client, version, deviceId, device, remoteEndPoint, user);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|