2019-11-01 18:38:54 +01:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 20:54:44 +01:00
|
|
|
using System;
|
2020-05-20 19:07:53 +02:00
|
|
|
using Jellyfin.Data.Entities;
|
2020-09-02 12:22:14 +02:00
|
|
|
using MediaBrowser.Common.Extensions;
|
2014-07-02 06:57:18 +02:00
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
using MediaBrowser.Controller.Session;
|
2020-09-02 12:22:14 +02:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2014-07-02 06:57:18 +02:00
|
|
|
|
2016-11-04 02:18:51 +01:00
|
|
|
namespace Emby.Server.Implementations.HttpServer.Security
|
2014-07-02 06:57:18 +02:00
|
|
|
{
|
|
|
|
public class SessionContext : ISessionContext
|
|
|
|
{
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
private readonly IAuthorizationContext _authContext;
|
|
|
|
|
|
|
|
public SessionContext(IUserManager userManager, IAuthorizationContext authContext, ISessionManager sessionManager)
|
|
|
|
{
|
|
|
|
_userManager = userManager;
|
|
|
|
_authContext = authContext;
|
|
|
|
_sessionManager = sessionManager;
|
|
|
|
}
|
|
|
|
|
2020-09-02 12:22:14 +02:00
|
|
|
public SessionInfo GetSession(HttpContext requestContext)
|
2014-07-02 06:57:18 +02:00
|
|
|
{
|
|
|
|
var authorization = _authContext.GetAuthorizationInfo(requestContext);
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
var user = authorization.User;
|
2020-09-10 14:16:41 +02:00
|
|
|
return _sessionManager.LogSessionActivity(authorization.Client, authorization.Version, authorization.DeviceId, authorization.Device, requestContext.GetNormalizedRemoteIp(), user);
|
2014-07-02 06:57:18 +02:00
|
|
|
}
|
2014-11-15 03:31:03 +01:00
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
public SessionInfo GetSession(object requestContext)
|
2014-11-15 03:31:03 +01:00
|
|
|
{
|
2020-09-02 12:22:14 +02:00
|
|
|
return GetSession((HttpContext)requestContext);
|
2014-11-15 03:31:03 +01:00
|
|
|
}
|
|
|
|
|
2020-09-02 12:22:14 +02:00
|
|
|
public User GetUser(HttpContext requestContext)
|
2015-03-09 20:40:03 +01:00
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
var session = GetSession(requestContext);
|
2015-03-09 20:40:03 +01:00
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
return session == null || session.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(session.UserId);
|
2015-03-09 20:40:03 +01:00
|
|
|
}
|
|
|
|
|
2020-05-20 19:07:53 +02:00
|
|
|
public User GetUser(object requestContext)
|
2014-11-15 03:31:03 +01:00
|
|
|
{
|
2020-12-16 06:17:04 +01:00
|
|
|
return GetUser(((HttpRequest)requestContext).HttpContext);
|
2014-11-15 03:31:03 +01:00
|
|
|
}
|
2014-07-02 06:57:18 +02:00
|
|
|
}
|
|
|
|
}
|