This commit is contained in:
Bjarke Berg
2020-02-17 09:04:15 +01:00
parent 7a55852cbb
commit f2b1558cb1
6 changed files with 18 additions and 23 deletions

View File

@@ -24,8 +24,6 @@ namespace Umbraco.Web
private static bool _registered;
// ReSharper restore StaticMemberInGenericType
// private readonly IHttpContextAccessor _httpContextAccessor;
protected abstract string ItemKey { get; }
// read

View File

@@ -14,23 +14,22 @@ namespace Umbraco.Web
/// </remarks>
public class UmbracoContextReference : IDisposable //fixme - should we inherit from DisposableObjectSlim?
{
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private bool _disposed;
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoContextReference"/> class.
/// </summary>
internal UmbracoContextReference(bool isRoot, IUmbracoContextAccessor umbracoContextAccessor)
internal UmbracoContextReference(bool isRoot, IUmbracoContext umbracoContext)
{
IsRoot = isRoot;
_umbracoContextAccessor = umbracoContextAccessor;
UmbracoContext = umbracoContext;
}
/// <summary>
/// Gets the <see cref="UmbracoContext"/>.
/// </summary>
public IUmbracoContext UmbracoContext => _umbracoContextAccessor.UmbracoContext;
public IUmbracoContext UmbracoContext { get; private set; }
/// <summary>
/// Gets a value indicating whether the reference is a root reference.
@@ -50,7 +49,7 @@ namespace Umbraco.Web
if (IsRoot)
{
UmbracoContext.Dispose();
_umbracoContextAccessor.UmbracoContext = null;
UmbracoContext = null;
}
GC.SuppressFinalize(this);

View File

@@ -6,15 +6,12 @@ using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Web.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Migrations.Install;
using Umbraco.Core.Models.Identity;
using Umbraco.Core.Services;
using Umbraco.Web.Install.Models;
using Umbraco.Web.Models.Identity;
using Umbraco.Web.Security;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Cookie;
namespace Umbraco.Web.Install.InstallSteps
{
@@ -37,8 +34,9 @@ namespace Umbraco.Web.Install.InstallSteps
private readonly IUserPasswordConfiguration _passwordConfiguration;
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
private readonly IConnectionStrings _connectionStrings;
private readonly ICookieManager _cookieManager;
public NewInstallStep(IHttpContextAccessor httpContextAccessor, IUserService userService, DatabaseBuilder databaseBuilder, IGlobalSettings globalSettings, IUserPasswordConfiguration passwordConfiguration, IUmbracoSettingsSection umbracoSettingsSection, IConnectionStrings connectionStrings)
public NewInstallStep(IHttpContextAccessor httpContextAccessor, IUserService userService, DatabaseBuilder databaseBuilder, IGlobalSettings globalSettings, IUserPasswordConfiguration passwordConfiguration, IUmbracoSettingsSection umbracoSettingsSection, IConnectionStrings connectionStrings, ICookieManager cookieManager)
{
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
@@ -47,6 +45,7 @@ namespace Umbraco.Web.Install.InstallSteps
_passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration));
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
_connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings));
_cookieManager = cookieManager;
}
public override async Task<InstallSetupResult> ExecuteAsync(UserModel user)
@@ -137,7 +136,7 @@ namespace Umbraco.Web.Install.InstallSteps
// In this one case when it's a brand new install and nothing has been configured, make sure the
// back office cookie is cleared so there's no old cookies lying around causing problems
_httpContextAccessor.HttpContext.ExpireCookie(_umbracoSettingsSection.Security.AuthCookieName);
_cookieManager.ExpireCookie(_umbracoSettingsSection.Security.AuthCookieName);
return true;
}

View File

@@ -10,7 +10,13 @@ namespace Umbraco.Web
get
{
var httpContext = System.Web.HttpContext.Current;
return httpContext is null ? null : new HttpContextWrapper(httpContext);
if (httpContext is null)
{
throw new InvalidOperationException("HttpContext is not available");
}
return new HttpContextWrapper(httpContext);
}
set
{

View File

@@ -101,13 +101,6 @@ namespace Umbraco.Web.Security
Core.Constants.Security.BackOfficeExternalAuthenticationType);
}
/// <summary>
/// Renews the user's login ticket
/// </summary>
public void RenewLoginTimeout()
{
_httpContextAccessor.HttpContext.RenewUmbracoAuthTicket();
}
/// <summary>
/// Gets the current user's id.

View File

@@ -72,13 +72,13 @@ namespace Umbraco.Web
{
var currentUmbracoContext = _umbracoContextAccessor.UmbracoContext;
if (currentUmbracoContext != null)
return new UmbracoContextReference(false, _umbracoContextAccessor);
return new UmbracoContextReference(false, currentUmbracoContext);
var umbracoContext = CreateUmbracoContext();
_umbracoContextAccessor.UmbracoContext = umbracoContext;
return new UmbracoContextReference(true, _umbracoContextAccessor);
return new UmbracoContextReference(true, umbracoContext);
}
// dummy TextWriter that does not write