Implements Public Access in netcore (#10137)
* Getting new netcore PublicAccessChecker in place * Adds full test coverage for PublicAccessChecker * remove PublicAccessComposer * adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller * Implements the required methods on IMemberManager, removes old migrated code * Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops * adds note * adds note * Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling. * Changes name to IUmbracoEndpointBuilder * adds note * Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect * fixing build * Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware. * adds note * removes unused filter, fixes build * fixes WebPath and tests * Looks up entities in one query * remove usings * Fix test, remove stylesheet * Set status code before we write to response to avoid error * Ensures that users and members are validated when logging in. Shares more code between users and members. * Fixes RepositoryCacheKeys to ensure the keys are normalized * oops didn't mean to commit this * Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy * bah, far out this keeps getting recommitted. sorry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -5,14 +5,13 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Serilog.Context;
|
||||
using SixLabors.ImageSharp.Web.DependencyInjection;
|
||||
using Smidge;
|
||||
using Smidge.Nuglify;
|
||||
using StackExchange.Profiling;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Hosting;
|
||||
using Umbraco.Cms.Core.Logging.Serilog.Enrichers;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Web.Common.ApplicationBuilder;
|
||||
using Umbraco.Cms.Web.Common.Middleware;
|
||||
using Umbraco.Cms.Web.Common.Plugins;
|
||||
|
||||
@@ -26,8 +25,12 @@ namespace Umbraco.Extensions
|
||||
/// <summary>
|
||||
/// Configures and use services required for using Umbraco
|
||||
/// </summary>
|
||||
public static IApplicationBuilder UseUmbraco(this IApplicationBuilder app)
|
||||
public static IUmbracoApplicationBuilder UseUmbraco(this IApplicationBuilder app)
|
||||
{
|
||||
IOptions<UmbracoPipelineOptions> startupOptions = app.ApplicationServices.GetRequiredService<IOptions<UmbracoPipelineOptions>>();
|
||||
|
||||
app.RunPrePipeline(startupOptions.Value);
|
||||
|
||||
// TODO: Should we do some checks like this to verify that the corresponding "Add" methods have been called for the
|
||||
// corresponding "Use" methods?
|
||||
// https://github.com/dotnet/aspnetcore/blob/b795ac3546eb3e2f47a01a64feb3020794ca33bb/src/Mvc/Mvc.Core/src/Builder/MvcApplicationBuilderExtensions.cs#L132
|
||||
@@ -66,22 +69,46 @@ namespace Umbraco.Extensions
|
||||
// Must be called after UseRouting and before UseEndpoints
|
||||
app.UseSession();
|
||||
|
||||
// Must come after the above!
|
||||
app.UseUmbracoInstaller();
|
||||
// DO NOT PUT ANY UseEndpoints declarations here!! Those must all come very last in the pipeline,
|
||||
// endpoints are terminating middleware. All of our endpoints are declared in ext of IUmbracoApplicationBuilder
|
||||
|
||||
return app;
|
||||
app.RunPostPipeline(startupOptions.Value);
|
||||
app.RunPreEndpointsPipeline(startupOptions.Value);
|
||||
|
||||
return ActivatorUtilities.CreateInstance<UmbracoApplicationBuilder>(
|
||||
app.ApplicationServices,
|
||||
new object[] { app });
|
||||
}
|
||||
|
||||
private static void RunPrePipeline(this IApplicationBuilder app, UmbracoPipelineOptions startupOptions)
|
||||
{
|
||||
foreach (IUmbracoPipelineFilter filter in startupOptions.PipelineFilters)
|
||||
{
|
||||
filter.OnPrePipeline(app);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunPostPipeline(this IApplicationBuilder app, UmbracoPipelineOptions startupOptions)
|
||||
{
|
||||
foreach (IUmbracoPipelineFilter filter in startupOptions.PipelineFilters)
|
||||
{
|
||||
filter.OnPostPipeline(app);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunPreEndpointsPipeline(this IApplicationBuilder app, UmbracoPipelineOptions startupOptions)
|
||||
{
|
||||
foreach (IUmbracoPipelineFilter filter in startupOptions.PipelineFilters)
|
||||
{
|
||||
filter.OnEndpoints(app);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Umbraco <see cref="IRuntimeState"/> is greater than <see cref="RuntimeLevel.BootFailed"/>
|
||||
/// </summary>
|
||||
public static bool UmbracoCanBoot(this IApplicationBuilder app)
|
||||
{
|
||||
var state = app.ApplicationServices.GetRequiredService<IRuntimeState>();
|
||||
|
||||
// can't continue if boot failed
|
||||
return state.Level > RuntimeLevel.BootFailed;
|
||||
}
|
||||
=> app.ApplicationServices.GetRequiredService<IRuntimeState>().UmbracoCanBoot();
|
||||
|
||||
/// <summary>
|
||||
/// Enables core Umbraco functionality
|
||||
@@ -151,27 +178,6 @@ namespace Umbraco.Extensions
|
||||
return app;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables runtime minification for Umbraco
|
||||
/// </summary>
|
||||
public static IApplicationBuilder UseUmbracoRuntimeMinification(this IApplicationBuilder app)
|
||||
{
|
||||
if (app == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
|
||||
if (!app.UmbracoCanBoot())
|
||||
{
|
||||
return app;
|
||||
}
|
||||
|
||||
app.UseSmidge();
|
||||
app.UseSmidgeNuglify();
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseUmbracoPlugins(this IApplicationBuilder app)
|
||||
{
|
||||
var hostingEnvironment = app.ApplicationServices.GetRequiredService<IHostingEnvironment>();
|
||||
|
||||
Reference in New Issue
Block a user