Huge IIOHelper cleanup, removes some overlap with IHostingEnvironment, much less usages of IIOHelper and instead just use what is already available on IHostingEnvironment
This commit is contained in:
@@ -19,6 +19,8 @@ namespace Umbraco.Core.Configuration.Legacy
|
||||
}
|
||||
}
|
||||
|
||||
public string ApplicationVirtualPath => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco is running in [debug mode].
|
||||
/// </summary>
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace Umbraco.Configuration.Models
|
||||
public LocalTempStorage LocalTempStorageLocation =>
|
||||
_configuration.GetValue(Prefix+"LocalTempStorage", LocalTempStorage.Default);
|
||||
|
||||
public string ApplicationVirtualPath => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco is running in [debug mode].
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Umbraco.Core.Hosting;
|
||||
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
public static class GlobalSettingsExtensions
|
||||
{
|
||||
private static string _mvcArea;
|
||||
private static string _backOfficePath;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the absolute path for the Umbraco back office
|
||||
/// </summary>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetBackOfficePath(this IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
if (_backOfficePath != null) return _backOfficePath;
|
||||
_backOfficePath = hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath);
|
||||
return _backOfficePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This returns the string of the MVC Area route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This will return the MVC area that we will route all custom routes through like surface controllers, etc...
|
||||
/// We will use the 'Path' (default ~/umbraco) to create it but since it cannot contain '/' and people may specify a path of ~/asdf/asdf/admin
|
||||
/// we will convert the '/' to '-' and use that as the path. its a bit lame but will work.
|
||||
///
|
||||
/// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something
|
||||
/// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco".
|
||||
/// </remarks>
|
||||
public static string GetUmbracoMvcArea(this IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
if (_mvcArea != null) return _mvcArea;
|
||||
|
||||
_mvcArea = globalSettings.GetUmbracoMvcAreaNoCache(hostingEnvironment);
|
||||
|
||||
return _mvcArea;
|
||||
}
|
||||
|
||||
internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var path = string.IsNullOrEmpty(globalSettings.UmbracoPath)
|
||||
? string.Empty
|
||||
: hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath);
|
||||
|
||||
if (path.IsNullOrWhiteSpace())
|
||||
throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified");
|
||||
|
||||
if (path.StartsWith(hostingEnvironment.ApplicationVirtualPath)) // beware of TrimStart, see U4-2518
|
||||
path = path.Substring(hostingEnvironment.ApplicationVirtualPath.Length);
|
||||
return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,24 @@
|
||||
using Umbraco.Core.Hosting;
|
||||
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
public interface IHostingSettings
|
||||
{
|
||||
bool DebugMode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the configuration for the location of temporary files.
|
||||
/// </summary>
|
||||
LocalTempStorage LocalTempStorageLocation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional property to explicitly configure the application's virtual path
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default this is null which will mean that the <see cref="IHostingEnvironment.ApplicationVirtualPath"/> is automatically configured,
|
||||
/// otherwise this explicitly sets it.
|
||||
/// If set, this value must begin with a "/" and cannot end with "/".
|
||||
/// </remarks>
|
||||
string ApplicationVirtualPath { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,23 @@ namespace Umbraco.Core.Hosting
|
||||
string ApplicationPhysicalPath { get; }
|
||||
|
||||
string LocalTempPath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The web application's hosted path
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// In most cases this will return "/" but if the site is hosted in a virtual directory then this will return the virtual directory's path such as "/mysite".
|
||||
/// This value must begin with a "/" and cannot end with "/".
|
||||
/// </remarks>
|
||||
string ApplicationVirtualPath { get; }
|
||||
|
||||
bool IsDebugMode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether Umbraco is hosted.
|
||||
/// </summary>
|
||||
bool IsHosted { get; }
|
||||
|
||||
Version IISVersion { get; }
|
||||
string MapPath(string path);
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@ namespace Umbraco.Core.IO
|
||||
{
|
||||
public interface IIOHelper
|
||||
{
|
||||
|
||||
string BackOfficePath { get; }
|
||||
|
||||
// TODO: There is no need for this, we should just use Path.DirectorySeparatorChar which is cross platform, no need for an abstraction?
|
||||
char DirSepChar { get; }
|
||||
|
||||
string FindFile(string virtualPath);
|
||||
|
||||
// TODO: This is the same as IHostingEnvironment.ToAbsolute
|
||||
@@ -57,12 +56,5 @@ namespace Umbraco.Core.IO
|
||||
/// <returns></returns>
|
||||
string GetRelativePath(string path);
|
||||
|
||||
// TODO: This is the same as IHostingEnvironment.ApplicationVirtualPath i don't think we want this
|
||||
string Root
|
||||
{
|
||||
get;
|
||||
set; //Only required for unit tests
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,29 +13,15 @@ namespace Umbraco.Core.IO
|
||||
public class IOHelper : IIOHelper
|
||||
{
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
|
||||
public IOHelper(IHostingEnvironment hostingEnvironment, IGlobalSettings globalSettings)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
public string BackOfficePath
|
||||
{
|
||||
get
|
||||
{
|
||||
var path = _globalSettings.UmbracoPath;
|
||||
|
||||
return string.IsNullOrEmpty(path) ? string.Empty : ResolveUrl(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// static compiled regex for faster performance
|
||||
//private static readonly Regex ResolveUrlPattern = new Regex("(=[\"\']?)(\\W?\\~(?:.(?![\"\']?\\s+(?:\\S+)=|[>\"\']))+.)[\"\']?", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
|
||||
public char DirSepChar => Path.DirectorySeparatorChar;
|
||||
|
||||
//helper to try and match the old path to a new virtual one
|
||||
@@ -44,10 +30,10 @@ namespace Umbraco.Core.IO
|
||||
string retval = virtualPath;
|
||||
|
||||
if (virtualPath.StartsWith("~"))
|
||||
retval = virtualPath.Replace("~", Root);
|
||||
retval = virtualPath.Replace("~", _hostingEnvironment.ApplicationVirtualPath);
|
||||
|
||||
if (virtualPath.StartsWith("/") && virtualPath.StartsWith(Root) == false)
|
||||
retval = Root + "/" + virtualPath.TrimStart('/');
|
||||
if (virtualPath.StartsWith("/") && virtualPath.StartsWith(_hostingEnvironment.ApplicationVirtualPath) == false)
|
||||
retval = _hostingEnvironment.ApplicationVirtualPath + "/" + virtualPath.TrimStart('/');
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -65,7 +51,7 @@ namespace Umbraco.Core.IO
|
||||
try
|
||||
{
|
||||
if (virtualPath.StartsWith("~"))
|
||||
return Attempt.Succeed(virtualPath.Replace("~", Root).Replace("//", "/"));
|
||||
return Attempt.Succeed(virtualPath.Replace("~", _hostingEnvironment.ApplicationVirtualPath).Replace("//", "/"));
|
||||
if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute))
|
||||
return Attempt.Succeed(virtualPath);
|
||||
|
||||
@@ -93,8 +79,8 @@ namespace Umbraco.Core.IO
|
||||
|
||||
if (_hostingEnvironment.IsHosted)
|
||||
{
|
||||
var result = (String.IsNullOrEmpty(path) == false && (path.StartsWith("~") || path.StartsWith(Root)))
|
||||
? _hostingEnvironment.MapPath(path)
|
||||
var result = (!string.IsNullOrEmpty(path) && (path.StartsWith("~") || path.StartsWith(_hostingEnvironment.ApplicationVirtualPath)))
|
||||
? _hostingEnvironment.MapPath(path)
|
||||
: _hostingEnvironment.MapPath("~/" + path.TrimStart('/'));
|
||||
|
||||
if (result != null) return result;
|
||||
@@ -136,7 +122,7 @@ namespace Umbraco.Core.IO
|
||||
// TODO: what's below is dirty, there are too many ways to get the root dir, etc.
|
||||
// not going to fix everything today
|
||||
|
||||
var mappedRoot = MapPath(Root);
|
||||
var mappedRoot = MapPath(_hostingEnvironment.ApplicationVirtualPath);
|
||||
if (filePath.StartsWith(mappedRoot) == false)
|
||||
filePath = MapPath(filePath);
|
||||
|
||||
@@ -204,32 +190,5 @@ namespace Umbraco.Core.IO
|
||||
return PathUtility.EnsurePathIsApplicationRootPrefixed(path);
|
||||
}
|
||||
|
||||
private string _root;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root path of the application
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// In most cases this will be an empty string which indicates the app is not running in a virtual directory.
|
||||
/// This is NOT a physical path.
|
||||
/// </remarks>
|
||||
public string Root
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_root != null) return _root;
|
||||
|
||||
var appPath = _hostingEnvironment.ApplicationVirtualPath;
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
if (appPath == null || appPath == "/")
|
||||
appPath = string.Empty;
|
||||
|
||||
_root = appPath;
|
||||
|
||||
return _root;
|
||||
}
|
||||
//Only required for unit tests
|
||||
set => _root = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ namespace Umbraco.Core.IO
|
||||
{
|
||||
public static class IOHelperExtensions
|
||||
{
|
||||
private static string _mvcArea;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to create a directory.
|
||||
/// </summary>
|
||||
@@ -38,37 +36,6 @@ namespace Umbraco.Core.IO
|
||||
return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This returns the string of the MVC Area route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This will return the MVC area that we will route all custom routes through like surface controllers, etc...
|
||||
/// We will use the 'Path' (default ~/umbraco) to create it but since it cannot contain '/' and people may specify a path of ~/asdf/asdf/admin
|
||||
/// we will convert the '/' to '-' and use that as the path. its a bit lame but will work.
|
||||
///
|
||||
/// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something
|
||||
/// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco".
|
||||
/// </remarks>
|
||||
public static string GetUmbracoMvcArea(this IIOHelper ioHelper)
|
||||
{
|
||||
if (_mvcArea != null) return _mvcArea;
|
||||
|
||||
_mvcArea = GetUmbracoMvcAreaNoCache(ioHelper);
|
||||
|
||||
return _mvcArea;
|
||||
}
|
||||
|
||||
internal static string GetUmbracoMvcAreaNoCache(this IIOHelper ioHelper)
|
||||
{
|
||||
if (ioHelper.BackOfficePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Core
|
||||
@@ -16,44 +17,42 @@ namespace Umbraco.Core
|
||||
/// Checks if the current uri is a back office request
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="applicationPath">
|
||||
/// The current application path or VirtualPath
|
||||
/// </param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// There are some special routes we need to check to properly determine this:
|
||||
///
|
||||
///
|
||||
/// If any route has an extension in the path like .aspx = back office
|
||||
///
|
||||
///
|
||||
/// These are def back office:
|
||||
/// /Umbraco/BackOffice = back office
|
||||
/// /Umbraco/Preview = back office
|
||||
/// If it's not any of the above, and there's no extension then we cannot determine if it's back office or front-end
|
||||
/// so we can only assume that it is not back office. This will occur if people use an UmbracoApiController for the backoffice
|
||||
/// but do not inherit from UmbracoAuthorizedApiController and do not use [IsBackOffice] attribute.
|
||||
///
|
||||
///
|
||||
/// These are def front-end:
|
||||
/// /Umbraco/Surface = front-end
|
||||
/// /Umbraco/Api = front-end
|
||||
/// But if we've got this far we'll just have to assume it's front-end anyways.
|
||||
///
|
||||
///
|
||||
/// </remarks>
|
||||
internal static bool IsBackOfficeRequest(this Uri url, string applicationPath, IIOHelper ioHelper)
|
||||
internal static bool IsBackOfficeRequest(this Uri url, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
applicationPath = applicationPath ?? string.Empty;
|
||||
|
||||
var applicationPath = hostingEnvironment.ApplicationVirtualPath;
|
||||
|
||||
var fullUrlPath = url.AbsolutePath.TrimStart(new[] {'/'});
|
||||
var appPath = applicationPath.TrimStart(new[] {'/'});
|
||||
var urlPath = fullUrlPath.TrimStart(appPath).EnsureStartsWith('/');
|
||||
|
||||
//check if this is in the umbraco back office
|
||||
var isUmbracoPath = urlPath.InvariantStartsWith(ioHelper.BackOfficePath.EnsureStartsWith('/').TrimStart(appPath.EnsureStartsWith('/')).EnsureStartsWith('/'));
|
||||
var backOfficePath = globalSettings.GetBackOfficePath(hostingEnvironment);
|
||||
var isUmbracoPath = urlPath.InvariantStartsWith(backOfficePath.EnsureStartsWith('/').TrimStart(appPath.EnsureStartsWith('/')).EnsureStartsWith('/'));
|
||||
//if not, then def not back office
|
||||
if (isUmbracoPath == false) return false;
|
||||
|
||||
var mvcArea = ioHelper.GetUmbracoMvcArea();
|
||||
var mvcArea = globalSettings.GetUmbracoMvcArea(hostingEnvironment);
|
||||
//if its the normal /umbraco path
|
||||
if (urlPath.InvariantEquals("/" + mvcArea)
|
||||
|| urlPath.InvariantEquals("/" + mvcArea + "/"))
|
||||
@@ -108,9 +107,9 @@ namespace Umbraco.Core
|
||||
/// Checks if the current uri is an install request
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsInstallerRequest(this Uri url, IIOHelper ioHelper)
|
||||
internal static bool IsInstallerRequest(this Uri url, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var authority = url.GetLeftPart(UriPartial.Authority);
|
||||
var afterAuthority = url.GetLeftPart(UriPartial.Query)
|
||||
@@ -118,7 +117,7 @@ namespace Umbraco.Core
|
||||
.TrimStart("/");
|
||||
|
||||
//check if this is in the umbraco back office
|
||||
return afterAuthority.InvariantStartsWith(ioHelper.ResolveUrl("~/install").TrimStart("/"));
|
||||
return afterAuthority.InvariantStartsWith(hostingEnvironment.ToAbsolute("~/install").TrimStart("/"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -126,13 +125,15 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsDefaultBackOfficeRequest(this Uri url, IIOHelper ioHelper)
|
||||
internal static bool IsDefaultBackOfficeRequest(this Uri url, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
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/"))
|
||||
var backOfficePath = globalSettings.GetBackOfficePath(hostingEnvironment);
|
||||
if (url.AbsolutePath.InvariantEquals(backOfficePath.TrimEnd("/"))
|
||||
|| url.AbsolutePath.InvariantEquals(backOfficePath.EnsureEndsWith('/'))
|
||||
|| url.AbsolutePath.InvariantEquals(backOfficePath.EnsureEndsWith('/') + "Default")
|
||||
|| url.AbsolutePath.InvariantEquals(backOfficePath.EnsureEndsWith('/') + "Default/"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
@@ -28,13 +29,13 @@ namespace Umbraco.Web.Models.Mapping
|
||||
private readonly IMemberTypeService _memberTypeService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
|
||||
public ContentTypeMapDefinition(PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IFileService fileService,
|
||||
IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService,
|
||||
ILogger logger, IShortStringHelper shortStringHelper, IIOHelper ioHelper, IGlobalSettings globalSettings)
|
||||
ILogger logger, IShortStringHelper shortStringHelper, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_propertyEditors = propertyEditors;
|
||||
_dataTypeService = dataTypeService;
|
||||
@@ -44,8 +45,8 @@ namespace Umbraco.Web.Models.Mapping
|
||||
_memberTypeService = memberTypeService;
|
||||
_logger = logger;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
_ioHelper = ioHelper;
|
||||
_globalSettings = globalSettings;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
public void DefineMaps(UmbracoMapper mapper)
|
||||
@@ -191,7 +192,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
target.Icon = source.Icon;
|
||||
target.IconFilePath = target.IconIsClass
|
||||
? string.Empty
|
||||
: $"{_ioHelper.BackOfficePath.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
|
||||
: $"{_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith("/")}images/umbraco/{source.Icon}";
|
||||
|
||||
target.Trashed = source.Trashed;
|
||||
target.Id = source.Id;
|
||||
@@ -204,7 +205,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
target.Thumbnail = source.Thumbnail;
|
||||
target.ThumbnailFilePath = target.ThumbnailIsClass
|
||||
? string.Empty
|
||||
: _ioHelper.ResolveUrl("~/umbraco/images/thumbnails/" + source.Thumbnail);
|
||||
: _hostingEnvironment.ToAbsolute("~/umbraco/images/thumbnails/" + source.Thumbnail);
|
||||
target.UpdateDate = source.UpdateDate;
|
||||
}
|
||||
|
||||
@@ -497,7 +498,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
target.Icon = source.Icon;
|
||||
target.IconFilePath = target.IconIsClass
|
||||
? string.Empty
|
||||
: $"{_ioHelper.BackOfficePath.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
|
||||
: $"{_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith("/")}images/umbraco/{source.Icon}";
|
||||
target.Id = source.Id;
|
||||
target.IsContainer = source.IsContainer;
|
||||
target.IsElement = source.IsElement;
|
||||
@@ -508,7 +509,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
target.Thumbnail = source.Thumbnail;
|
||||
target.ThumbnailFilePath = target.ThumbnailIsClass
|
||||
? string.Empty
|
||||
: _ioHelper.ResolveUrl("~/umbraco/images/thumbnails/" + source.Thumbnail);
|
||||
: _hostingEnvironment.ToAbsolute("~/umbraco/images/thumbnails/" + source.Thumbnail);
|
||||
target.Udi = MapContentTypeUdi(source);
|
||||
target.UpdateDate = source.UpdateDate;
|
||||
|
||||
@@ -540,7 +541,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
target.Icon = source.Icon;
|
||||
target.IconFilePath = target.IconIsClass
|
||||
? string.Empty
|
||||
: $"{_ioHelper.BackOfficePath.EnsureEndsWith("/")}images/umbraco/{source.Icon}";
|
||||
: $"{_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith("/")}images/umbraco/{source.Icon}";
|
||||
target.Id = source.Id;
|
||||
target.IsContainer = source.IsContainer;
|
||||
target.IsElement = source.IsElement;
|
||||
@@ -551,7 +552,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
target.Thumbnail = source.Thumbnail;
|
||||
target.ThumbnailFilePath = target.ThumbnailIsClass
|
||||
? string.Empty
|
||||
: _ioHelper.ResolveUrl("~/umbraco/images/thumbnails/" + source.Thumbnail);
|
||||
: _hostingEnvironment.ToAbsolute("~/umbraco/images/thumbnails/" + source.Thumbnail);
|
||||
target.Trashed = source.Trashed;
|
||||
target.Udi = source.Udi;
|
||||
}
|
||||
|
||||
@@ -231,8 +231,6 @@ namespace Umbraco.Core.Runtime
|
||||
// throws if not full-trust
|
||||
_umbracoBootPermissionChecker.ThrowIfNotPermissions();
|
||||
|
||||
ConfigureApplicationRootPath();
|
||||
|
||||
// run handlers
|
||||
RuntimeOptions.DoRuntimeEssentials(_factory);
|
||||
|
||||
@@ -265,13 +263,6 @@ namespace Umbraco.Core.Runtime
|
||||
};
|
||||
}
|
||||
|
||||
protected virtual void ConfigureApplicationRootPath()
|
||||
{
|
||||
var path = GetApplicationRootPath();
|
||||
if (string.IsNullOrWhiteSpace(path) == false)
|
||||
IOHelper.Root = path;
|
||||
}
|
||||
|
||||
private bool AcquireMainDom(IMainDom mainDom, IApplicationShutdownRegistry applicationShutdownRegistry)
|
||||
{
|
||||
using (var timer = ProfilingLogger.DebugDuration<CoreRuntime>("Acquiring MainDom.", "Acquired."))
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Trees
|
||||
@@ -112,7 +113,8 @@ namespace Umbraco.Web.Models.Trees
|
||||
return Current.IOHelper.ResolveUrl("~" + Icon.TrimStart('~'));
|
||||
|
||||
//legacy icon path
|
||||
return string.Format("{0}images/umbraco/{1}", Current.IOHelper.BackOfficePath.EnsureEndsWith("/"), Icon);
|
||||
var backOfficePath = Current.Configs.Global().GetUmbracoMvcArea(Current.HostingEnvironment);
|
||||
return string.Format("{0}images/umbraco/{1}", backOfficePath.EnsureEndsWith("/"), Icon);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Web.WebAssets
|
||||
@@ -28,9 +29,9 @@ namespace Umbraco.Web.WebAssets
|
||||
/// The angular module name to boot
|
||||
/// </param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetJavascriptInitialization(IEnumerable<string> scripts, string angularModule, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
public static string GetJavascriptInitialization(IEnumerable<string> scripts, string angularModule, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var jarray = new StringBuilder();
|
||||
jarray.AppendLine("[");
|
||||
@@ -46,7 +47,7 @@ namespace Umbraco.Web.WebAssets
|
||||
}
|
||||
jarray.Append("]");
|
||||
|
||||
return WriteScript(jarray.ToString(), ioHelper.ResolveUrl(globalSettings.UmbracoPath), angularModule);
|
||||
return WriteScript(jarray.ToString(), hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath), angularModule);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Manifest;
|
||||
@@ -24,19 +25,22 @@ namespace Umbraco.Web.WebAssets
|
||||
|
||||
private readonly IRuntimeMinifier _runtimeMinifier;
|
||||
private readonly IManifestParser _parser;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly PropertyEditorCollection _propertyEditorCollection;
|
||||
|
||||
public BackOfficeWebAssets(
|
||||
IRuntimeMinifier runtimeMinifier,
|
||||
IManifestParser parser,
|
||||
IIOHelper ioHelper,
|
||||
PropertyEditorCollection propertyEditorCollection)
|
||||
PropertyEditorCollection propertyEditorCollection,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IGlobalSettings globalSettings)
|
||||
{
|
||||
_runtimeMinifier = runtimeMinifier;
|
||||
_parser = parser;
|
||||
_ioHelper = ioHelper;
|
||||
_propertyEditorCollection = propertyEditorCollection;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
public void CreateBundles()
|
||||
@@ -150,7 +154,7 @@ namespace Umbraco.Web.WebAssets
|
||||
/// <returns></returns>
|
||||
private string[] FormatPaths(params string[] assets)
|
||||
{
|
||||
var umbracoPath = _ioHelper.GetUmbracoMvcArea();
|
||||
var umbracoPath = _globalSettings.GetUmbracoMvcArea(_hostingEnvironment);
|
||||
|
||||
return assets
|
||||
.Where(x => x.IsNullOrWhiteSpace() == false)
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.WebAssets;
|
||||
|
||||
@@ -14,10 +15,10 @@ namespace Umbraco.Web.WebAssets
|
||||
/// Returns the JavaScript to load the back office's assets
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static async Task<string> GetScriptForLoadingBackOfficeAsync(this IRuntimeMinifier minifier, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
public static async Task<string> GetScriptForLoadingBackOfficeAsync(this IRuntimeMinifier minifier, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var files = await minifier.GetAssetPathsAsync(BackOfficeWebAssets.UmbracoJsBundleName);
|
||||
var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(files, "umbraco", globalSettings, ioHelper);
|
||||
var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(files, "umbraco", globalSettings, hostingEnvironment);
|
||||
result += await GetStylesheetInitializationAsync(minifier);
|
||||
|
||||
return result;
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace Umbraco.Tests.Cache
|
||||
new TestDefaultCultureAccessor(),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper,
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
@@ -79,10 +79,10 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
_umbracoContext = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
publishedSnapshotService.Object,
|
||||
new WebSecurity(httpContextAccessor, Mock.Of<IUserService>(), globalSettings, IOHelper),
|
||||
new WebSecurity(httpContextAccessor, Mock.Of<IUserService>(), globalSettings, HostingEnvironment),
|
||||
globalSettings,
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Hosting;
|
||||
|
||||
namespace Umbraco.Tests.Configurations
|
||||
{
|
||||
@@ -10,20 +11,6 @@ namespace Umbraco.Tests.Configurations
|
||||
[TestFixture]
|
||||
public class GlobalSettingsTests : BaseWebTest
|
||||
{
|
||||
private string _root;
|
||||
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
_root = TestHelper.IOHelper.Root;
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
TestHelper.IOHelper.Root = _root;
|
||||
}
|
||||
|
||||
[TestCase("~/umbraco", "/", "umbraco")]
|
||||
[TestCase("~/umbraco", "/MyVirtualDir", "umbraco")]
|
||||
[TestCase("~/customPath", "/MyVirtualDir/", "custompath")]
|
||||
@@ -33,18 +20,15 @@ namespace Umbraco.Tests.Configurations
|
||||
{
|
||||
|
||||
var globalSettings = SettingsForTests.GenerateMockGlobalSettings();
|
||||
var ioHelper = new IOHelper(TestHelper.GetHostingEnvironment(), globalSettings);
|
||||
var mockHostingSettings = Mock.Get(SettingsForTests.GetDefaultHostingSettings());
|
||||
mockHostingSettings.Setup(x => x.ApplicationVirtualPath).Returns(rootPath);
|
||||
|
||||
var hostingEnvironment = new AspNetHostingEnvironment(mockHostingSettings.Object);
|
||||
|
||||
var globalSettingsMock = Mock.Get(globalSettings);
|
||||
globalSettingsMock.Setup(x => x.UmbracoPath).Returns(() => path);
|
||||
|
||||
ioHelper.Root = rootPath;
|
||||
Assert.AreEqual(outcome, ioHelper.GetUmbracoMvcAreaNoCache());
|
||||
Assert.AreEqual(outcome, globalSettingsMock.Object.GetUmbracoMvcAreaNoCache(hostingEnvironment));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
using System;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Hosting;
|
||||
|
||||
namespace Umbraco.Tests.CoreThings
|
||||
{
|
||||
[TestFixture]
|
||||
public class UriExtensionsTests
|
||||
{
|
||||
private string _root;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_root = TestHelper.IOHelper.Root;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
TestHelper.IOHelper.Root = _root;
|
||||
}
|
||||
|
||||
[TestCase("http://www.domain.com/umbraco", "", true)]
|
||||
[TestCase("http://www.domain.com/Umbraco/", "", true)]
|
||||
@@ -45,10 +34,13 @@ namespace Umbraco.Tests.CoreThings
|
||||
[TestCase("http://www.domain.com/umbraco/test/legacyAjaxCalls.ashx?some=query&blah=js", "", true)]
|
||||
public void Is_Back_Office_Request(string input, string virtualPath, bool expected)
|
||||
{
|
||||
var ioHelper = TestHelper.IOHelper;
|
||||
ioHelper.Root = virtualPath;
|
||||
var globalSettings = SettingsForTests.GenerateMockGlobalSettings();
|
||||
var mockHostingSettings = Mock.Get(SettingsForTests.GetDefaultHostingSettings());
|
||||
mockHostingSettings.Setup(x => x.ApplicationVirtualPath).Returns(virtualPath);
|
||||
var hostingEnvironment = new AspNetHostingEnvironment(mockHostingSettings.Object);
|
||||
|
||||
var source = new Uri(input);
|
||||
Assert.AreEqual(expected, source.IsBackOfficeRequest(virtualPath, ioHelper));
|
||||
Assert.AreEqual(expected, source.IsBackOfficeRequest(globalSettings, hostingEnvironment));
|
||||
}
|
||||
|
||||
[TestCase("http://www.domain.com/install", true)]
|
||||
@@ -63,7 +55,7 @@ namespace Umbraco.Tests.CoreThings
|
||||
public void Is_Installer_Request(string input, bool expected)
|
||||
{
|
||||
var source = new Uri(input);
|
||||
Assert.AreEqual(expected, source.IsInstallerRequest(TestHelper.IOHelper));
|
||||
Assert.AreEqual(expected, source.IsInstallerRequest(TestHelper.GetHostingEnvironment()));
|
||||
}
|
||||
|
||||
[TestCase("http://www.domain.com/foo/bar", "/", "http://www.domain.com/")]
|
||||
|
||||
@@ -74,10 +74,10 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var umbracoContext = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
publishedSnapshotService.Object,
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, IOHelper),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, HostingEnvironment),
|
||||
globalSettings,
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Umbraco.Tests.Routing
|
||||
ShortStringHelper,
|
||||
new SurfaceControllerTypeCollection(Enumerable.Empty<Type>()),
|
||||
new UmbracoApiControllerTypeCollection(Enumerable.Empty<Type>()),
|
||||
IOHelper);
|
||||
HostingEnvironment);
|
||||
}
|
||||
|
||||
public class TestRuntime : WebRuntime
|
||||
|
||||
@@ -43,7 +43,8 @@ namespace Umbraco.Tests.Routing
|
||||
new RoutableDocumentFilter(globalSettings, IOHelper),
|
||||
UriUtility,
|
||||
AppCaches.RequestCache,
|
||||
IOHelper
|
||||
globalSettings,
|
||||
HostingEnvironment
|
||||
);
|
||||
|
||||
runtime.Level = RuntimeLevel.Run;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Tests.Runtimes
|
||||
{
|
||||
IList<IViewEngine> engines = new List<IViewEngine>
|
||||
{
|
||||
new RenderViewEngine(TestHelper.IOHelper),
|
||||
new RenderViewEngine(TestHelper.GetHostingEnvironment()),
|
||||
new PluginViewEngine()
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Umbraco.Tests.Runtimes
|
||||
{
|
||||
IList<IViewEngine> engines = new List<IViewEngine>
|
||||
{
|
||||
new RenderViewEngine(TestHelper.IOHelper),
|
||||
new RenderViewEngine(TestHelper.GetHostingEnvironment()),
|
||||
new PluginViewEngine()
|
||||
};
|
||||
|
||||
|
||||
@@ -123,10 +123,10 @@ namespace Umbraco.Tests.Scoping
|
||||
var umbracoContext = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
service,
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, IOHelper),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, HostingEnvironment),
|
||||
globalSettings,
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
|
||||
@@ -34,15 +34,16 @@ namespace Umbraco.Tests.Security
|
||||
var umbracoContext = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, IOHelper), globalSettings,
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, HostingEnvironment),
|
||||
globalSettings,
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Install);
|
||||
var mgr = new BackOfficeCookieManager(
|
||||
Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbracoContext), runtime, IOHelper, AppCaches.RequestCache);
|
||||
Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbracoContext), runtime, HostingEnvironment, globalSettings, AppCaches.RequestCache);
|
||||
|
||||
var result = mgr.ShouldAuthenticateRequest(Mock.Of<IOwinContext>(), new Uri("http://localhost/umbraco"));
|
||||
|
||||
@@ -57,15 +58,15 @@ namespace Umbraco.Tests.Security
|
||||
var umbCtx = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, IOHelper),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, HostingEnvironment),
|
||||
globalSettings,
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Run);
|
||||
var mgr = new BackOfficeCookieManager(Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbCtx), runtime, IOHelper, AppCaches.RequestCache);
|
||||
var mgr = new BackOfficeCookieManager(Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbCtx), runtime, HostingEnvironment, globalSettings, AppCaches.RequestCache);
|
||||
|
||||
var request = new Mock<OwinRequest>();
|
||||
request.Setup(owinRequest => owinRequest.Uri).Returns(new Uri("http://localhost/umbraco"));
|
||||
|
||||
@@ -143,8 +143,8 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
publishedSnapshotService.Object,
|
||||
webSecurity.Object,
|
||||
globalSettings,
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
new TestVariationContextAccessor(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
TestHelper.UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
@@ -378,10 +378,10 @@ namespace Umbraco.Tests.TestHelpers
|
||||
httpContextAccessor,
|
||||
service,
|
||||
new WebSecurity(httpContextAccessor, Factory.GetInstance<IUserService>(),
|
||||
Factory.GetInstance<IGlobalSettings>(), IOHelper),
|
||||
Factory.GetInstance<IGlobalSettings>(), HostingEnvironment),
|
||||
globalSettings ?? Factory.GetInstance<IGlobalSettings>(),
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Umbraco.Tests.Testing.Objects
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
TestHelper.UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
@@ -33,6 +33,7 @@ using Umbraco.Web.Features;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -81,6 +82,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var usersController = new AuthenticationController(
|
||||
new TestUserPasswordConfig(),
|
||||
Factory.GetInstance<IGlobalSettings>(),
|
||||
Factory.GetInstance<IHostingEnvironment>(),
|
||||
umbracoContextAccessor,
|
||||
Factory.GetInstance<ISqlContext>(),
|
||||
Factory.GetInstance<ServiceContext>(),
|
||||
@@ -89,7 +91,6 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Factory.GetInstance<IRuntimeState>(),
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<ISecuritySettings>(),
|
||||
Factory.GetInstance<IIOHelper>(),
|
||||
Factory.GetInstance<IPublishedUrlProvider>()
|
||||
);
|
||||
return usersController;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Ensure_Same_Area1()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
new PluginControllerArea(TestObjects.GetGlobalSettings(), IOHelper,
|
||||
new PluginControllerArea(TestObjects.GetGlobalSettings(), HostingEnvironment,
|
||||
new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
@@ -27,7 +27,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Ensure_Same_Area3()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
new PluginControllerArea(TestObjects.GetGlobalSettings(), IOHelper,
|
||||
new PluginControllerArea(TestObjects.GetGlobalSettings(), HostingEnvironment,
|
||||
new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
@@ -39,7 +39,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
[Test]
|
||||
public void Ensure_Same_Area2()
|
||||
{
|
||||
var area = new PluginControllerArea(TestObjects.GetGlobalSettings(), IOHelper,
|
||||
var area = new PluginControllerArea(TestObjects.GetGlobalSettings(), HostingEnvironment,
|
||||
new PluginControllerMetadata[]
|
||||
{
|
||||
PluginController.GetMetadata(typeof(Plugin1Controller)),
|
||||
|
||||
@@ -36,6 +36,7 @@ using Umbraco.Web.Models.ContentEditing;
|
||||
using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
@@ -91,7 +92,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
ShortStringHelper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IContentSettings>(),
|
||||
Factory.GetInstance<IIOHelper>(),
|
||||
Factory.GetInstance<IHostingEnvironment>(),
|
||||
Factory.GetInstance<IImageUrlGenerator>(),
|
||||
Factory.GetInstance<IPublishedUrlProvider>(),
|
||||
Factory.GetInstance<ISecuritySettings>()
|
||||
@@ -164,7 +165,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
ShortStringHelper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IContentSettings>(),
|
||||
Factory.GetInstance<IIOHelper>(),
|
||||
Factory.GetInstance<IHostingEnvironment>(),
|
||||
Factory.GetInstance<IImageUrlGenerator>(),
|
||||
Factory.GetInstance<IPublishedUrlProvider>(),
|
||||
Factory.GetInstance<ISecuritySettings>()
|
||||
@@ -207,7 +208,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
ShortStringHelper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IContentSettings>(),
|
||||
Factory.GetInstance<IIOHelper>(),
|
||||
Factory.GetInstance<IHostingEnvironment>(),
|
||||
Factory.GetInstance<IImageUrlGenerator>(),
|
||||
Factory.GetInstance<IPublishedUrlProvider>(),
|
||||
Factory.GetInstance<ISecuritySettings>()
|
||||
@@ -285,7 +286,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
ShortStringHelper,
|
||||
Factory.GetInstance<UmbracoMapper>(),
|
||||
Factory.GetInstance<IContentSettings>(),
|
||||
Factory.GetInstance<IIOHelper>(),
|
||||
Factory.GetInstance<IHostingEnvironment>(),
|
||||
Factory.GetInstance<IImageUrlGenerator>(),
|
||||
Factory.GetInstance<IPublishedUrlProvider>(),
|
||||
Factory.GetInstance<ISecuritySettings>()
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
TestHelper.UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
TestHelper.UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
@@ -136,7 +136,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
TestHelper.UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
@@ -168,7 +168,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
TestHelper.UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper,
|
||||
HostingEnvironment,
|
||||
UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
@@ -77,7 +77,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper,
|
||||
HostingEnvironment,
|
||||
UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
@@ -110,7 +110,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper,
|
||||
HostingEnvironment,
|
||||
UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
@@ -143,7 +143,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestDefaultCultureAccessor(),
|
||||
globalSettings,
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper,
|
||||
HostingEnvironment,
|
||||
UriUtility,
|
||||
httpContextAccessor,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
@@ -438,10 +438,10 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
var ctx = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
_service,
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, IOHelper),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, globalSettings, HostingEnvironment),
|
||||
globalSettings,
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ namespace Umbraco.Tests.Web
|
||||
var umbCtx = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, TestObjects.GetGlobalSettings(), IOHelper),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, TestObjects.GetGlobalSettings(), HostingEnvironment),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
var r1 = new RouteData();
|
||||
@@ -53,10 +53,10 @@ namespace Umbraco.Tests.Web
|
||||
var umbCtx = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, TestObjects.GetGlobalSettings(), IOHelper),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, TestObjects.GetGlobalSettings(), HostingEnvironment),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
@@ -84,10 +84,10 @@ namespace Umbraco.Tests.Web
|
||||
var umbCtx = new UmbracoContext(
|
||||
httpContextAccessor,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, TestObjects.GetGlobalSettings(), IOHelper),
|
||||
new WebSecurity(httpContextAccessor, ServiceContext.UserService, TestObjects.GetGlobalSettings(), HostingEnvironment),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
HostingEnvironment,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility,
|
||||
new AspNetCookieManager(httpContextAccessor));
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Runtime;
|
||||
using Umbraco.Core.WebAssets;
|
||||
@@ -14,13 +15,13 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
{
|
||||
private readonly IRuntimeMinifier _runtimeMinifier;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public BackOfficeController(IRuntimeMinifier runtimeMinifier, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
public BackOfficeController(IRuntimeMinifier runtimeMinifier, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_runtimeMinifier = runtimeMinifier;
|
||||
_globalSettings = globalSettings;
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
// GET
|
||||
@@ -36,7 +37,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
[MinifyJavaScriptResult(Order = 0)]
|
||||
public async Task<IActionResult> Application()
|
||||
{
|
||||
var result = await _runtimeMinifier.GetScriptForLoadingBackOfficeAsync(_globalSettings, _ioHelper);
|
||||
var result = await _runtimeMinifier.GetScriptForLoadingBackOfficeAsync(_globalSettings, _hostingEnvironment);
|
||||
|
||||
return new JavaScriptResult(result);
|
||||
}
|
||||
|
||||
@@ -91,13 +91,11 @@ namespace Umbraco.Web.Common.AspNetCore
|
||||
if (!virtualPath.StartsWith("~/") && !virtualPath.StartsWith("/"))
|
||||
throw new InvalidOperationException($"{nameof(virtualPath)} must start with ~/ or /");
|
||||
|
||||
var root = ApplicationVirtualPath.EnsureStartsWith('/');
|
||||
|
||||
// will occur if it starts with "/"
|
||||
if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute))
|
||||
return virtualPath;
|
||||
|
||||
var fullPath = root.EnsureEndsWith('/') + virtualPath.TrimStart("~/");
|
||||
var fullPath = ApplicationVirtualPath.EnsureEndsWith('/') + virtualPath.TrimStart("~/");
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<base href="@Model.IOHelper.BackOfficePath.EnsureEndsWith('/')" />
|
||||
<base href="@Model.BackOfficePath.EnsureEndsWith('/')" />
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
@@ -44,9 +44,10 @@
|
||||
redirectUrl = Url.Action("AuthorizeUpgrade", "BackOffice")
|
||||
});
|
||||
}
|
||||
@Html.BareMinimumServerVariablesScript(Url, externalLoginUrl, Model.Features, Model.GlobalSettings, Model.UmbracoVersion, Model.ContentSettings, Model.IOHelper, Model.TreeCollection, Model.HttpContextAccessor, Model.HostingEnvironment, Model.RuntimeSettings, Model.SecuritySettings, runtimeMinifier)
|
||||
|
||||
<script type="text/javascript">
|
||||
@Html.BareMinimumServerVariablesScript(Url, Model.Features, Model.GlobalSettings, Model.UmbracoVersion, Model.ContentSettings, Model.TreeCollection, Model.HttpContextAccessor, Model.HostingEnvironment, Model.RuntimeSettings, Model.SecuritySettings, runtimeMinifier)
|
||||
|
||||
<script type="text/javascript">
|
||||
document.angularReady = function (app) {
|
||||
|
||||
@Html.AngularValueExternalLoginInfoScript(ViewData.GetExternalSignInError())
|
||||
|
||||
@@ -105,9 +105,9 @@
|
||||
on-login="hideLoginScreen()">
|
||||
</umb-login>
|
||||
|
||||
@Html.BareMinimumServerVariablesScript(Url, Url.Action("ExternalLogin", "BackOffice", new { area = ViewData.GetUmbracoPath() }), Model.Features, Model.GlobalSettings, Model.UmbracoVersion, Model.ContentSettings, Model.IOHelper, Model.TreeCollection, Model.HttpContextAccessor, Model.HostingEnvironment, Model.RuntimeSettings, Model.SecuritySettings, Current.RuntimeMinifier)
|
||||
@Html.BareMinimumServerVariablesScript(Url, Model.Features, Model.GlobalSettings, Model.UmbracoVersion, Model.ContentSettings, Model.TreeCollection, Model.HttpContextAccessor, Model.HostingEnvironment, Model.RuntimeSettings, Model.SecuritySettings, Current.RuntimeMinifier)
|
||||
|
||||
<script>
|
||||
<script>
|
||||
|
||||
document.angularReady = function(app) {
|
||||
@Html.AngularValueExternalLoginInfoScript(ViewData.GetExternalSignInError())
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.AspNet.SignalR;
|
||||
using Microsoft.Owin.Logging;
|
||||
using Owin;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Logging;
|
||||
@@ -43,10 +44,11 @@ namespace Umbraco.Web
|
||||
/// Configures SignalR.
|
||||
/// </summary>
|
||||
/// <param name="app">The app builder.</param>
|
||||
/// <param name="ioHelper"></param>
|
||||
public static IAppBuilder UseSignalR(this IAppBuilder app, IIOHelper ioHelper)
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var umbracoPath = ioHelper.GetUmbracoMvcArea();
|
||||
var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment);
|
||||
var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr";
|
||||
return app.MapSignalR(signalrPath, new HubConfiguration { EnableDetailedErrors = true });
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Umbraco.Web.Hosting
|
||||
ApplicationId = HostingEnvironment.ApplicationID;
|
||||
// when we are not hosted (i.e. unit test or otherwise) we'll need to get the root path from the executing assembly
|
||||
ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath ?? Assembly.GetExecutingAssembly().GetRootDirectorySafe();
|
||||
ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath;
|
||||
ApplicationVirtualPath = hostingSettings.ApplicationVirtualPath ?? HostingEnvironment.ApplicationVirtualPath.EnsureStartsWith("/");
|
||||
IISVersion = HttpRuntime.IISVersion;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Umbraco.Web.Hosting
|
||||
return HostingEnvironment.MapPath(path);
|
||||
}
|
||||
|
||||
public string ToAbsolute(string virtualPath) => VirtualPathUtility.ToAbsolute(virtualPath, ApplicationVirtualPath.EnsureStartsWith('/'));
|
||||
public string ToAbsolute(string virtualPath) => VirtualPathUtility.ToAbsolute(virtualPath, ApplicationVirtualPath);
|
||||
|
||||
|
||||
public string LocalTempPath
|
||||
|
||||
@@ -27,6 +27,7 @@ using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Web.Models.Identity;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -44,13 +45,14 @@ namespace Umbraco.Web.Editors
|
||||
private BackOfficeUserManager<BackOfficeIdentityUser> _userManager;
|
||||
private BackOfficeSignInManager _signInManager;
|
||||
private readonly IUserPasswordConfiguration _passwordConfiguration;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
private readonly ISecuritySettings _securitySettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public AuthenticationController(
|
||||
IUserPasswordConfiguration passwordConfiguration,
|
||||
IGlobalSettings globalSettings,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ISqlContext sqlContext,
|
||||
ServiceContext services,
|
||||
@@ -59,14 +61,13 @@ namespace Umbraco.Web.Editors
|
||||
IRuntimeState runtimeState,
|
||||
UmbracoMapper umbracoMapper,
|
||||
ISecuritySettings securitySettings,
|
||||
IIOHelper ioHelper,
|
||||
IPublishedUrlProvider publishedUrlProvider)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider)
|
||||
{
|
||||
_passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration));
|
||||
_hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
|
||||
_runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState));
|
||||
_securitySettings = securitySettings ?? throw new ArgumentNullException(nameof(securitySettings));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
}
|
||||
|
||||
protected BackOfficeUserManager<BackOfficeIdentityUser> UserManager => _userManager
|
||||
@@ -534,7 +535,7 @@ namespace Umbraco.Web.Editors
|
||||
var action = urlHelper.Action("ValidatePasswordResetCode", "BackOffice",
|
||||
new
|
||||
{
|
||||
area = _ioHelper.GetUmbracoMvcArea(),
|
||||
area = GlobalSettings.GetUmbracoMvcArea(_hostingEnvironment),
|
||||
u = userId,
|
||||
r = code
|
||||
});
|
||||
|
||||
@@ -44,7 +44,6 @@ namespace Umbraco.Web.Editors
|
||||
[DisableBrowserCache]
|
||||
public class BackOfficeController : UmbracoController
|
||||
{
|
||||
private readonly IManifestParser _manifestParser;
|
||||
private readonly UmbracoFeatures _features;
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
private BackOfficeUserManager<BackOfficeIdentityUser> _userManager;
|
||||
@@ -52,7 +51,6 @@ namespace Umbraco.Web.Editors
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IGridConfig _gridConfig;
|
||||
private readonly IContentSettings _contentSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly TreeCollection _treeCollection;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
@@ -61,7 +59,6 @@ namespace Umbraco.Web.Editors
|
||||
private readonly IRuntimeMinifier _runtimeMinifier;
|
||||
|
||||
public BackOfficeController(
|
||||
IManifestParser manifestParser,
|
||||
UmbracoFeatures features,
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
@@ -72,7 +69,6 @@ namespace Umbraco.Web.Editors
|
||||
IUmbracoVersion umbracoVersion,
|
||||
IGridConfig gridConfig,
|
||||
IContentSettings contentSettings,
|
||||
IIOHelper ioHelper,
|
||||
TreeCollection treeCollection,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
@@ -82,13 +78,11 @@ namespace Umbraco.Web.Editors
|
||||
: base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger)
|
||||
|
||||
{
|
||||
_manifestParser = manifestParser;
|
||||
_features = features;
|
||||
_runtimeState = runtimeState;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_gridConfig = gridConfig ?? throw new ArgumentNullException(nameof(gridConfig));
|
||||
_contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection));
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
@@ -111,9 +105,9 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
return await RenderDefaultOrProcessExternalLoginAsync(
|
||||
() =>
|
||||
View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings,_ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)),
|
||||
View(GlobalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings, _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(GlobalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith('/') + "Views/Default.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -197,7 +191,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
return await RenderDefaultOrProcessExternalLoginAsync(
|
||||
//The default view to render when there is no external login info or errors
|
||||
() => View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "Views/AuthorizeUpgrade.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings, _ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)),
|
||||
() => View(GlobalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith('/') + "Views/AuthorizeUpgrade.cshtml", new BackOfficeModel(_features, GlobalSettings, _umbracoVersion, _contentSettings, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings)),
|
||||
//The ActionResult to perform if external login is successful
|
||||
() => Redirect("/"));
|
||||
}
|
||||
@@ -248,7 +242,7 @@ namespace Umbraco.Web.Editors
|
||||
[OutputCache(Order = 1, VaryByParam = "none", Location = OutputCacheLocation.Server, Duration = 5000)]
|
||||
public async Task<JavaScriptResult> Application()
|
||||
{
|
||||
var result = await _runtimeMinifier.GetScriptForLoadingBackOfficeAsync(GlobalSettings, _ioHelper);
|
||||
var result = await _runtimeMinifier.GetScriptForLoadingBackOfficeAsync(GlobalSettings, _hostingEnvironment);
|
||||
|
||||
return JavaScript(result);
|
||||
}
|
||||
@@ -270,7 +264,7 @@ namespace Umbraco.Web.Editors
|
||||
[MinifyJavaScriptResult(Order = 1)]
|
||||
public JavaScriptResult ServerVariables()
|
||||
{
|
||||
var serverVars = new BackOfficeServerVariables(Url, _runtimeState, _features, GlobalSettings, _umbracoVersion, _contentSettings, _ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings, _runtimeMinifier);
|
||||
var serverVars = new BackOfficeServerVariables(Url, _runtimeState, _features, GlobalSettings, _umbracoVersion, _contentSettings, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings, _runtimeMinifier);
|
||||
|
||||
//cache the result if debugging is disabled
|
||||
var result = _hostingEnvironment.IsDebugMode
|
||||
@@ -364,7 +358,7 @@ namespace Umbraco.Web.Editors
|
||||
if (defaultResponse == null) throw new ArgumentNullException("defaultResponse");
|
||||
if (externalSignInResponse == null) throw new ArgumentNullException("externalSignInResponse");
|
||||
|
||||
ViewData.SetUmbracoPath(_ioHelper.GetUmbracoMvcArea());
|
||||
ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(_hostingEnvironment));
|
||||
|
||||
//check if there is the TempData with the any token name specified, if so, assign to view bag and render the view
|
||||
if (ViewData.FromTempData(TempData, ViewDataExtensions.TokenExternalSignInError) ||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Umbraco.Web.Editors
|
||||
public class BackOfficeModel
|
||||
{
|
||||
public BackOfficeModel(UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion,
|
||||
IContentSettings contentSettings, IIOHelper ioHelper, TreeCollection treeCollection,
|
||||
IContentSettings contentSettings, TreeCollection treeCollection,
|
||||
IHttpContextAccessor httpContextAccessor, IHostingEnvironment hostingEnvironment,
|
||||
IRuntimeSettings runtimeSettings, ISecuritySettings securitySettings)
|
||||
{
|
||||
@@ -19,23 +19,24 @@ namespace Umbraco.Web.Editors
|
||||
GlobalSettings = globalSettings;
|
||||
UmbracoVersion = umbracoVersion;
|
||||
ContentSettings = contentSettings;
|
||||
IOHelper = ioHelper;
|
||||
TreeCollection = treeCollection;
|
||||
HttpContextAccessor = httpContextAccessor;
|
||||
HostingEnvironment = hostingEnvironment;
|
||||
RuntimeSettings = runtimeSettings;
|
||||
SecuritySettings = securitySettings;
|
||||
BackOfficePath = GlobalSettings.GetBackOfficePath(HostingEnvironment);
|
||||
}
|
||||
|
||||
public UmbracoFeatures Features { get; }
|
||||
public IGlobalSettings GlobalSettings { get; }
|
||||
public IUmbracoVersion UmbracoVersion { get; }
|
||||
public IContentSettings ContentSettings { get; }
|
||||
public IIOHelper IOHelper { get; }
|
||||
public TreeCollection TreeCollection { get; }
|
||||
public IHttpContextAccessor HttpContextAccessor { get; }
|
||||
public IHostingEnvironment HostingEnvironment { get; }
|
||||
public IRuntimeSettings RuntimeSettings { get; set; }
|
||||
public ISecuritySettings SecuritySettings { get; set; }
|
||||
|
||||
public string BackOfficePath { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Umbraco.Web.Editors
|
||||
private readonly UmbracoFeatures _features;
|
||||
public IEnumerable<ILanguage> Languages { get; }
|
||||
|
||||
public BackOfficePreviewModel(UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IEnumerable<ILanguage> languages, IContentSettings contentSettings, IIOHelper ioHelper, TreeCollection treeCollection, IHttpContextAccessor httpContextAccessor, IHostingEnvironment hostingEnvironment, IRuntimeSettings runtimeSettings, ISecuritySettings securitySettings)
|
||||
: base(features, globalSettings, umbracoVersion, contentSettings, ioHelper, treeCollection, httpContextAccessor, hostingEnvironment, runtimeSettings, securitySettings)
|
||||
public BackOfficePreviewModel(UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IEnumerable<ILanguage> languages, IContentSettings contentSettings, TreeCollection treeCollection, IHttpContextAccessor httpContextAccessor, IHostingEnvironment hostingEnvironment, IRuntimeSettings runtimeSettings, ISecuritySettings securitySettings)
|
||||
: base(features, globalSettings, umbracoVersion, contentSettings, treeCollection, httpContextAccessor, hostingEnvironment, runtimeSettings, securitySettings)
|
||||
{
|
||||
_features = features;
|
||||
Languages = languages;
|
||||
|
||||
@@ -35,7 +35,6 @@ namespace Umbraco.Web.Editors
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IContentSettings _contentSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly TreeCollection _treeCollection;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
@@ -50,7 +49,6 @@ namespace Umbraco.Web.Editors
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoVersion umbracoVersion,
|
||||
IContentSettings contentSettings,
|
||||
IIOHelper ioHelper,
|
||||
TreeCollection treeCollection,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
@@ -64,7 +62,6 @@ namespace Umbraco.Web.Editors
|
||||
_globalSettings = globalSettings;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_treeCollection = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection));
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
@@ -347,9 +344,9 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
"umbracoSettings", new Dictionary<string, object>
|
||||
{
|
||||
{"umbracoPath", _ioHelper.BackOfficePath},
|
||||
{"mediaPath", _ioHelper.ResolveUrl(globalSettings.UmbracoMediaPath).TrimEnd('/')},
|
||||
{"appPluginsPath", _ioHelper.ResolveUrl(Constants.SystemDirectories.AppPlugins).TrimEnd('/')},
|
||||
{"umbracoPath", _globalSettings.GetBackOfficePath(_hostingEnvironment)},
|
||||
{"mediaPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoMediaPath).TrimEnd('/')},
|
||||
{"appPluginsPath", _hostingEnvironment.ToAbsolute(Constants.SystemDirectories.AppPlugins).TrimEnd('/')},
|
||||
{
|
||||
"imageFileTypes",
|
||||
string.Join(",", _contentSettings.ImageFileTypes)
|
||||
@@ -368,7 +365,7 @@ namespace Umbraco.Web.Editors
|
||||
},
|
||||
{"keepUserLoggedIn", _securitySettings.KeepUserLoggedIn},
|
||||
{"usernameIsEmail", _securitySettings.UsernameIsEmail},
|
||||
{"cssPath", _ioHelper.ResolveUrl(globalSettings.UmbracoCssPath).TrimEnd('/')},
|
||||
{"cssPath", _hostingEnvironment.ToAbsolute(globalSettings.UmbracoCssPath).TrimEnd('/')},
|
||||
{"allowPasswordReset", _securitySettings.AllowPasswordReset},
|
||||
{"loginBackgroundImage", _contentSettings.LoginBackgroundImage},
|
||||
{"showUserInvite", EmailSender.CanSendRequiredEmail(globalSettings)},
|
||||
|
||||
@@ -22,6 +22,7 @@ using Umbraco.Web.Security;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
@@ -35,7 +36,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
private readonly IMediaFileSystem _mediaFileSystem;
|
||||
private readonly IContentSettings _contentSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IImageUrlGenerator _imageUrlGenerator;
|
||||
|
||||
public CurrentUserController(
|
||||
@@ -50,14 +51,14 @@ namespace Umbraco.Web.Editors
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
IContentSettings contentSettings,
|
||||
IIOHelper ioHelper,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IImageUrlGenerator imageUrlGenerator,
|
||||
IPublishedUrlProvider publishedUrlProvider)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, shortStringHelper, umbracoMapper, publishedUrlProvider)
|
||||
{
|
||||
_mediaFileSystem = mediaFileSystem;
|
||||
_contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
|
||||
_imageUrlGenerator = imageUrlGenerator;
|
||||
}
|
||||
|
||||
@@ -192,7 +193,7 @@ namespace Umbraco.Web.Editors
|
||||
public async Task<HttpResponseMessage> PostSetAvatar()
|
||||
{
|
||||
//borrow the logic from the user controller
|
||||
return await UsersController.PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, _mediaFileSystem, ShortStringHelper, _contentSettings, _ioHelper, _imageUrlGenerator, Security.GetUserId().ResultOr(0));
|
||||
return await UsersController.PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, _mediaFileSystem, ShortStringHelper, _contentSettings, _hostingEnvironment, _imageUrlGenerator, Security.GetUserId().ResultOr(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace Umbraco.Web.Editors
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IContentSettings _contentSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly TreeCollection _treeCollection;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
@@ -49,7 +48,6 @@ namespace Umbraco.Web.Editors
|
||||
ILocalizationService localizationService,
|
||||
IUmbracoVersion umbracoVersion,
|
||||
IContentSettings contentSettings,
|
||||
IIOHelper ioHelper,
|
||||
TreeCollection treeCollection,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
@@ -65,7 +63,6 @@ namespace Umbraco.Web.Editors
|
||||
_localizationService = localizationService;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_treeCollection = treeCollection;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
@@ -81,7 +78,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
var availableLanguages = _localizationService.GetAllLanguages();
|
||||
|
||||
var model = new BackOfficePreviewModel(_features, _globalSettings, _umbracoVersion, availableLanguages, _contentSettings, _ioHelper, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings);
|
||||
var model = new BackOfficePreviewModel(_features, _globalSettings, _umbracoVersion, availableLanguages, _contentSettings, _treeCollection, _httpContextAccessor, _hostingEnvironment, _runtimeSettings, _securitySettings);
|
||||
|
||||
if (model.PreviewExtendedHeaderView.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -92,7 +89,7 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
}
|
||||
|
||||
return View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "Views/Preview/" + "Index.cshtml", model);
|
||||
return View(_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith('/') + "Views/Preview/" + "Index.cshtml", model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -104,7 +101,7 @@ namespace Umbraco.Web.Editors
|
||||
public async Task<JavaScriptResult> Application()
|
||||
{
|
||||
var files = await _runtimeMinifier.GetAssetPathsAsync(BackOfficeWebAssets.UmbracoPreviewJsBundleName);
|
||||
var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(files, "umbraco.preview", _globalSettings, _ioHelper);
|
||||
var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(files, "umbraco.preview", _globalSettings, _hostingEnvironment);
|
||||
|
||||
return JavaScript(result);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
using Task = System.Threading.Tasks.Task;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Core.Media;
|
||||
|
||||
@@ -48,7 +49,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
private readonly IMediaFileSystem _mediaFileSystem;
|
||||
private readonly IContentSettings _contentSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly ISqlContext _sqlContext;
|
||||
private readonly IImageUrlGenerator _imageUrlGenerator;
|
||||
private readonly ISecuritySettings _securitySettings;
|
||||
@@ -65,7 +66,7 @@ namespace Umbraco.Web.Editors
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
IContentSettings contentSettings,
|
||||
IIOHelper ioHelper,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IImageUrlGenerator imageUrlGenerator,
|
||||
IPublishedUrlProvider publishedUrlProvider,
|
||||
ISecuritySettings securitySettings)
|
||||
@@ -73,7 +74,7 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
_mediaFileSystem = mediaFileSystem;
|
||||
_contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings));
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_sqlContext = sqlContext;
|
||||
_imageUrlGenerator = imageUrlGenerator;
|
||||
_securitySettings = securitySettings;
|
||||
@@ -97,17 +98,17 @@ namespace Umbraco.Web.Editors
|
||||
[AdminUsersAuthorize]
|
||||
public async Task<HttpResponseMessage> PostSetAvatar(int id)
|
||||
{
|
||||
return await PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, _mediaFileSystem, ShortStringHelper, _contentSettings, _ioHelper, _imageUrlGenerator, id);
|
||||
return await PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, _mediaFileSystem, ShortStringHelper, _contentSettings, _hostingEnvironment, _imageUrlGenerator, id);
|
||||
}
|
||||
|
||||
internal static async Task<HttpResponseMessage> PostSetAvatarInternal(HttpRequestMessage request, IUserService userService, IAppCache cache, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IContentSettings contentSettings, IIOHelper ioHelper, IImageUrlGenerator imageUrlGenerator, int id)
|
||||
internal static async Task<HttpResponseMessage> PostSetAvatarInternal(HttpRequestMessage request, IUserService userService, IAppCache cache, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper, IContentSettings contentSettings, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, int id)
|
||||
{
|
||||
if (request.Content.IsMimeMultipartContent() == false)
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
||||
}
|
||||
|
||||
var root = ioHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
|
||||
var root = hostingEnvironment.MapPath(Constants.SystemDirectories.TempFileUploads);
|
||||
//ensure it exists
|
||||
Directory.CreateDirectory(root);
|
||||
var provider = new MultipartFormDataStreamProvider(root);
|
||||
@@ -488,7 +489,7 @@ namespace Umbraco.Web.Editors
|
||||
var action = urlHelper.Action("VerifyInvite", "BackOffice",
|
||||
new
|
||||
{
|
||||
area = _ioHelper.GetUmbracoMvcArea(),
|
||||
area = GlobalSettings.GetUmbracoMvcArea(_hostingEnvironment),
|
||||
invite = inviteToken
|
||||
});
|
||||
|
||||
|
||||
@@ -30,20 +30,24 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="uri"></param>
|
||||
/// <param name="externalLoginsUrl">
|
||||
/// The post url used to sign in with external logins - this can change depending on for what service the external login is service.
|
||||
/// Example: normal back office login or authenticating upgrade login
|
||||
/// </param>
|
||||
/// <param name="features"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="umbracoVersion"></param>
|
||||
/// <param name="contentSettings"></param>
|
||||
/// <param name="treeCollection"></param>
|
||||
/// <param name="httpContextAccessor"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="settings"></param>
|
||||
/// <param name="securitySettings"></param>
|
||||
/// <param name="runtimeMinifier"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// These are the bare minimal server variables that are required for the application to start without being authenticated,
|
||||
/// we will load the rest of the server vars after the user is authenticated.
|
||||
/// </remarks>
|
||||
public static IHtmlString BareMinimumServerVariablesScript(this HtmlHelper html, UrlHelper uri, string externalLoginsUrl, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IContentSettings contentSettings, IIOHelper ioHelper, TreeCollection treeCollection, IHttpContextAccessor httpContextAccessor, IHostingEnvironment hostingEnvironment, IRuntimeSettings settings, ISecuritySettings securitySettings, IRuntimeMinifier runtimeMinifier)
|
||||
public static IHtmlString BareMinimumServerVariablesScript(this HtmlHelper html, UrlHelper uri, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IContentSettings contentSettings, TreeCollection treeCollection, IHttpContextAccessor httpContextAccessor, IHostingEnvironment hostingEnvironment, IRuntimeSettings settings, ISecuritySettings securitySettings, IRuntimeMinifier runtimeMinifier)
|
||||
{
|
||||
var serverVars = new BackOfficeServerVariables(uri, Current.RuntimeState, features, globalSettings, umbracoVersion, contentSettings, ioHelper, treeCollection, httpContextAccessor, hostingEnvironment, settings, securitySettings, runtimeMinifier);
|
||||
var serverVars = new BackOfficeServerVariables(uri, Current.RuntimeState, features, globalSettings, umbracoVersion, contentSettings, treeCollection, httpContextAccessor, hostingEnvironment, settings, securitySettings, runtimeMinifier);
|
||||
var minVars = serverVars.BareMinimumServerVariables();
|
||||
|
||||
var str = @"<script type=""text/javascript"">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.WebAssets;
|
||||
@@ -21,30 +22,24 @@ namespace Umbraco.Web.Install.Controllers
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly InstallHelper _installHelper;
|
||||
private readonly IRuntimeState _runtime;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IRuntimeMinifier _runtimeMinifier;
|
||||
|
||||
public InstallController(
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
InstallHelper installHelper,
|
||||
IRuntimeState runtime,
|
||||
ILogger logger,
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoVersion umbracoVersion,
|
||||
IIOHelper ioHelper,
|
||||
IRuntimeMinifier runtimeMinifier)
|
||||
IRuntimeMinifier runtimeMinifier,
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_installHelper = installHelper;
|
||||
_runtime = runtime;
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_ioHelper = ioHelper;
|
||||
_runtimeMinifier = runtimeMinifier;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -73,12 +68,12 @@ namespace Umbraco.Web.Install.Controllers
|
||||
ViewData.SetInstallApiBaseUrl(Url.GetUmbracoApiService("GetSetup", "InstallApi", "UmbracoInstall").TrimEnd("GetSetup"));
|
||||
|
||||
// get the base umbraco folder
|
||||
ViewData.SetUmbracoBaseFolder(_ioHelper.ResolveUrl(_globalSettings.UmbracoPath));
|
||||
ViewData.SetUmbracoBaseFolder(_hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath));
|
||||
|
||||
_installHelper.InstallStatus(false, "");
|
||||
|
||||
// always ensure full path (see NOTE in the class remarks)
|
||||
return View(_ioHelper.BackOfficePath.EnsureEndsWith('/') + "install/views/index.cshtml");
|
||||
return View(_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith('/') + "install/views/index.cshtml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Web.SessionState;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.WebApi;
|
||||
@@ -19,7 +20,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// Creates a custom individual route for the specified controller plugin. Individual routes
|
||||
/// are required by controller plugins to map to a unique URL based on ID.
|
||||
/// </summary>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="controllerName"></param>
|
||||
/// <param name="controllerType"></param>
|
||||
/// <param name="routes">An existing route collection</param>
|
||||
@@ -39,10 +40,11 @@ namespace Umbraco.Web.Mvc
|
||||
/// if not specified, will just route like:
|
||||
/// /umbraco/areaname
|
||||
/// </param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
internal static Route RouteControllerPlugin(this AreaRegistration area,
|
||||
IIOHelper ioHelper,
|
||||
IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment,
|
||||
string controllerName, Type controllerType, RouteCollection routes,
|
||||
string controllerSuffixName, string defaultAction, object defaultId,
|
||||
string umbracoTokenValue = "backoffice",
|
||||
@@ -58,7 +60,7 @@ namespace Umbraco.Web.Mvc
|
||||
if (routes == null) throw new ArgumentNullException(nameof(routes));
|
||||
if (defaultId == null) throw new ArgumentNullException(nameof(defaultId));
|
||||
|
||||
var umbracoArea = ioHelper.GetUmbracoMvcArea();
|
||||
var umbracoArea = globalSettings.GetUmbracoMvcArea(hostingEnvironment);
|
||||
|
||||
//routes are explicitly named with controller names and IDs
|
||||
var url = umbracoArea + "/" +
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
@@ -11,11 +12,13 @@ namespace Umbraco.Web.Mvc
|
||||
/// </summary>
|
||||
internal class BackOfficeArea : AreaRegistration
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public BackOfficeArea(IIOHelper ioHelper)
|
||||
public BackOfficeArea(IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
_globalSettings = globalSettings;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,6 +52,6 @@ namespace Umbraco.Web.Mvc
|
||||
new[] {typeof (BackOfficeController).Namespace});
|
||||
}
|
||||
|
||||
public override string AreaName => _ioHelper.GetUmbracoMvcArea();
|
||||
public override string AreaName => _globalSettings.GetUmbracoMvcArea(_hostingEnvironment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Web.Routing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.WebApi;
|
||||
|
||||
@@ -17,7 +18,7 @@ namespace Umbraco.Web.Mvc
|
||||
internal class PluginControllerArea : AreaRegistration
|
||||
{
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IEnumerable<PluginControllerMetadata> _surfaceControllers;
|
||||
private readonly IEnumerable<PluginControllerMetadata> _apiControllers;
|
||||
private readonly string _areaName;
|
||||
@@ -27,11 +28,12 @@ namespace Umbraco.Web.Mvc
|
||||
/// based on their PluginControllerAttribute. If they are not the same an exception will be thrown.
|
||||
/// </summary>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="pluginControllers"></param>
|
||||
public PluginControllerArea(IGlobalSettings globalSettings, IIOHelper ioHelper, IEnumerable<PluginControllerMetadata> pluginControllers)
|
||||
public PluginControllerArea(IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IEnumerable<PluginControllerMetadata> pluginControllers)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
var controllers = pluginControllers.ToArray();
|
||||
|
||||
if (controllers.Any(x => x.AreaName.IsNullOrWhiteSpace()))
|
||||
@@ -77,7 +79,7 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
foreach (var s in surfaceControllers)
|
||||
{
|
||||
var route = this.RouteControllerPlugin(_ioHelper, s.ControllerName, s.ControllerType, routes, "", "Index", UrlParameter.Optional, "surface");
|
||||
var route = this.RouteControllerPlugin(_globalSettings, _hostingEnvironment, s.ControllerName, s.ControllerType, routes, "", "Index", UrlParameter.Optional, "surface");
|
||||
//set the route handler to our SurfaceRouteHandler
|
||||
route.RouteHandler = new SurfaceRouteHandler();
|
||||
}
|
||||
@@ -92,7 +94,7 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
foreach (var s in apiControllers)
|
||||
{
|
||||
this.RouteControllerPlugin(_ioHelper, s.ControllerName, s.ControllerType, routes, "", "", UrlParameter.Optional, "api",
|
||||
this.RouteControllerPlugin(_globalSettings, _hostingEnvironment, s.ControllerName, s.ControllerType, routes, "", "", UrlParameter.Optional, "api",
|
||||
isMvc: false,
|
||||
areaPathPrefix: s.IsBackOffice ? "backoffice" : null);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
@@ -15,7 +16,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// </summary>
|
||||
public class RenderViewEngine : RazorViewEngine
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
private readonly IEnumerable<string> _supplementedViewLocations = new[] { "/{0}.cshtml" };
|
||||
//NOTE: we will make the main view location the last to be searched since if it is the first to be searched and there is both a view and a partial
|
||||
@@ -26,9 +27,9 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public RenderViewEngine(IIOHelper ioHelper)
|
||||
public RenderViewEngine(IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
|
||||
|
||||
const string templateFolder = Constants.ViewLocation;
|
||||
|
||||
@@ -47,7 +48,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// </summary>
|
||||
private void EnsureFoldersAndFiles()
|
||||
{
|
||||
var viewFolder = _ioHelper.MapPath(Constants.ViewLocation);
|
||||
var viewFolder = _hostingEnvironment.MapPath(Constants.ViewLocation);
|
||||
|
||||
// ensure the web.config file is in the ~/Views folder
|
||||
Directory.CreateDirectory(viewFolder);
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
if (redirectToUmbracoLogin)
|
||||
{
|
||||
_redirectUrl = Current.IOHelper.BackOfficePath.EnsureStartsWith("~");
|
||||
_redirectUrl = Current.Configs.Global().GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Web.Routing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Install;
|
||||
@@ -25,7 +26,7 @@ namespace Umbraco.Web.Runtime
|
||||
private readonly SurfaceControllerTypeCollection _surfaceControllerTypes;
|
||||
private readonly UmbracoApiControllerTypeCollection _apiControllerTypes;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
|
||||
public WebInitialComponent(
|
||||
@@ -33,14 +34,14 @@ namespace Umbraco.Web.Runtime
|
||||
SurfaceControllerTypeCollection surfaceControllerTypes,
|
||||
UmbracoApiControllerTypeCollection apiControllerTypes,
|
||||
IGlobalSettings globalSettings,
|
||||
IIOHelper ioHelper,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IShortStringHelper shortStringHelper)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_surfaceControllerTypes = surfaceControllerTypes;
|
||||
_apiControllerTypes = apiControllerTypes;
|
||||
_globalSettings = globalSettings;
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
}
|
||||
|
||||
@@ -59,7 +60,7 @@ namespace Umbraco.Web.Runtime
|
||||
ConfigureGlobalFilters();
|
||||
|
||||
// set routes
|
||||
CreateRoutes(_umbracoContextAccessor, _globalSettings, _shortStringHelper, _surfaceControllerTypes, _apiControllerTypes, _ioHelper);
|
||||
CreateRoutes(_umbracoContextAccessor, _globalSettings, _shortStringHelper, _surfaceControllerTypes, _apiControllerTypes, _hostingEnvironment);
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
@@ -94,7 +95,7 @@ namespace Umbraco.Web.Runtime
|
||||
ControllerBuilder.Current.SetControllerFactory(controllerFactory);
|
||||
|
||||
// set the render & plugin view engines
|
||||
ViewEngines.Engines.Add(new RenderViewEngine(_ioHelper));
|
||||
ViewEngines.Engines.Add(new RenderViewEngine(_hostingEnvironment));
|
||||
ViewEngines.Engines.Add(new PluginViewEngine());
|
||||
|
||||
//set model binder
|
||||
@@ -114,9 +115,9 @@ namespace Umbraco.Web.Runtime
|
||||
IShortStringHelper shortStringHelper,
|
||||
SurfaceControllerTypeCollection surfaceControllerTypes,
|
||||
UmbracoApiControllerTypeCollection apiControllerTypes,
|
||||
IIOHelper ioHelper)
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var umbracoPath = ioHelper.GetUmbracoMvcArea();
|
||||
var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment);
|
||||
|
||||
// create the front-end route
|
||||
var defaultRoute = RouteTable.Routes.MapRoute(
|
||||
@@ -133,10 +134,10 @@ namespace Umbraco.Web.Runtime
|
||||
RouteTable.Routes.RegisterArea<UmbracoInstallArea>();
|
||||
|
||||
// register all back office routes
|
||||
RouteTable.Routes.RegisterArea(new BackOfficeArea(ioHelper));
|
||||
RouteTable.Routes.RegisterArea(new BackOfficeArea(globalSettings, hostingEnvironment));
|
||||
|
||||
// plugin controllers must come first because the next route will catch many things
|
||||
RoutePluginControllers(globalSettings, surfaceControllerTypes, apiControllerTypes, ioHelper);
|
||||
RoutePluginControllers(globalSettings, surfaceControllerTypes, apiControllerTypes, hostingEnvironment);
|
||||
}
|
||||
|
||||
private static void RouteNoContentController(string umbracoPath)
|
||||
@@ -151,9 +152,9 @@ namespace Umbraco.Web.Runtime
|
||||
IGlobalSettings globalSettings,
|
||||
SurfaceControllerTypeCollection surfaceControllerTypes,
|
||||
UmbracoApiControllerTypeCollection apiControllerTypes,
|
||||
IIOHelper ioHelper)
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var umbracoPath = ioHelper.GetUmbracoMvcArea();
|
||||
var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment);
|
||||
|
||||
// need to find the plugin controllers and route them
|
||||
var pluginControllers = surfaceControllerTypes.Concat(apiControllerTypes).ToArray();
|
||||
@@ -175,7 +176,7 @@ namespace Umbraco.Web.Runtime
|
||||
foreach (var g in groupedAreas)
|
||||
{
|
||||
// create & register an area for the controllers (this will throw an exception if all controllers are not in the same area)
|
||||
var pluginControllerArea = new PluginControllerArea(globalSettings, ioHelper, g.Select(PluginController.GetMetadata));
|
||||
var pluginControllerArea = new PluginControllerArea(globalSettings, hostingEnvironment, g.Select(PluginController.GetMetadata));
|
||||
RouteTable.Routes.RegisterArea(pluginControllerArea);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
@@ -36,9 +37,11 @@ namespace Umbraco.Web.Security
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="mapper"></param>
|
||||
/// <param name="contentSettings"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="userMembershipProvider"></param>
|
||||
/// <param name="passwordConfiguration"></param>
|
||||
/// <param name="ipResolver"></param>
|
||||
public static void ConfigureUserManagerForUmbracoBackOffice(this IAppBuilder app,
|
||||
ServiceContext services,
|
||||
UmbracoMapper mapper,
|
||||
@@ -75,9 +78,9 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="app"></param>
|
||||
/// <param name="runtimeState"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="userMembershipProvider"></param>
|
||||
/// <param name="customUserStore"></param>
|
||||
/// <param name="contentSettings"></param>
|
||||
/// <param name="passwordConfiguration"></param>
|
||||
/// <param name="ipResolver"></param>
|
||||
public static void ConfigureUserManagerForUmbracoBackOffice(this IAppBuilder app,
|
||||
IRuntimeState runtimeState,
|
||||
@@ -143,6 +146,8 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="userService"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="securitySettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// By default this will be configured to execute on PipelineStage.Authenticate
|
||||
@@ -153,10 +158,10 @@ namespace Umbraco.Web.Security
|
||||
IUserService userService,
|
||||
IGlobalSettings globalSettings,
|
||||
ISecuritySettings securitySettings,
|
||||
IIOHelper ioHelper,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IRequestCache requestCache)
|
||||
{
|
||||
return app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, runtimeState, userService, globalSettings, securitySettings, ioHelper, requestCache, PipelineStage.Authenticate);
|
||||
return app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, runtimeState, userService, globalSettings, securitySettings, hostingEnvironment, requestCache, PipelineStage.Authenticate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,7 +173,8 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="userService"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="securitySettings"></param>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
/// <param name="stage">
|
||||
/// Configurable pipeline stage
|
||||
/// </param>
|
||||
@@ -179,14 +185,14 @@ namespace Umbraco.Web.Security
|
||||
IUserService userService,
|
||||
IGlobalSettings globalSettings,
|
||||
ISecuritySettings securitySettings,
|
||||
IIOHelper ioHelper,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IRequestCache requestCache,
|
||||
PipelineStage stage)
|
||||
{
|
||||
//Create the default options and provider
|
||||
var authOptions = app.CreateUmbracoCookieAuthOptions(umbracoContextAccessor, globalSettings, runtimeState, securitySettings, ioHelper, requestCache);
|
||||
var authOptions = app.CreateUmbracoCookieAuthOptions(umbracoContextAccessor, globalSettings, runtimeState, securitySettings, hostingEnvironment, requestCache);
|
||||
|
||||
authOptions.Provider = new BackOfficeCookieAuthenticationProvider(userService, runtimeState, globalSettings, ioHelper, securitySettings)
|
||||
authOptions.Provider = new BackOfficeCookieAuthenticationProvider(userService, runtimeState, globalSettings, hostingEnvironment, securitySettings)
|
||||
{
|
||||
// Enables the application to validate the security stamp when the user
|
||||
// logs in. This is a security feature which is used when you
|
||||
@@ -199,7 +205,7 @@ namespace Umbraco.Web.Security
|
||||
|
||||
};
|
||||
|
||||
return app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySettings, ioHelper, requestCache, authOptions, stage);
|
||||
return app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySettings, hostingEnvironment, requestCache, authOptions, stage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -210,14 +216,15 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="runtimeState"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="securitySettings"></param>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
/// <param name="cookieOptions">Custom auth cookie options can be specified to have more control over the cookie authentication logic</param>
|
||||
/// <param name="stage">
|
||||
/// Configurable pipeline stage
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public static IAppBuilder UseUmbracoBackOfficeCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings,
|
||||
ISecuritySettings securitySettings, IIOHelper ioHelper, IRequestCache requestCache, CookieAuthenticationOptions cookieOptions, PipelineStage stage)
|
||||
ISecuritySettings securitySettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, CookieAuthenticationOptions cookieOptions, PipelineStage stage)
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState));
|
||||
@@ -232,10 +239,11 @@ namespace Umbraco.Web.Security
|
||||
//don't apply if app is not ready
|
||||
if (runtimeState.Level != RuntimeLevel.Upgrade && runtimeState.Level != RuntimeLevel.Run) return app;
|
||||
|
||||
var backOfficePath = globalSettings.GetBackOfficePath(hostingEnvironment);
|
||||
var cookieAuthOptions = app.CreateUmbracoCookieAuthOptions(
|
||||
umbracoContextAccessor, globalSettings, runtimeState, securitySettings,
|
||||
//This defines the explicit path read cookies from for this middleware
|
||||
ioHelper, requestCache, new[] {$"{ioHelper.BackOfficePath}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"});
|
||||
hostingEnvironment, requestCache, new[] {$"{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
|
||||
@@ -310,13 +318,15 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="umbracoContextAccessor"></param>
|
||||
/// <param name="runtimeState"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// By default this will be configured to execute on PipelineStage.Authenticate
|
||||
/// </remarks>
|
||||
public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,IGlobalSettings globalSettings, IIOHelper ioHelper, IRequestCache requestCache)
|
||||
public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache)
|
||||
{
|
||||
return app.UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, ioHelper, requestCache, PipelineStage.Authenticate);
|
||||
return app.UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, hostingEnvironment, requestCache, PipelineStage.Authenticate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -327,16 +337,17 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="umbracoContextAccessor"></param>
|
||||
/// <param name="runtimeState"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
/// <param name="stage"></param>
|
||||
/// <returns></returns>
|
||||
public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app,
|
||||
IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,
|
||||
IGlobalSettings globalSettings, IIOHelper ioHelper, IRequestCache requestCache, PipelineStage stage)
|
||||
IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, PipelineStage stage)
|
||||
{
|
||||
if (app == null) throw new ArgumentNullException(nameof(app));
|
||||
if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState));
|
||||
if (ioHelper == null) throw new ArgumentNullException(nameof(ioHelper));
|
||||
if (hostingEnvironment == null) throw new ArgumentNullException(nameof(hostingEnvironment));
|
||||
|
||||
app.UseCookieAuthentication(new CookieAuthenticationOptions
|
||||
{
|
||||
@@ -345,7 +356,7 @@ namespace Umbraco.Web.Security
|
||||
CookieName = Constants.Security.BackOfficeExternalCookieName,
|
||||
ExpireTimeSpan = TimeSpan.FromMinutes(5),
|
||||
//Custom cookie manager so we can filter requests
|
||||
CookieManager = new BackOfficeCookieManager(umbracoContextAccessor, runtimeState, ioHelper, requestCache),
|
||||
CookieManager = new BackOfficeCookieManager(umbracoContextAccessor, runtimeState, hostingEnvironment, globalSettings, requestCache),
|
||||
CookiePath = "/",
|
||||
CookieSecure = globalSettings.UseHttps ? CookieSecureOption.Always : CookieSecureOption.SameAsRequest,
|
||||
CookieHttpOnly = true,
|
||||
@@ -364,6 +375,8 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="securitySettings"></param>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This ensures that during a preview request that the back office use is also Authenticated and that the back office Identity
|
||||
@@ -372,9 +385,9 @@ namespace Umbraco.Web.Security
|
||||
/// <remarks>
|
||||
/// By default this will be configured to execute on PipelineStage.PostAuthenticate
|
||||
/// </remarks>
|
||||
public static IAppBuilder UseUmbracoPreviewAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySettings securitySettings, IIOHelper ioHelper, IRequestCache requestCache)
|
||||
public static IAppBuilder UseUmbracoPreviewAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySettings securitySettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache)
|
||||
{
|
||||
return app.UseUmbracoPreviewAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySettings, ioHelper, requestCache, PipelineStage.PostAuthenticate);
|
||||
return app.UseUmbracoPreviewAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySettings, hostingEnvironment, requestCache, PipelineStage.PostAuthenticate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -386,18 +399,20 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="securitySettings"></param>
|
||||
/// <param name="ioHelper"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
/// <param name="stage"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This ensures that during a preview request that the back office use is also Authenticated and that the back office Identity
|
||||
/// is added as a secondary identity to the current IPrincipal so it can be used to Authorize the previewed document.
|
||||
/// </remarks>
|
||||
public static IAppBuilder UseUmbracoPreviewAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySettings securitySettings, IIOHelper ioHelper, IRequestCache requestCache, PipelineStage stage)
|
||||
public static IAppBuilder UseUmbracoPreviewAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySettings securitySettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, PipelineStage stage)
|
||||
{
|
||||
if (runtimeState.Level != RuntimeLevel.Run) return app;
|
||||
|
||||
var authOptions = app.CreateUmbracoCookieAuthOptions(umbracoContextAccessor, globalSettings, runtimeState, securitySettings, ioHelper, requestCache);
|
||||
app.Use(typeof(PreviewAuthenticationMiddleware), authOptions, ioHelper);
|
||||
var authOptions = app.CreateUmbracoCookieAuthOptions(umbracoContextAccessor, globalSettings, runtimeState, securitySettings, hostingEnvironment, requestCache);
|
||||
app.Use(typeof(PreviewAuthenticationMiddleware), authOptions, globalSettings, hostingEnvironment);
|
||||
|
||||
// This middleware must execute at least on PostAuthentication, by default it is on Authorize
|
||||
// The middleware needs to execute after the RoleManagerModule executes which is during PostAuthenticate,
|
||||
@@ -423,11 +438,13 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="runtimeState"></param>
|
||||
/// <param name="securitySettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="requestCache"></param>
|
||||
/// <param name="explicitPaths"></param>
|
||||
/// <returns></returns>
|
||||
public static UmbracoBackOfficeCookieAuthOptions CreateUmbracoCookieAuthOptions(this IAppBuilder app,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IGlobalSettings globalSettings, IRuntimeState runtimeState, ISecuritySettings securitySettings, IIOHelper ioHelper, IRequestCache requestCache, string[] explicitPaths = null)
|
||||
IGlobalSettings globalSettings, IRuntimeState runtimeState, ISecuritySettings securitySettings, IHostingEnvironment hostingEnvironment, IRequestCache requestCache, string[] explicitPaths = null)
|
||||
{
|
||||
//this is how aspnet wires up the default AuthenticationTicket protector so we'll use the same code
|
||||
var ticketDataFormat = new TicketDataFormat(
|
||||
@@ -440,9 +457,9 @@ namespace Umbraco.Web.Security
|
||||
umbracoContextAccessor,
|
||||
securitySettings,
|
||||
globalSettings,
|
||||
hostingEnvironment,
|
||||
runtimeState,
|
||||
ticketDataFormat,
|
||||
ioHelper,
|
||||
requestCache);
|
||||
|
||||
return authOptions;
|
||||
|
||||
@@ -11,6 +11,7 @@ using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
|
||||
namespace Umbraco.Web.Security
|
||||
{
|
||||
@@ -19,15 +20,15 @@ namespace Umbraco.Web.Security
|
||||
private readonly IUserService _userService;
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly ISecuritySettings _securitySettings;
|
||||
|
||||
public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings, IIOHelper ioHelper, ISecuritySettings securitySettings)
|
||||
public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, ISecuritySettings securitySettings)
|
||||
{
|
||||
_userService = userService;
|
||||
_runtimeState = runtimeState;
|
||||
_globalSettings = globalSettings;
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_securitySettings = securitySettings;
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ namespace Umbraco.Web.Security
|
||||
protected virtual async Task EnsureValidSessionId(CookieValidateIdentityContext context)
|
||||
{
|
||||
if (_runtimeState.Level == RuntimeLevel.Run)
|
||||
await SessionIdValidator.ValidateSessionAsync(TimeSpan.FromMinutes(1), context, _globalSettings, _ioHelper);
|
||||
await SessionIdValidator.ValidateSessionAsync(TimeSpan.FromMinutes(1), context, _globalSettings, _hostingEnvironment);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using Microsoft.Owin.Infrastructure;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Security;
|
||||
|
||||
@@ -23,23 +24,26 @@ namespace Umbraco.Web.Security
|
||||
{
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IRuntimeState _runtime;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IRequestCache _requestCache;
|
||||
private readonly string[] _explicitPaths;
|
||||
private readonly string _getRemainingSecondsPath;
|
||||
|
||||
public BackOfficeCookieManager(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IIOHelper ioHelper, IRequestCache requestCache)
|
||||
: this(umbracoContextAccessor, runtime, ioHelper,requestCache, null)
|
||||
public BackOfficeCookieManager(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IHostingEnvironment hostingEnvironment, IGlobalSettings globalSettings, IRequestCache requestCache)
|
||||
: this(umbracoContextAccessor, runtime, hostingEnvironment, globalSettings, requestCache, null)
|
||||
{ }
|
||||
|
||||
public BackOfficeCookieManager(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IIOHelper ioHelper, IRequestCache requestCache, IEnumerable<string> explicitPaths)
|
||||
public BackOfficeCookieManager(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IHostingEnvironment hostingEnvironment, IGlobalSettings globalSettings, IRequestCache requestCache, IEnumerable<string> explicitPaths)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_runtime = runtime;
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_globalSettings = globalSettings;
|
||||
_requestCache = requestCache;
|
||||
_explicitPaths = explicitPaths?.ToArray();
|
||||
_getRemainingSecondsPath = $"{ioHelper.BackOfficePath}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds";
|
||||
var backOfficePath = _globalSettings.GetBackOfficePath(_hostingEnvironment);
|
||||
_getRemainingSecondsPath = $"{backOfficePath}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,9 +107,9 @@ namespace Umbraco.Web.Security
|
||||
(checkForceAuthTokens && owinContext.Get<bool?>(Constants.Security.ForceReAuthFlag) != null)
|
||||
|| (checkForceAuthTokens && _requestCache.IsAvailable && _requestCache.Get(Constants.Security.ForceReAuthFlag) != null)
|
||||
//check back office
|
||||
|| request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _ioHelper)
|
||||
|| request.Uri.IsBackOfficeRequest(_globalSettings, _hostingEnvironment)
|
||||
//check installer
|
||||
|| request.Uri.IsInstallerRequest(_ioHelper))
|
||||
|| request.Uri.IsInstallerRequest(_hostingEnvironment))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Microsoft.Owin.Logging;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Security;
|
||||
|
||||
@@ -27,7 +28,7 @@ namespace Umbraco.Web.Security
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly ISecuritySettings _security;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public GetUserSecondsMiddleWare(
|
||||
OwinMiddleware next,
|
||||
@@ -35,14 +36,14 @@ namespace Umbraco.Web.Security
|
||||
IGlobalSettings globalSettings,
|
||||
ISecuritySettings security,
|
||||
ILogger logger,
|
||||
IIOHelper ioHelper)
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
: base(next)
|
||||
{
|
||||
_authOptions = authOptions ?? throw new ArgumentNullException(nameof(authOptions));
|
||||
_globalSettings = globalSettings;
|
||||
_security = security;
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
public override async Task Invoke(IOwinContext context)
|
||||
@@ -52,7 +53,7 @@ namespace Umbraco.Web.Security
|
||||
|
||||
if (request.Uri.Scheme.InvariantStartsWith("http")
|
||||
&& request.Uri.AbsolutePath.InvariantEquals(
|
||||
$"{_ioHelper.BackOfficePath}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"))
|
||||
$"{_globalSettings.GetBackOfficePath(_hostingEnvironment)}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"))
|
||||
{
|
||||
var cookie = _authOptions.CookieManager.GetRequestCookie(context, _security.AuthCookieName);
|
||||
if (cookie.IsNullOrWhiteSpace() == false)
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Web;
|
||||
using Microsoft.Owin;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Security;
|
||||
|
||||
@@ -12,7 +13,8 @@ namespace Umbraco.Web.Security
|
||||
internal class PreviewAuthenticationMiddleware : OwinMiddleware
|
||||
{
|
||||
private readonly UmbracoBackOfficeCookieAuthOptions _cookieOptions;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates the middleware with an optional pointer to the next component.
|
||||
@@ -20,11 +22,13 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="next"/>
|
||||
/// <param name="cookieOptions"></param>
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
public PreviewAuthenticationMiddleware(OwinMiddleware next,
|
||||
UmbracoBackOfficeCookieAuthOptions cookieOptions, IIOHelper ioHelper) : base(next)
|
||||
UmbracoBackOfficeCookieAuthOptions cookieOptions, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) : base(next)
|
||||
{
|
||||
_cookieOptions = cookieOptions;
|
||||
_ioHelper = ioHelper;
|
||||
_globalSettings = globalSettings;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,7 +45,7 @@ namespace Umbraco.Web.Security
|
||||
var isPreview = request.HasPreviewCookie()
|
||||
&& claimsPrincipal != null
|
||||
&& request.Uri != null
|
||||
&& request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _ioHelper) == false;
|
||||
&& request.Uri.IsBackOfficeRequest(_globalSettings, _hostingEnvironment) == false;
|
||||
if (isPreview)
|
||||
{
|
||||
//If we've gotten this far it means a preview cookie has been set and a front-end umbraco document request is executing.
|
||||
|
||||
@@ -9,6 +9,7 @@ using Microsoft.Owin.Infrastructure;
|
||||
using Microsoft.Owin.Security.Cookies;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
@@ -29,9 +30,9 @@ namespace Umbraco.Web.Security
|
||||
{
|
||||
public const string CookieName = "UMB_UCONTEXT_C";
|
||||
|
||||
public static async Task ValidateSessionAsync(TimeSpan validateInterval, CookieValidateIdentityContext context, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
public static async Task ValidateSessionAsync(TimeSpan validateInterval, CookieValidateIdentityContext context, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
if (context.Request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, ioHelper) == false)
|
||||
if (context.Request.Uri.IsBackOfficeRequest(globalSettings, hostingEnvironment) == false)
|
||||
return;
|
||||
|
||||
var valid = await ValidateSessionAsync(validateInterval, context.OwinContext, context.Options.CookieManager, context.Options.SystemClock, context.Properties.IssuedUtc, context.Identity, globalSettings);
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Web.Security
|
||||
@@ -22,9 +23,9 @@ namespace Umbraco.Web.Security
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
ISecuritySettings securitySettings,
|
||||
IGlobalSettings globalSettings,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IRuntimeState runtimeState,
|
||||
ISecureDataFormat<AuthenticationTicket> secureDataFormat,
|
||||
IIOHelper ioHelper,
|
||||
IRequestCache requestCache)
|
||||
{
|
||||
var secureDataFormat1 = secureDataFormat ?? throw new ArgumentNullException(nameof(secureDataFormat));
|
||||
@@ -42,7 +43,7 @@ namespace Umbraco.Web.Security
|
||||
TicketDataFormat = new UmbracoSecureDataFormat(LoginTimeoutMinutes, secureDataFormat1);
|
||||
|
||||
//Custom cookie manager so we can filter requests
|
||||
CookieManager = new BackOfficeCookieManager(umbracoContextAccessor, runtimeState, ioHelper, requestCache, explicitPaths);
|
||||
CookieManager = new BackOfficeCookieManager(umbracoContextAccessor, runtimeState, hostingEnvironment, globalSettings, requestCache, explicitPaths);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,6 +8,7 @@ using Umbraco.Core.Models.Membership;
|
||||
using Microsoft.AspNet.Identity.Owin;
|
||||
using Microsoft.Owin;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models.Identity;
|
||||
@@ -23,14 +24,14 @@ namespace Umbraco.Web.Security
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public WebSecurity(IHttpContextAccessor httpContextAccessor, IUserService userService, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
public WebSecurity(IHttpContextAccessor httpContextAccessor, IUserService userService, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userService = userService;
|
||||
_globalSettings = globalSettings;
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
private IUser _currentUser;
|
||||
@@ -145,7 +146,7 @@ namespace Umbraco.Web.Security
|
||||
var user = CurrentUser;
|
||||
|
||||
// Check for console access
|
||||
if (user == null || (requiresApproval && user.IsApproved == false) || (user.IsLockedOut && RequestIsInUmbracoApplication(_httpContextAccessor, _globalSettings, _ioHelper)))
|
||||
if (user == null || (requiresApproval && user.IsApproved == false) || (user.IsLockedOut && RequestIsInUmbracoApplication(_httpContextAccessor, _globalSettings, _hostingEnvironment)))
|
||||
{
|
||||
if (throwExceptions) throw new ArgumentException("You have no privileges to the umbraco console. Please contact your administrator");
|
||||
return ValidateRequestAttempt.FailedNoPrivileges;
|
||||
@@ -154,9 +155,9 @@ namespace Umbraco.Web.Security
|
||||
|
||||
}
|
||||
|
||||
private static bool RequestIsInUmbracoApplication(IHttpContextAccessor httpContextAccessor, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
private static bool RequestIsInUmbracoApplication(IHttpContextAccessor httpContextAccessor, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
return httpContextAccessor.GetRequiredHttpContext().Request.Path.ToLower().IndexOf(ioHelper.ResolveUrl(globalSettings.UmbracoPath).ToLower(), StringComparison.Ordinal) > -1;
|
||||
return httpContextAccessor.GetRequiredHttpContext().Request.Path.ToLower().IndexOf(hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath).ToLower(), StringComparison.Ordinal) > -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Web;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Cookie;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web.Composing;
|
||||
@@ -19,8 +20,7 @@ namespace Umbraco.Web
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly UriUtility _uriUtility;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly ICookieManager _cookieManager;
|
||||
private readonly Lazy<IPublishedSnapshot> _publishedSnapshot;
|
||||
private string _previewToken;
|
||||
@@ -34,8 +34,8 @@ namespace Umbraco.Web
|
||||
IPublishedSnapshotService publishedSnapshotService,
|
||||
IWebSecurity webSecurity,
|
||||
IGlobalSettings globalSettings,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
IIOHelper ioHelper,
|
||||
UriUtility uriUtility,
|
||||
ICookieManager cookieManager)
|
||||
{
|
||||
@@ -45,8 +45,7 @@ namespace Umbraco.Web
|
||||
VariationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_uriUtility = uriUtility;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_cookieManager = cookieManager;
|
||||
|
||||
// ensure that this instance is disposed when the request terminates, though we *also* ensure
|
||||
@@ -74,7 +73,7 @@ namespace Umbraco.Web
|
||||
// see: http://issues.umbraco.org/issue/U4-1890
|
||||
//
|
||||
OriginalRequestUrl = GetRequestFromContext()?.Url ?? new Uri("http://localhost");
|
||||
CleanedUmbracoUrl = _uriUtility.UriToUmbraco(OriginalRequestUrl);
|
||||
CleanedUmbracoUrl = uriUtility.UriToUmbraco(OriginalRequestUrl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -184,7 +183,7 @@ namespace Umbraco.Web
|
||||
{
|
||||
var request = GetRequestFromContext();
|
||||
if (request?.Url != null
|
||||
&& request.Url.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _ioHelper) == false
|
||||
&& request.Url.IsBackOfficeRequest(_globalSettings, _hostingEnvironment) == false
|
||||
&& Security.CurrentUser != null)
|
||||
{
|
||||
var previewToken = _cookieManager.GetPreviewCookieValue(); // may be null or empty
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Cookie;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
@@ -25,7 +26,7 @@ namespace Umbraco.Web
|
||||
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ICookieManager _cookieManager;
|
||||
private readonly UriUtility _uriUtility;
|
||||
@@ -40,7 +41,7 @@ namespace Umbraco.Web
|
||||
IDefaultCultureAccessor defaultCultureAccessor,
|
||||
IGlobalSettings globalSettings,
|
||||
IUserService userService,
|
||||
IIOHelper ioHelper,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
UriUtility uriUtility,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
ICookieManager cookieManager)
|
||||
@@ -51,7 +52,7 @@ namespace Umbraco.Web
|
||||
_defaultCultureAccessor = defaultCultureAccessor ?? throw new ArgumentNullException(nameof(defaultCultureAccessor));
|
||||
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
|
||||
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_uriUtility = uriUtility;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_cookieManager = cookieManager;
|
||||
@@ -70,9 +71,9 @@ namespace Umbraco.Web
|
||||
_variationContextAccessor.VariationContext = new VariationContext(_defaultCultureAccessor.DefaultCulture);
|
||||
}
|
||||
|
||||
var webSecurity = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _ioHelper);
|
||||
var webSecurity = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _hostingEnvironment);
|
||||
|
||||
return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _variationContextAccessor, _ioHelper, _uriUtility, _cookieManager);
|
||||
return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _hostingEnvironment, _variationContextAccessor, _uriUtility, _cookieManager);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -5,6 +5,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Net;
|
||||
@@ -35,7 +36,7 @@ namespace Umbraco.Web
|
||||
protected ServiceContext Services => Current.Services;
|
||||
protected UmbracoMapper Mapper => Current.Mapper;
|
||||
protected IIpResolver IpResolver => Current.IpResolver;
|
||||
protected IIOHelper IOHelper => Current.IOHelper;
|
||||
protected IHostingEnvironment HostingEnvironment => Current.HostingEnvironment;
|
||||
protected IRequestCache RequestCache => Current.AppCaches.RequestCache;
|
||||
|
||||
/// <summary>
|
||||
@@ -76,7 +77,7 @@ namespace Umbraco.Web
|
||||
ConfigureUmbracoAuthentication(app);
|
||||
|
||||
app
|
||||
.UseSignalR(IOHelper)
|
||||
.UseSignalR(GlobalSettings, HostingEnvironment)
|
||||
.FinalizeMiddlewareConfiguration();
|
||||
}
|
||||
|
||||
@@ -105,9 +106,9 @@ namespace Umbraco.Web
|
||||
// Ensure owin is configured for Umbraco back office authentication.
|
||||
// Front-end OWIN cookie configuration must be declared after this code.
|
||||
app
|
||||
.UseUmbracoBackOfficeCookieAuthentication(UmbracoContextAccessor, RuntimeState, Services.UserService, GlobalSettings, SecuritySettings, IOHelper, RequestCache, PipelineStage.Authenticate)
|
||||
.UseUmbracoBackOfficeExternalCookieAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, IOHelper, RequestCache, PipelineStage.Authenticate)
|
||||
.UseUmbracoPreviewAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, SecuritySettings, IOHelper, RequestCache, PipelineStage.Authorize);
|
||||
.UseUmbracoBackOfficeCookieAuthentication(UmbracoContextAccessor, RuntimeState, Services.UserService, GlobalSettings, SecuritySettings, HostingEnvironment, RequestCache, PipelineStage.Authenticate)
|
||||
.UseUmbracoBackOfficeExternalCookieAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, HostingEnvironment, RequestCache, PipelineStage.Authenticate)
|
||||
.UseUmbracoPreviewAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, SecuritySettings, HostingEnvironment, RequestCache, PipelineStage.Authorize);
|
||||
}
|
||||
|
||||
public static event EventHandler<OwinMiddlewareConfiguredEventArgs> MiddlewareConfigured;
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Composing;
|
||||
@@ -37,7 +38,8 @@ namespace Umbraco.Web
|
||||
private readonly IUmbracoContextFactory _umbracoContextFactory;
|
||||
private readonly RoutableDocumentFilter _routableDocumentLookup;
|
||||
private readonly IRequestCache _requestCache;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly UriUtility _uriUtility;
|
||||
|
||||
public UmbracoInjectedModule(
|
||||
@@ -48,7 +50,8 @@ namespace Umbraco.Web
|
||||
RoutableDocumentFilter routableDocumentLookup,
|
||||
UriUtility uriUtility,
|
||||
IRequestCache requestCache,
|
||||
IIOHelper ioHelper)
|
||||
IGlobalSettings globalSettings,
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_runtime = runtime;
|
||||
_logger = logger;
|
||||
@@ -57,7 +60,8 @@ namespace Umbraco.Web
|
||||
_routableDocumentLookup = routableDocumentLookup;
|
||||
_uriUtility = uriUtility;
|
||||
_requestCache = requestCache;
|
||||
_ioHelper = ioHelper;
|
||||
_globalSettings = globalSettings;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
#region HttpModule event handlers
|
||||
@@ -111,7 +115,7 @@ namespace Umbraco.Web
|
||||
var umbracoContext = Current.UmbracoContext;
|
||||
|
||||
// re-write for the default back office path
|
||||
if (httpContext.Request.Url.IsDefaultBackOfficeRequest(_ioHelper))
|
||||
if (httpContext.Request.Url.IsDefaultBackOfficeRequest(_globalSettings, _hostingEnvironment))
|
||||
{
|
||||
if (EnsureRuntime(httpContext, umbracoContext.OriginalRequestUrl))
|
||||
RewriteToBackOfficeHandler(httpContext);
|
||||
@@ -257,7 +261,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 = _ioHelper.BackOfficePath.TrimEnd('/') + "/Default";
|
||||
var rewritePath = _globalSettings.GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/Default";
|
||||
// rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc)
|
||||
context.RewritePath(rewritePath, "", "", false);
|
||||
|
||||
@@ -290,7 +294,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 = _ioHelper.BackOfficePath.TrimEnd('/') + "/RenderMvc";
|
||||
var rewritePath = _globalSettings.GetBackOfficePath(_hostingEnvironment).TrimEnd('/') + "/RenderMvc";
|
||||
// rewrite the path to the path of the handler (i.e. /umbraco/RenderMvc)
|
||||
context.RewritePath(rewritePath, "", query, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user