mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-30 09:19:04 +02:00
run all ajax through apiclient
This commit is contained in:
parent
389390b82e
commit
9bab99d4d8
|
@ -1,4 +1,7 @@
|
||||||
using MediaBrowser.Controller.Net;
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Net;
|
||||||
|
using MediaBrowser.Controller.Session;
|
||||||
using ServiceStack;
|
using ServiceStack;
|
||||||
using ServiceStack.Auth;
|
using ServiceStack.Auth;
|
||||||
using ServiceStack.Web;
|
using ServiceStack.Web;
|
||||||
|
@ -10,6 +13,17 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
|
||||||
{
|
{
|
||||||
public class AuthService : IAuthService
|
public class AuthService : IAuthService
|
||||||
{
|
{
|
||||||
|
public AuthService(IUserManager userManager, ISessionManager sessionManager, IAuthorizationContext authorizationContext)
|
||||||
|
{
|
||||||
|
AuthorizationContext = authorizationContext;
|
||||||
|
SessionManager = sessionManager;
|
||||||
|
UserManager = userManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IUserManager UserManager { get; private set; }
|
||||||
|
public ISessionManager SessionManager { get; private set; }
|
||||||
|
public IAuthorizationContext AuthorizationContext { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restrict authentication to a specific <see cref="IAuthProvider"/>.
|
/// Restrict authentication to a specific <see cref="IAuthProvider"/>.
|
||||||
/// For example, if this attribute should only permit access
|
/// For example, if this attribute should only permit access
|
||||||
|
@ -37,7 +51,32 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
|
||||||
|
|
||||||
private void ValidateUser(IRequest req)
|
private void ValidateUser(IRequest req)
|
||||||
{
|
{
|
||||||
var user = req.TryResolve<ISessionContext>().GetUser(req);
|
User user = null;
|
||||||
|
|
||||||
|
//This code is executed before the service
|
||||||
|
var auth = AuthorizationContext.GetAuthorizationInfo(req);
|
||||||
|
|
||||||
|
if (auth != null)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(auth.UserId))
|
||||||
|
{
|
||||||
|
var userId = auth.UserId;
|
||||||
|
|
||||||
|
user = UserManager.GetUserById(new Guid(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = req.RemoteIp;
|
||||||
|
|
||||||
|
SessionManager.LogSessionActivity(client, version, deviceId, device, remoteEndPoint, user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (user == null || user.Configuration.IsDisabled)
|
if (user == null || user.Configuration.IsDisabled)
|
||||||
{
|
{
|
||||||
|
@ -74,6 +113,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LogRequest()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected bool DoHtmlRedirectIfConfigured(IRequest req, IResponse res, bool includeRedirectParam = false)
|
protected bool DoHtmlRedirectIfConfigured(IRequest req, IResponse res, bool includeRedirectParam = false)
|
||||||
{
|
{
|
||||||
var htmlRedirect = this.HtmlRedirect ?? AuthenticateService.HtmlRedirect;
|
var htmlRedirect = this.HtmlRedirect ?? AuthenticateService.HtmlRedirect;
|
||||||
|
|
|
@ -671,7 +671,7 @@ namespace MediaBrowser.ServerApplication
|
||||||
var authContext = new AuthorizationContext();
|
var authContext = new AuthorizationContext();
|
||||||
RegisterSingleInstance<IAuthorizationContext>(authContext);
|
RegisterSingleInstance<IAuthorizationContext>(authContext);
|
||||||
RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
|
RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
|
||||||
RegisterSingleInstance<IAuthService>(new AuthService());
|
RegisterSingleInstance<IAuthService>(new AuthService(UserManager, SessionManager, authContext));
|
||||||
|
|
||||||
RegisterSingleInstance<ISubtitleEncoder>(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder));
|
RegisterSingleInstance<ISubtitleEncoder>(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue