2014-07-01 21:57:18 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
|
using ServiceStack.Web;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.HttpServer.Security
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
public SessionInfo GetSession(IServiceRequest requestContext)
|
2014-07-01 21:57:18 -07:00
|
|
|
|
{
|
|
|
|
|
var authorization = _authContext.GetAuthorizationInfo(requestContext);
|
|
|
|
|
|
|
|
|
|
return _sessionManager.GetSession(authorization.DeviceId, authorization.Client, authorization.Version);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 19:31:03 -07:00
|
|
|
|
public User GetUser(IServiceRequest requestContext)
|
2014-07-01 21:57:18 -07:00
|
|
|
|
{
|
|
|
|
|
var session = GetSession(requestContext);
|
|
|
|
|
|
|
|
|
|
return session == null || !session.UserId.HasValue ? null : _userManager.GetUserById(session.UserId.Value);
|
|
|
|
|
}
|
2014-11-14 19:31:03 -07:00
|
|
|
|
|
|
|
|
|
public SessionInfo GetSession(object requestContext)
|
|
|
|
|
{
|
|
|
|
|
var req = new ServiceStackServiceRequest((IRequest)requestContext);
|
|
|
|
|
return GetSession(req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public User GetUser(object requestContext)
|
|
|
|
|
{
|
|
|
|
|
var req = new ServiceStackServiceRequest((IRequest)requestContext);
|
|
|
|
|
return GetUser(req);
|
|
|
|
|
}
|
2014-07-01 21:57:18 -07:00
|
|
|
|
}
|
|
|
|
|
}
|