Move files

This commit is contained in:
Bjarke Berg
2020-02-13 12:29:08 +01:00
parent 392828fcb2
commit 31130be85a
18 changed files with 89 additions and 125 deletions

View File

@@ -6,7 +6,7 @@ namespace Umbraco.Web.Models.PublishedContent
/// <summary>
/// Implements a hybrid <see cref="IVariationContextAccessor"/>.
/// </summary>
internal class HybridVariationContextAccessor : HybridAccessorBase<VariationContext>, IVariationContextAccessor
public class HybridVariationContextAccessor : HybridAccessorBase<VariationContext>, IVariationContextAccessor
{
public HybridVariationContextAccessor(IRequestCache requestCache)
: base(requestCache)

View File

@@ -14,16 +14,14 @@ namespace Umbraco.Web.Models.PublishedContent
{
private readonly ILocalizationService _localizationService;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IPublishedValueFallback _publishedValueFallback;
/// <summary>
/// Initializes a new instance of the <see cref="PublishedValueFallback"/> class.
/// </summary>
public PublishedValueFallback(ServiceContext serviceContext, IVariationContextAccessor variationContextAccessor, IPublishedValueFallback publishedValueFallback)
public PublishedValueFallback(ServiceContext serviceContext, IVariationContextAccessor variationContextAccessor)
{
_localizationService = serviceContext.LocalizationService;
_variationContextAccessor = variationContextAccessor;
_publishedValueFallback = publishedValueFallback;
}
/// <inheritdoc />
@@ -184,7 +182,7 @@ namespace Umbraco.Web.Models.PublishedContent
// if we found a content with the property having a value, return that property value
if (property != null && property.HasValue(culture, segment))
{
value = property.Value<T>(_publishedValueFallback, culture, segment);
value = property.Value<T>(this, culture, segment);
return true;
}
@@ -218,7 +216,7 @@ namespace Umbraco.Web.Models.PublishedContent
if (property.HasValue(culture2, segment))
{
value = property.Value<T>(_publishedValueFallback, culture2, segment);
value = property.Value<T>(this, culture2, segment);
return true;
}
@@ -252,7 +250,7 @@ namespace Umbraco.Web.Models.PublishedContent
if (content.HasValue(alias, culture2, segment))
{
value = content.Value<T>(_publishedValueFallback, alias, culture2, segment);
value = content.Value<T>(this, alias, culture2, segment);
return true;
}
@@ -289,7 +287,7 @@ namespace Umbraco.Web.Models.PublishedContent
if (content.HasValue(alias, culture2, segment))
{
value = content.Value<T>(_publishedValueFallback, alias, culture2, segment);
value = content.Value<T>(this, alias, culture2, segment);
return true;
}

View File

@@ -153,6 +153,8 @@ namespace Umbraco.Tests.Cache
};
var httpContextAccessor = TestObjects.GetHttpContextAccessor();
var umbracoContextFactory = new UmbracoContextFactory(
new TestUmbracoContextAccessor(),
Mock.Of<IPublishedSnapshotService>(),
@@ -163,7 +165,8 @@ namespace Umbraco.Tests.Cache
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
IOHelper);
IOHelper,
httpContextAccessor);
// just assert it does not throw
var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null);

View File

@@ -74,10 +74,12 @@ namespace Umbraco.Tests.Cache.PublishedCache
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedShapshot);
var httpContext = _httpContextFactory.HttpContext;
var httpContextAccessor = TestObjects.GetHttpContextAccessor(httpContext);
_umbracoContext = new UmbracoContext(
_httpContextFactory.HttpContext,
httpContext,
publishedSnapshotService.Object,
new WebSecurity(_httpContextFactory.HttpContext, Mock.Of<IUserService>(), globalSettings, IOHelper),
new WebSecurity(httpContextAccessor, Mock.Of<IUserService>(), globalSettings, IOHelper),
umbracoSettings,
Enumerable.Empty<IUrlProvider>(),
Enumerable.Empty<IMediaUrlProvider>(),

View File

@@ -68,10 +68,12 @@ namespace Umbraco.Tests.PublishedContent
var globalSettings = TestObjects.GetGlobalSettings();
var httpContext = GetHttpContextFactory("http://umbraco.local/", routeData).HttpContext;
var httpContextAccessor = TestObjects.GetHttpContextAccessor(httpContext);
var umbracoContext = new UmbracoContext(
httpContext,
publishedSnapshotService.Object,
new WebSecurity(httpContext, Current.Services.UserService, globalSettings, IOHelper),
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
Enumerable.Empty<IMediaUrlProvider>(),

View File

@@ -117,12 +117,12 @@ namespace Umbraco.Tests.Scoping
var service = PublishedSnapshotService as PublishedSnapshotService;
var httpContext = GetHttpContextFactory(url, routeData).HttpContext;
var httpContextAccessor = TestObjects.GetHttpContextAccessor(httpContext);
var globalSettings = TestObjects.GetGlobalSettings();
var umbracoContext = new UmbracoContext(
httpContext,
service,
new WebSecurity(httpContext, Current.Services.UserService, globalSettings, IOHelper),
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
umbracoSettings ?? SettingsForTests.GetDefaultUmbracoSettings(),
urlProviders ?? Enumerable.Empty<IUrlProvider>(),
Enumerable.Empty<IMediaUrlProvider>(),

View File

@@ -28,11 +28,12 @@ namespace Umbraco.Tests.Security
//should force app ctx to show not-configured
ConfigurationManager.AppSettings.Set(Constants.AppSettings.ConfigurationStatus, "");
var httpContextAccessor = TestObjects.GetHttpContextAccessor();
var globalSettings = TestObjects.GetGlobalSettings();
var umbracoContext = new UmbracoContext(
Mock.Of<HttpContextBase>(),
Mock.Of<IPublishedSnapshotService>(),
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings, IOHelper),
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), Enumerable.Empty<IMediaUrlProvider>(), globalSettings,
new TestVariationContextAccessor(), IOHelper);
@@ -48,11 +49,12 @@ namespace Umbraco.Tests.Security
[Test]
public void ShouldAuthenticateRequest_When_Configured()
{
var httpContextAccessor = TestObjects.GetHttpContextAccessor();
var globalSettings = TestObjects.GetGlobalSettings();
var umbCtx = new UmbracoContext(
Mock.Of<HttpContextBase>(),
Mock.Of<IPublishedSnapshotService>(),
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings, IOHelper),
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), Enumerable.Empty<IMediaUrlProvider>(), globalSettings,
new TestVariationContextAccessor(), IOHelper);

View File

@@ -127,6 +127,8 @@ namespace Umbraco.Tests.TestHelpers
if (accessor == null) accessor = new TestUmbracoContextAccessor();
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbracoContextFactory = new UmbracoContextFactory(
accessor,
publishedSnapshotService,
@@ -137,7 +139,8 @@ namespace Umbraco.Tests.TestHelpers
urlProviders,
mediaUrlProviders,
Mock.Of<IUserService>(),
TestHelper.IOHelper);
TestHelper.IOHelper,
httpContextAccessor);
return umbracoContextFactory.EnsureUmbracoContext(httpContext).UmbracoContext;
}

View File

@@ -380,11 +380,11 @@ namespace Umbraco.Tests.TestHelpers
}
var httpContext = GetHttpContextFactory(url, routeData).HttpContext;
var httpContextAccessor = TestObjects.GetHttpContextAccessor(httpContext);
var umbracoContext = new UmbracoContext(
httpContext,
service,
new WebSecurity(httpContext, Factory.GetInstance<IUserService>(),
new WebSecurity(httpContextAccessor, Factory.GetInstance<IUserService>(),
Factory.GetInstance<IGlobalSettings>(), IOHelper),
umbracoSettings ?? Factory.GetInstance<IUmbracoSettingsSection>(),
urlProviders ?? Enumerable.Empty<IUrlProvider>(),

View File

@@ -33,6 +33,8 @@ namespace Umbraco.Tests.Testing.Objects
var snapshotService = new Mock<IPublishedSnapshotService>();
snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(snapshot.Object);
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbracoContextFactory = new UmbracoContextFactory(
umbracoContextAccessor,
snapshotService.Object,
@@ -43,7 +45,8 @@ namespace Umbraco.Tests.Testing.Objects
new UrlProviderCollection(new[] { urlProvider }),
new MediaUrlProviderCollection(new[] { mediaUrlProvider }),
Mock.Of<IUserService>(),
TestHelper.IOHelper);
TestHelper.IOHelper,
httpContextAccessor);
return umbracoContextFactory;
}

View File

@@ -1,74 +0,0 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Umbraco.Web" />
<add namespace="Umbraco.Core" />
<add namespace="Umbraco.Core.Models" />
<add namespace="Umbraco.Core.Models.PublishedContent" />
<add namespace="Umbraco.Web.Mvc" />
<add namespace="Examine" />
<add namespace="Umbraco.Web.PublishedModels" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
<system.web>
<compilation targetFramework="4.7.2">
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<!--
Views are compiled by the Microsoft.CodeDom.Providers.DotNetCompilerPlatform which uses the Roslyn compiler
from ~/bin/roslyn to expose an ICodeProvider implementation to System.CodeDom.
For instance, starting with package 1.4.0 (which contains version 1.2.2.0) System.Collections.Immutable
lists netstandard2.0 as a supported target, whereas package 1.3.1 only listed net45. So now, when
installing, NuGet picks the netstandard2.0 version, thus introducing a dependency to netstandard2.0.
Somehow, transitive dependencies are not working correctly, and either (a) NuGet fails to properly
register this dependency, or (b) when reference assemblies are gathered before compiling views, this
dependency is missed. In any case, the result is that the ICodeProvider is passed a list of referenced
assemblies that is missing .NET Standard.
It may be a mix of both. NuGet registers the dependency well enough, that we can actually build the
whole application - but it is not doing something that is required in order to have .NET Standard
being a dependency when building views.
See also: https://stackoverflow.com/questions/50165910
Funny enough, the CSharpCompiler already explicitly adds System.Runtime as a referenced assembly,
with a comment mentioning an issue. But it's not adding .NET Standard. So, for the time being, to be sure,
we are adding both here.
-->
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
</assemblies>
</compilation>
</system.web>
</configuration>

View File

@@ -63,7 +63,7 @@ namespace Umbraco.Tests.Web.Mvc
var globalSettings = TestObjects.GetGlobalSettings();
var attr = new RenderIndexActionSelectorAttribute();
var req = new RequestContext();
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbracoContextFactory = new UmbracoContextFactory(
Current.UmbracoContextAccessor,
Mock.Of<IPublishedSnapshotService>(),
@@ -74,7 +74,8 @@ namespace Umbraco.Tests.Web.Mvc
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
TestHelper.IOHelper);
TestHelper.IOHelper,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
var umbCtx = umbracoContextReference.UmbracoContext;
@@ -94,6 +95,7 @@ namespace Umbraco.Tests.Web.Mvc
var globalSettings = TestObjects.GetGlobalSettings();
var attr = new RenderIndexActionSelectorAttribute();
var req = new RequestContext();
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbracoContextFactory = new UmbracoContextFactory(
Current.UmbracoContextAccessor,
@@ -105,7 +107,8 @@ namespace Umbraco.Tests.Web.Mvc
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
TestHelper.IOHelper);
TestHelper.IOHelper,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
var umbCtx = umbracoContextReference.UmbracoContext;
@@ -125,6 +128,7 @@ namespace Umbraco.Tests.Web.Mvc
var globalSettings = TestObjects.GetGlobalSettings();
var attr = new RenderIndexActionSelectorAttribute();
var req = new RequestContext();
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbracoContextFactory = new UmbracoContextFactory(
Current.UmbracoContextAccessor,
@@ -136,7 +140,8 @@ namespace Umbraco.Tests.Web.Mvc
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
TestHelper.IOHelper);
TestHelper.IOHelper,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
var umbCtx = umbracoContextReference.UmbracoContext;
@@ -156,6 +161,7 @@ namespace Umbraco.Tests.Web.Mvc
var globalSettings = TestObjects.GetGlobalSettings();
var attr = new RenderIndexActionSelectorAttribute();
var req = new RequestContext();
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbracoContextFactory = new UmbracoContextFactory(
Current.UmbracoContextAccessor,
@@ -167,7 +173,8 @@ namespace Umbraco.Tests.Web.Mvc
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
TestHelper.IOHelper);
TestHelper.IOHelper,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
var umbCtx = umbracoContextReference.UmbracoContext;

View File

@@ -39,6 +39,7 @@ namespace Umbraco.Tests.Web.Mvc
public void Can_Construct_And_Get_Result()
{
var globalSettings = TestObjects.GetGlobalSettings();
var httpContextAccessor = TestObjects.GetHttpContextAccessor();
var umbracoContextFactory = new UmbracoContextFactory(
Current.UmbracoContextAccessor,
@@ -50,7 +51,8 @@ namespace Umbraco.Tests.Web.Mvc
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
IOHelper);
IOHelper,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
var umbracoContext = umbracoContextReference.UmbracoContext;
@@ -68,6 +70,7 @@ namespace Umbraco.Tests.Web.Mvc
public void Umbraco_Context_Not_Null()
{
var globalSettings = TestObjects.GetGlobalSettings();
var httpContextAccessor = TestObjects.GetHttpContextAccessor();
var umbracoContextFactory = new UmbracoContextFactory(
Current.UmbracoContextAccessor,
@@ -79,7 +82,8 @@ namespace Umbraco.Tests.Web.Mvc
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
IOHelper);
IOHelper,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
var umbCtx = umbracoContextReference.UmbracoContext;
@@ -100,6 +104,7 @@ namespace Umbraco.Tests.Web.Mvc
content.Setup(x => x.Id).Returns(2);
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
var globalSettings = TestObjects.GetGlobalSettings();
var httpContextAccessor = TestObjects.GetHttpContextAccessor();
var umbracoContextFactory = new UmbracoContextFactory(
Current.UmbracoContextAccessor,
@@ -111,7 +116,8 @@ namespace Umbraco.Tests.Web.Mvc
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
IOHelper);
IOHelper,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
var umbracoContext = umbracoContextReference.UmbracoContext;
@@ -139,6 +145,7 @@ namespace Umbraco.Tests.Web.Mvc
{
var webRoutingSettings = Mock.Of<IWebRoutingSection>(section => section.UrlProviderMode == "Auto");
var globalSettings = TestObjects.GetGlobalSettings();
var httpContextAccessor = TestObjects.GetHttpContextAccessor();
var umbracoContextFactory = new UmbracoContextFactory(
Current.UmbracoContextAccessor,
@@ -150,7 +157,8 @@ namespace Umbraco.Tests.Web.Mvc
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
Mock.Of<IUserService>(),
IOHelper);
IOHelper,
httpContextAccessor);
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>());
var umbracoContext = umbracoContextReference.UmbracoContext;

View File

@@ -435,12 +435,13 @@ namespace Umbraco.Tests.Web.Mvc
var http = GetHttpContextFactory(url, routeData).HttpContext;
var httpContextAccessor = TestObjects.GetHttpContextAccessor(http);
var globalSettings = TestObjects.GetGlobalSettings();
var ctx = new UmbracoContext(
http,
_service,
new WebSecurity(http, Current.Services.UserService, globalSettings, IOHelper),
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
Enumerable.Empty<IMediaUrlProvider>(),

View File

@@ -26,10 +26,12 @@ namespace Umbraco.Tests.Web
[Test]
public void RouteDataExtensions_GetUmbracoContext()
{
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbCtx = new UmbracoContext(
Mock.Of<HttpContextBase>(),
Mock.Of<IPublishedSnapshotService>(),
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
new WebSecurity(httpContextAccessor, Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
TestObjects.GetUmbracoSettings(),
new List<IUrlProvider>(),
Enumerable.Empty<IMediaUrlProvider>(),
@@ -46,10 +48,12 @@ namespace Umbraco.Tests.Web
[Test]
public void ControllerContextExtensions_GetUmbracoContext_From_RouteValues()
{
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbCtx = new UmbracoContext(
Mock.Of<HttpContextBase>(),
Mock.Of<IPublishedSnapshotService>(),
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
new WebSecurity(httpContextAccessor, Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
TestObjects.GetUmbracoSettings(),
new List<IUrlProvider>(),
Enumerable.Empty<IMediaUrlProvider>(),
@@ -76,10 +80,12 @@ namespace Umbraco.Tests.Web
[Test]
public void ControllerContextExtensions_GetUmbracoContext_From_Current()
{
var httpContextAccessor = Mock.Of<IHttpContextAccessor>();
var umbCtx = new UmbracoContext(
Mock.Of<HttpContextBase>(),
Mock.Of<IPublishedSnapshotService>(),
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
new WebSecurity(httpContextAccessor, Current.Services.UserService, TestObjects.GetGlobalSettings(), IOHelper),
TestObjects.GetUmbracoSettings(),
new List<IUrlProvider>(),
Enumerable.Empty<IMediaUrlProvider>(),

View File

@@ -37,7 +37,7 @@ namespace Umbraco.Web.Install.InstallSteps
public override Task<InstallSetupResult> ExecuteAsync(object model)
{
var security = new WebSecurity(_httpContextAccessor.HttpContext, _userService, _globalSettings, _ioHelper);
var security = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _ioHelper);
if (security.IsAuthenticated() == false && _globalSettings.ConfigurationStatus.IsNullOrWhiteSpace())
{

View File

@@ -22,14 +22,14 @@ namespace Umbraco.Web.Security
/// </summary>
public class WebSecurity : IWebSecurity
{
private readonly HttpContextBase _httpContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IUserService _userService;
private readonly IGlobalSettings _globalSettings;
private readonly IIOHelper _ioHelper;
public WebSecurity(HttpContextBase httpContext, IUserService userService, IGlobalSettings globalSettings, IIOHelper ioHelper)
public WebSecurity(IHttpContextAccessor httpContextAccessor, IUserService userService, IGlobalSettings globalSettings, IIOHelper ioHelper)
{
_httpContext = httpContext;
_httpContextAccessor = httpContextAccessor;
_userService = userService;
_globalSettings = globalSettings;
_ioHelper = ioHelper;
@@ -63,7 +63,7 @@ namespace Umbraco.Web.Security
{
if (_signInManager == null)
{
var mgr = _httpContext.GetOwinContext().Get<BackOfficeSignInManager>();
var mgr = _httpContextAccessor.HttpContext.GetOwinContext().Get<BackOfficeSignInManager>();
if (mgr == null)
{
throw new NullReferenceException("Could not resolve an instance of " + typeof(BackOfficeSignInManager) + " from the " + typeof(IOwinContext));
@@ -76,7 +76,7 @@ namespace Umbraco.Web.Security
private BackOfficeUserManager<BackOfficeIdentityUser> _userManager;
protected BackOfficeUserManager<BackOfficeIdentityUser> UserManager
=> _userManager ?? (_userManager = _httpContext.GetOwinContext().GetBackOfficeUserManager());
=> _userManager ?? (_userManager = _httpContextAccessor.HttpContext.GetOwinContext().GetBackOfficeUserManager());
/// <summary>
/// Logs a user in.
@@ -85,7 +85,7 @@ namespace Umbraco.Web.Security
/// <returns>returns the number of seconds until their session times out</returns>
public virtual double PerformLogin(int userId)
{
var owinCtx = _httpContext.GetOwinContext();
var owinCtx = _httpContextAccessor.HttpContext.GetOwinContext();
//ensure it's done for owin too
owinCtx.Authentication.SignOut(Constants.Security.BackOfficeExternalAuthenticationType);
@@ -93,7 +93,7 @@ namespace Umbraco.Web.Security
SignInManager.SignInAsync(user, isPersistent: true, rememberBrowser: false).Wait();
_httpContext.SetPrincipalForRequest(owinCtx.Request.User);
_httpContextAccessor.HttpContext.SetPrincipalForRequest(owinCtx.Request.User);
return TimeSpan.FromMinutes(_globalSettings.TimeOutInMinutes).TotalSeconds;
}
@@ -103,8 +103,8 @@ namespace Umbraco.Web.Security
/// </summary>
public virtual void ClearCurrentLogin()
{
_httpContext.UmbracoLogout();
_httpContext.GetOwinContext().Authentication.SignOut(
_httpContextAccessor.HttpContext.UmbracoLogout();
_httpContextAccessor.HttpContext.GetOwinContext().Authentication.SignOut(
Core.Constants.Security.BackOfficeAuthenticationType,
Core.Constants.Security.BackOfficeExternalAuthenticationType);
}
@@ -114,7 +114,7 @@ namespace Umbraco.Web.Security
/// </summary>
public virtual void RenewLoginTimeout()
{
_httpContext.RenewUmbracoAuthTicket();
_httpContextAccessor.HttpContext.RenewUmbracoAuthTicket();
}
/// <summary>
@@ -154,7 +154,7 @@ namespace Umbraco.Web.Security
/// <returns></returns>
public virtual Attempt<int> GetUserId()
{
var identity = _httpContext.GetCurrentIdentity(false);
var identity = _httpContextAccessor.HttpContext.GetCurrentIdentity(false);
return identity == null ? Attempt.Fail<int>() : Attempt.Succeed(Convert.ToInt32(identity.Id));
}
@@ -164,7 +164,7 @@ namespace Umbraco.Web.Security
/// <returns></returns>
public virtual string GetSessionId()
{
var identity = _httpContext.GetCurrentIdentity(false);
var identity = _httpContextAccessor.HttpContext.GetCurrentIdentity(false);
return identity?.SessionId;
}
@@ -199,7 +199,7 @@ namespace Umbraco.Web.Security
var user = CurrentUser;
// Check for console access
if (user == null || (requiresApproval && user.IsApproved == false) || (user.IsLockedOut && RequestIsInUmbracoApplication(_httpContext, _globalSettings, _ioHelper)))
if (user == null || (requiresApproval && user.IsApproved == false) || (user.IsLockedOut && RequestIsInUmbracoApplication(_httpContextAccessor.HttpContext, _globalSettings, _ioHelper)))
{
if (throwExceptions) throw new ArgumentException("You have no privileges to the umbraco console. Please contact your administrator");
return ValidateRequestAttempt.FailedNoPrivileges;
@@ -221,7 +221,7 @@ namespace Umbraco.Web.Security
public ValidateRequestAttempt AuthorizeRequest(bool throwExceptions = false)
{
// check for secure connection
if (_globalSettings.UseHttps && _httpContext.Request.IsSecureConnection == false)
if (_globalSettings.UseHttps && _httpContextAccessor.HttpContext.Request.IsSecureConnection == false)
{
if (throwExceptions) throw new SecurityException("This installation requires a secure connection (via SSL). Please update the URL to include https://");
return ValidateRequestAttempt.FailedNoSsl;
@@ -262,7 +262,8 @@ namespace Umbraco.Web.Security
/// <returns></returns>
public bool IsAuthenticated()
{
return _httpContext.User != null && _httpContext.User.Identity.IsAuthenticated && _httpContext.GetCurrentIdentity(false) != null;
var httpContext = _httpContextAccessor.HttpContext;
return httpContext.User != null && httpContext.User.Identity.IsAuthenticated && httpContext.GetCurrentIdentity(false) != null;
}
}

View File

@@ -34,11 +34,12 @@ namespace Umbraco.Web
private readonly MediaUrlProviderCollection _mediaUrlProviders;
private readonly IUserService _userService;
private readonly IIOHelper _ioHelper;
private readonly IHttpContextAccessor _httpContextAccessor;
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoContextFactory"/> class.
/// </summary>
public UmbracoContextFactory(IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, IUmbracoSettingsSection umbracoSettings, IGlobalSettings globalSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IUserService userService, IIOHelper ioHelper)
public UmbracoContextFactory(IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, IUmbracoSettingsSection umbracoSettings, IGlobalSettings globalSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IUserService userService, IIOHelper ioHelper, IHttpContextAccessor httpContextAccessor)
{
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
_publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService));
@@ -51,6 +52,7 @@ namespace Umbraco.Web
_mediaUrlProviders = mediaUrlProviders ?? throw new ArgumentNullException(nameof(mediaUrlProviders));
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
_ioHelper = ioHelper;
_httpContextAccessor = httpContextAccessor;
}
private IUmbracoContext CreateUmbracoContext(HttpContextBase httpContext)
@@ -67,7 +69,7 @@ namespace Umbraco.Web
}
var webSecurity = new WebSecurity(httpContext, _userService, _globalSettings, _ioHelper);
var webSecurity = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _ioHelper);
return new UmbracoContext(httpContext, _publishedSnapshotService, webSecurity, _umbracoSettings, _urlProviders, _mediaUrlProviders, _globalSettings, _variationContextAccessor, _ioHelper);
}