Avoid usage of IOHelper in GlobalSettings

This commit is contained in:
Bjarke Berg
2020-03-13 10:00:03 +01:00
parent 6fafe0408d
commit ea15fdb14e
31 changed files with 99 additions and 82 deletions

View File

@@ -29,11 +29,12 @@ namespace Umbraco.Core.Configuration
public IUserPasswordConfiguration UserPasswordConfigurationSettings { get; } = new UserPasswordConfigurationSettings();
public IMemberPasswordConfiguration MemberPasswordConfigurationSettings { get; } = new MemberPasswordConfigurationSettings();
public IContentSettings ContentSettings { get; } = new ContentSettings();
public IGlobalSettings GlobalSettings { get; } = new GlobalSettings();
public Configs Create(IIOHelper ioHelper, ILogger logger)
{
var configs = new Configs(section => ConfigurationManager.GetSection(section));
configs.Add<IGlobalSettings>(() => new GlobalSettings(ioHelper));
configs.Add<IGlobalSettings>(() => GlobalSettings);
configs.Add(() => HostingSettings);
configs.Add<IHealthChecks>("umbracoConfiguration/HealthChecks");
@@ -61,7 +62,7 @@ namespace Umbraco.Core.Configuration
configs.Add<IMemberPasswordConfiguration>(() => MemberPasswordConfigurationSettings);
configs.Add<IContentSettings>(() => ContentSettings);
configs.AddCoreConfigs(ioHelper);
configs.AddCoreConfigs();
return configs;
}
}

View File

@@ -3,6 +3,7 @@ using System.Configuration;
using System.Linq;
using System.Net.Mail;
using System.Xml.Linq;
using Umbraco.Composing;
using Umbraco.Configuration;
using Umbraco.Core.IO;
@@ -64,7 +65,6 @@ namespace Umbraco.Core.Configuration
/// </summary>
public class GlobalSettings : IGlobalSettings
{
private readonly IIOHelper _ioHelper;
// TODO these should not be static
private static string _reservedPaths;
@@ -74,11 +74,6 @@ namespace Umbraco.Core.Configuration
internal const string StaticReservedPaths = "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; //must end with a comma!
internal const string StaticReservedUrls = "~/config/splashes/noNodes.aspx,~/.well-known,"; //must end with a comma!
public GlobalSettings(IIOHelper ioHelper)
{
_ioHelper = ioHelper;
}
/// <summary>
/// Used in unit testing to reset all config items that were set with property setters (i.e. did not come from config)
/// </summary>
@@ -203,15 +198,7 @@ namespace Umbraco.Core.Configuration
/// Gets the path to umbraco's root directory (/umbraco by default).
/// </summary>
/// <value>The path.</value>
public string Path
{
get
{
return ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.Path)
? _ioHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path])
: string.Empty;
}
}
public string Path => ConfigurationManager.AppSettings[Constants.AppSettings.Path];
/// <summary>
/// Gets or sets the configuration status. This will return the version number of the currently installed umbraco instance.
@@ -227,7 +214,7 @@ namespace Umbraco.Core.Configuration
}
set
{
SaveSetting(Constants.AppSettings.ConfigurationStatus, value, _ioHelper);
SaveSetting(Constants.AppSettings.ConfigurationStatus, value, Current.IOHelper); //TODO remove
}
}
@@ -254,7 +241,7 @@ namespace Umbraco.Core.Configuration
ConfigurationManager.RefreshSection("appSettings");
}
/// <summary>
/// Gets the time out in minutes.
/// </summary>

View File

@@ -52,15 +52,13 @@ namespace Umbraco.Core
public static ICoreDebug CoreDebug(this Configs configs)
=> configs.GetConfig<ICoreDebug>();
public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper)
public static void AddCoreConfigs(this Configs configs)
{
var configDir = new DirectoryInfo(ioHelper.MapPath(Constants.SystemDirectories.Config));
// GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition
configs.Add<IGridConfig>(factory => new GridConfig(
factory.GetInstance<ILogger>(),
factory.GetInstance<AppCaches>(),
configDir,
new DirectoryInfo(factory.GetInstance<IIOHelper>().MapPath(Constants.SystemDirectories.Config)),
factory.GetInstance<IManifestParser>(),
factory.GetInstance<IRuntimeState>().Debug));
}

View File

@@ -28,14 +28,15 @@ namespace Umbraco.Core.Configuration
return _mvcArea;
}
//TODO Move to IOHelper
internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings, IIOHelper ioHelper)
{
if (globalSettings.Path.IsNullOrWhiteSpace())
if (ioHelper.BackOfficePath.IsNullOrWhiteSpace())
{
throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified");
}
var path = globalSettings.Path;
var path = ioHelper.BackOfficePath;
if (path.StartsWith(ioHelper.Root)) // beware of TrimStart, see U4-2518
path = path.Substring(ioHelper.Root.Length);
return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower();

View File

@@ -21,7 +21,7 @@
string ReservedPaths { get; }
/// <summary>
/// Gets the path to umbraco's root directory (/umbraco by default).
/// Gets the path to umbraco's root directory.
/// </summary>
string Path { get; }

View File

@@ -4,6 +4,9 @@ namespace Umbraco.Core.IO
{
public interface IIOHelper
{
string BackOfficePath { get; }
bool ForceNotHosted { get; set; }
char DirSepChar { get; }

View File

@@ -4,6 +4,7 @@ using System.Globalization;
using System.Reflection;
using System.IO;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.Strings;
@@ -12,10 +13,22 @@ namespace Umbraco.Core.IO
public class IOHelper : IIOHelper
{
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IGlobalSettings _globalSettings;
public IOHelper(IHostingEnvironment hostingEnvironment)
public IOHelper(IHostingEnvironment hostingEnvironment, IGlobalSettings globalSettings)
{
_hostingEnvironment = hostingEnvironment;
_globalSettings = globalSettings;
}
public string BackOfficePath
{
get
{
var path = _globalSettings.Path;
return string.IsNullOrEmpty(path) ? string.Empty : ResolveUrl(path);
}
}
/// <summary>

View File

@@ -49,7 +49,7 @@ namespace Umbraco.Core
var urlPath = fullUrlPath.TrimStart(appPath).EnsureStartsWith('/');
//check if this is in the umbraco back office
var isUmbracoPath = urlPath.InvariantStartsWith(globalSettings.Path.EnsureStartsWith('/').TrimStart(appPath.EnsureStartsWith('/')).EnsureStartsWith('/'));
var isUmbracoPath = urlPath.InvariantStartsWith(ioHelper.BackOfficePath.EnsureStartsWith('/').TrimStart(appPath.EnsureStartsWith('/')).EnsureStartsWith('/'));
//if not, then def not back office
if (isUmbracoPath == false) return false;
@@ -127,12 +127,12 @@ namespace Umbraco.Core
/// <param name="url"></param>
/// <param name="globalSettings"></param>
/// <returns></returns>
internal static bool IsDefaultBackOfficeRequest(this Uri url, IGlobalSettings globalSettings)
internal static bool IsDefaultBackOfficeRequest(this Uri url, IIOHelper ioHelper)
{
if (url.AbsolutePath.InvariantEquals(globalSettings.Path.TrimEnd("/"))
|| url.AbsolutePath.InvariantEquals(globalSettings.Path.EnsureEndsWith('/'))
|| url.AbsolutePath.InvariantEquals(globalSettings.Path.EnsureEndsWith('/') + "Default")
|| url.AbsolutePath.InvariantEquals(globalSettings.Path.EnsureEndsWith('/') + "Default/"))
if (url.AbsolutePath.InvariantEquals(ioHelper.BackOfficePath.TrimEnd("/"))
|| url.AbsolutePath.InvariantEquals(ioHelper.BackOfficePath.EnsureEndsWith('/'))
|| url.AbsolutePath.InvariantEquals(ioHelper.BackOfficePath.EnsureEndsWith('/') + "Default")
|| url.AbsolutePath.InvariantEquals(ioHelper.BackOfficePath.EnsureEndsWith('/') + "Default/"))
{
return true;
}

View File

@@ -191,7 +191,7 @@ namespace Umbraco.Web.Models.Mapping
target.Icon = source.Icon;
target.IconFilePath = target.IconIsClass
? string.Empty
: $"{_globalSettings.Path.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
: $"{_ioHelper.BackOfficePath.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
target.Trashed = source.Trashed;
target.Id = source.Id;
@@ -497,7 +497,7 @@ namespace Umbraco.Web.Models.Mapping
target.Icon = source.Icon;
target.IconFilePath = target.IconIsClass
? string.Empty
: $"{_globalSettings.Path.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
: $"{_ioHelper.BackOfficePath.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
target.Id = source.Id;
target.IsContainer = source.IsContainer;
target.IsElement = source.IsElement;
@@ -540,7 +540,7 @@ namespace Umbraco.Web.Models.Mapping
target.Icon = source.Icon;
target.IconFilePath = target.IconIsClass
? string.Empty
: $"{_globalSettings.Path.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
: $"{_ioHelper.BackOfficePath.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
target.Id = source.Id;
target.IsContainer = source.IsContainer;
target.IsElement = source.IsElement;

View File

@@ -112,7 +112,7 @@ namespace Umbraco.Web.Models.Trees
return Current.IOHelper.ResolveUrl("~" + Icon.TrimStart('~'));
//legacy icon path
return string.Format("{0}images/umbraco/{1}", Current.Configs.Global().Path.EnsureEndsWith("/"), Icon);
return string.Format("{0}images/umbraco/{1}", Current.IOHelper.BackOfficePath.EnsureEndsWith("/"), Icon);
}
}

View File

@@ -1,4 +1,5 @@
using Moq;
using Semver;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -13,14 +14,16 @@ namespace Umbraco.Tests.Common
{
}
public IGlobalSettings GenerateMockGlobalSettings(IUmbracoVersion umbVersion, IIOHelper ioHelper)
public IGlobalSettings GenerateMockGlobalSettings(IUmbracoVersion umbVersion = null)
{
var semanticVersion = umbVersion?.SemanticVersion ?? new SemVersion(9);
var config = Mock.Of<IGlobalSettings>(
settings =>
settings.ConfigurationStatus == umbVersion.SemanticVersion.ToSemanticString() &&
settings.ConfigurationStatus == semanticVersion.ToSemanticString() &&
settings.UseHttps == false &&
settings.HideTopLevelNodeFromPath == false &&
settings.Path == ioHelper.ResolveUrl("~/umbraco") &&
settings.Path == "~/umbraco" &&
settings.TimeOutInMinutes == 20 &&
settings.DefaultUILanguage == "en" &&
settings.ReservedPaths == (GlobalSettings.StaticReservedPaths + "~/umbraco") &&
@@ -102,12 +105,12 @@ namespace Umbraco.Tests.Common
private IGlobalSettings _defaultGlobalSettings;
private IHostingSettings _defaultHostingSettings;
public IGlobalSettings GetDefaultGlobalSettings(IUmbracoVersion umbVersion, IIOHelper ioHelper)
public IGlobalSettings GetDefaultGlobalSettings(IUmbracoVersion umbVersion)
{
if (_defaultGlobalSettings == null)
{
_defaultGlobalSettings = GenerateMockGlobalSettings(umbVersion, ioHelper);
_defaultGlobalSettings = GenerateMockGlobalSettings(umbVersion);
}
return _defaultGlobalSettings;
}

View File

@@ -30,15 +30,15 @@ namespace Umbraco.Tests.Common
public TestHelperBase()
{
SettingsForTests = new SettingsForTests();
IOHelper = new IOHelper(GetHostingEnvironment());
IOHelper = new IOHelper(GetHostingEnvironment(), SettingsForTests.GenerateMockGlobalSettings());
MainDom = new MainDom(Mock.Of<ILogger>(), GetHostingEnvironment(), new MainDomSemaphoreLock(Mock.Of<ILogger>(), GetHostingEnvironment()));
UriUtility = new UriUtility(GetHostingEnvironment());
UriUtility = new UriUtility(GetHostingEnvironment());
}
public ITypeFinder GetTypeFinder()
{
var typeFinder = new TypeFinder(Mock.Of<ILogger>(),
var typeFinder = new TypeFinder(Mock.Of<ILogger>(),
new DefaultUmbracoAssemblyProvider(typeof(TestHelperBase).Assembly));
return typeFinder;
}

View File

@@ -1,6 +1,7 @@
using Moq;
using NUnit.Framework;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.Configurations
@@ -30,13 +31,15 @@ namespace Umbraco.Tests.Configurations
[TestCase("~/some-wacky/nestedPath", "/MyVirtualDir/NestedVDir/", "some-wacky-nestedpath")]
public void Umbraco_Mvc_Area(string path, string rootPath, string outcome)
{
var globalSettings = SettingsForTests.GenerateMockGlobalSettings();
var ioHelper = new IOHelper(TestHelper.GetHostingEnvironment(), globalSettings);
var globalSettingsMock = Mock.Get(globalSettings);
globalSettingsMock.Setup(x => x.Path).Returns(() => TestHelper.IOHelper.ResolveUrl(path));
globalSettingsMock.Setup(x => x.Path).Returns(() => path);
TestHelper.IOHelper.Root = rootPath;
Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(IOHelper));
ioHelper.Root = rootPath;
Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(ioHelper));
}

View File

@@ -61,7 +61,7 @@ namespace Umbraco.Tests.PublishedContent
var configs = TestHelper.GetConfigs();
Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs);
var globalSettings = new GlobalSettings(TestHelper.IOHelper);
var globalSettings = new GlobalSettings();
var hostingEnvironment = Mock.Of<IHostingEnvironment>();
configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings);
configs.Add<IGlobalSettings>(() => globalSettings);

View File

@@ -54,7 +54,7 @@ namespace Umbraco.Tests.PublishedContent
var configs = TestHelper.GetConfigs();
Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs);
var globalSettings = new GlobalSettings(TestHelper.IOHelper);
var globalSettings = new GlobalSettings();
configs.Add(TestHelpers.SettingsForTests.GenerateMockContentSettings);
configs.Add<IGlobalSettings>(() => globalSettings);

View File

@@ -37,14 +37,14 @@ namespace Umbraco.Tests.Routing
_module = new UmbracoInjectedModule
(
globalSettings,
runtime,
logger,
null, // FIXME: PublishedRouter complexities...
Mock.Of<IUmbracoContextFactory>(),
new RoutableDocumentFilter(globalSettings, IOHelper),
UriUtility,
AppCaches.RequestCache
AppCaches.RequestCache,
IOHelper
);
runtime.Level = RuntimeLevel.Run;

View File

@@ -7,7 +7,7 @@ namespace Umbraco.Tests.TestHelpers
{
private static Common.SettingsForTests _settingsForTests = new Common.SettingsForTests();
public static IGlobalSettings GenerateMockGlobalSettings() => _settingsForTests.GenerateMockGlobalSettings(TestHelper.GetUmbracoVersion(), TestHelper.IOHelper);
public static IGlobalSettings GenerateMockGlobalSettings() => _settingsForTests.GenerateMockGlobalSettings(TestHelper.GetUmbracoVersion());
/// <summary>
/// Returns generated settings which can be stubbed to return whatever values necessary
@@ -45,7 +45,7 @@ namespace Umbraco.Tests.TestHelpers
public static void Reset() => _settingsForTests.Reset();
internal static IGlobalSettings GetDefaultGlobalSettings() => _settingsForTests.GetDefaultGlobalSettings(TestHelper.GetUmbracoVersion(), TestHelper.IOHelper);
internal static IGlobalSettings GetDefaultGlobalSettings() => _settingsForTests.GetDefaultGlobalSettings(TestHelper.GetUmbracoVersion());
internal static IHostingSettings GetDefaultHostingSettings() => _settingsForTests.GetDefaultHostingSettings();

View File

@@ -51,7 +51,7 @@ namespace Umbraco.Tests.TestHelpers
public override IBackOfficeInfo GetBackOfficeInfo()
=> new AspNetBackOfficeInfo(
SettingsForTests.GenerateMockGlobalSettings(GetUmbracoVersion(), IOHelper),
SettingsForTests.GenerateMockGlobalSettings(GetUmbracoVersion()),
TestHelper.IOHelper, Mock.Of<ILogger>(), SettingsForTests.GenerateMockWebRoutingSettings());
public override IHostingEnvironment GetHostingEnvironment()

View File

@@ -40,13 +40,14 @@ namespace Umbraco.Web.BackOffice.AspNetCore
var hostingSettings = configFactory.HostingSettings;
var coreDebug = configFactory.CoreDebug;
var globalSettings = configFactory.GlobalSettings;
var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment, httpContextAccessor, hostApplicationLifetime);
var ioHelper = new IOHelper(hostingEnvironment);
var ioHelper = new IOHelper(hostingEnvironment, globalSettings);
var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, new AspNetCoreSessionIdResolver(httpContextAccessor), () => services.BuildServiceProvider().GetService<IRequestCache>(), coreDebug, ioHelper, new AspNetCoreMarchal());
var configs = configFactory.Create(ioHelper, logger);
var backOfficeInfo = new AspNetCoreBackOfficeInfo(configs.Global());
var backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings);
var profiler = new LogProfiler(logger);
Current.Initialize(logger, configs, ioHelper, hostingEnvironment, backOfficeInfo, profiler);

View File

@@ -17,7 +17,7 @@
<html lang="en">
<head>
<base href="@Model.GlobalSettings.Path.EnsureEndsWith('/')" />
<base href="@Model.IOHelper.BackOfficePath.EnsureEndsWith('/')" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

View File

@@ -28,7 +28,7 @@
<html lang="en">
<head>
<base href="@Model.GlobalSettings.Path.EnsureEndsWith('/')" />
<base href="@Model.IOHelper.BackOfficePath.EnsureEndsWith('/')" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">

View File

@@ -104,8 +104,8 @@ namespace Umbraco.Web.Editors
public async Task<ActionResult> Default()
{
return await RenderDefaultOrProcessExternalLoginAsync(
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings,_ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)),
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings, _ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)));
() => View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings,_ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)),
() => View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings, _ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)));
}
[HttpGet]
@@ -188,7 +188,7 @@ namespace Umbraco.Web.Editors
{
return await RenderDefaultOrProcessExternalLoginAsync(
//The default view to render when there is no external login info or errors
() => View(GlobalSettings.Path.EnsureEndsWith('/') + "Views/AuthorizeUpgrade.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings, _ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)),
() => View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "Views/AuthorizeUpgrade.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings, _ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)),
//The ActionResult to perform if external login is successful
() => Redirect("/"));
}

View File

@@ -344,7 +344,7 @@ namespace Umbraco.Web.Editors
{
"umbracoSettings", new Dictionary<string, object>
{
{"umbracoPath", _globalSettings.Path},
{"umbracoPath", _ioHelper.BackOfficePath},
{"mediaPath", _ioHelper.ResolveUrl(globalSettings.UmbracoMediaPath).TrimEnd('/')},
{"appPluginsPath", _ioHelper.ResolveUrl(Constants.SystemDirectories.AppPlugins).TrimEnd('/')},
{

View File

@@ -88,7 +88,7 @@ namespace Umbraco.Web.Editors
}
}
return View(_globalSettings.Path.EnsureEndsWith('/') + "Views/Preview/" + "Index.cshtml", model);
return View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "Views/Preview/" + "Index.cshtml", model);
}
/// <summary>

View File

@@ -74,7 +74,7 @@ namespace Umbraco.Web.Install.Controllers
_installHelper.InstallStatus(false, "");
// always ensure full path (see NOTE in the class remarks)
return View(_globalSettings.Path.EnsureEndsWith('/') + "install/views/index.cshtml");
return View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "install/views/index.cshtml");
}
}
}

View File

@@ -57,7 +57,7 @@ namespace Umbraco.Web.Mvc
{
if (redirectToUmbracoLogin)
{
_redirectUrl = Current.Configs.Global().Path.EnsureStartsWith("~");
_redirectUrl = Current.IOHelper.BackOfficePath.EnsureStartsWith("~");
}
}

View File

@@ -235,7 +235,7 @@ namespace Umbraco.Web.Security
var cookieAuthOptions = app.CreateUmbracoCookieAuthOptions(
umbracoContextAccessor, globalSettings, runtimeState, securitySettings,
//This defines the explicit path read cookies from for this middleware
ioHelper, requestCache, new[] {$"{globalSettings.Path}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"});
ioHelper, requestCache, new[] {$"{ioHelper.BackOfficePath}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"});
cookieAuthOptions.Provider = cookieOptions.Provider;
//This is a custom middleware, we need to return the user's remaining logged in seconds
@@ -243,7 +243,8 @@ namespace Umbraco.Web.Security
cookieAuthOptions,
Current.Configs.Global(),
Current.Configs.Security(),
app.CreateLogger<GetUserSecondsMiddleWare>());
app.CreateLogger<GetUserSecondsMiddleWare>(),
Current.IOHelper);
//This is required so that we can read the auth ticket format outside of this pipeline
app.CreatePerOwinContext<UmbracoAuthTicketDataProtector>(

View File

@@ -41,7 +41,7 @@ namespace Umbraco.Web.Security
_ioHelper = ioHelper;
_requestCache = requestCache;
_explicitPaths = explicitPaths?.ToArray();
_getRemainingSecondsPath = $"{globalSettings.Path}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds";
_getRemainingSecondsPath = $"{ioHelper.BackOfficePath}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds";
}
/// <summary>

View File

@@ -8,6 +8,7 @@ using Microsoft.Owin.Logging;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Security;
namespace Umbraco.Web.Security
@@ -26,19 +27,22 @@ namespace Umbraco.Web.Security
private readonly IGlobalSettings _globalSettings;
private readonly ISecuritySettings _security;
private readonly ILogger _logger;
private readonly IIOHelper _ioHelper;
public GetUserSecondsMiddleWare(
OwinMiddleware next,
UmbracoBackOfficeCookieAuthOptions authOptions,
IGlobalSettings globalSettings,
ISecuritySettings security,
ILogger logger)
ILogger logger,
IIOHelper ioHelper)
: base(next)
{
_authOptions = authOptions ?? throw new ArgumentNullException(nameof(authOptions));
_globalSettings = globalSettings;
_security = security;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_ioHelper = ioHelper;
}
public override async Task Invoke(IOwinContext context)
@@ -48,7 +52,7 @@ namespace Umbraco.Web.Security
if (request.Uri.Scheme.InvariantStartsWith("http")
&& request.Uri.AbsolutePath.InvariantEquals(
$"{_globalSettings.Path}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"))
$"{_ioHelper.BackOfficePath}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"))
{
var cookie = _authOptions.CookieManager.GetRequestCookie(context, _security.AuthCookieName);
if (cookie.IsNullOrWhiteSpace() == false)

View File

@@ -35,13 +35,14 @@ namespace Umbraco.Web
var hostingSettings = configFactory.HostingSettings;
var coreDebug = configFactory.CoreDebug;
var globalSettings = configFactory.GlobalSettings;
var hostingEnvironment = new AspNetHostingEnvironment(hostingSettings);
var ioHelper = new IOHelper(hostingEnvironment);
var ioHelper = new IOHelper(hostingEnvironment, globalSettings);
var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, new AspNetSessionManager(), () => _factory?.GetInstance<IRequestCache>(), coreDebug, ioHelper, new FrameworkMarchal());
var configs = configFactory.Create(ioHelper, logger);
var backOfficeInfo = new AspNetBackOfficeInfo(configs.Global(), ioHelper, logger, configFactory.WebRoutingSettings);
var backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, ioHelper, logger, configFactory.WebRoutingSettings);
var profiler = new LogProfiler(logger);
Umbraco.Composing.Current.Initialize(logger, configs, ioHelper, hostingEnvironment, backOfficeInfo, profiler);
}

View File

@@ -6,6 +6,7 @@ using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Web.Composing;
using Umbraco.Web.Routing;
@@ -30,26 +31,25 @@ namespace Umbraco.Web
/// </remarks>
public class UmbracoInjectedModule : IHttpModule
{
private readonly IGlobalSettings _globalSettings;
private readonly IRuntimeState _runtime;
private readonly ILogger _logger;
private readonly IPublishedRouter _publishedRouter;
private readonly IUmbracoContextFactory _umbracoContextFactory;
private readonly RoutableDocumentFilter _routableDocumentLookup;
private readonly IRequestCache _requestCache;
private readonly IIOHelper _ioHelper;
private readonly UriUtility _uriUtility;
public UmbracoInjectedModule(
IGlobalSettings globalSettings,
IRuntimeState runtime,
ILogger logger,
IPublishedRouter publishedRouter,
IUmbracoContextFactory umbracoContextFactory,
RoutableDocumentFilter routableDocumentLookup,
UriUtility uriUtility,
IRequestCache requestCache)
IRequestCache requestCache,
IIOHelper ioHelper)
{
_globalSettings = globalSettings;
_runtime = runtime;
_logger = logger;
_publishedRouter = publishedRouter;
@@ -57,6 +57,7 @@ namespace Umbraco.Web
_routableDocumentLookup = routableDocumentLookup;
_uriUtility = uriUtility;
_requestCache = requestCache;
_ioHelper = ioHelper;
}
#region HttpModule event handlers
@@ -110,7 +111,7 @@ namespace Umbraco.Web
var umbracoContext = Current.UmbracoContext;
// re-write for the default back office path
if (httpContext.Request.Url.IsDefaultBackOfficeRequest(_globalSettings))
if (httpContext.Request.Url.IsDefaultBackOfficeRequest(_ioHelper))
{
if (EnsureRuntime(httpContext, umbracoContext.OriginalRequestUrl))
RewriteToBackOfficeHandler(httpContext);
@@ -256,7 +257,7 @@ namespace Umbraco.Web
private void RewriteToBackOfficeHandler(HttpContextBase context)
{
// GlobalSettings.Path has already been through IOHelper.ResolveUrl() so it begins with / and vdir (if any)
var rewritePath = _globalSettings.Path.TrimEnd('/') + "/Default";
var rewritePath = _ioHelper.BackOfficePath.TrimEnd('/') + "/Default";
// rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc)
context.RewritePath(rewritePath, "", "", false);
@@ -289,7 +290,7 @@ namespace Umbraco.Web
var query = pcr.Uri.Query.TrimStart('?');
// GlobalSettings.Path has already been through IOHelper.ResolveUrl() so it begins with / and vdir (if any)
var rewritePath = _globalSettings.Path.TrimEnd('/') + "/RenderMvc";
var rewritePath = _ioHelper.BackOfficePath.TrimEnd('/') + "/RenderMvc";
// rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc)
context.RewritePath(rewritePath, "", query, false);