* 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>
116 lines
4.7 KiB
C#
116 lines
4.7 KiB
C#
using System.IO;
|
|
using System.Reflection;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Serilog;
|
|
using Serilog.Extensions.Hosting;
|
|
using Umbraco.Cms.Core.Cache;
|
|
using Umbraco.Cms.Core.Composing;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Logging;
|
|
using Umbraco.Cms.Core.Logging.Serilog;
|
|
using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment;
|
|
|
|
namespace Umbraco.Extensions
|
|
{
|
|
public static partial class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Create and configure the logger
|
|
/// </summary>
|
|
public static IServiceCollection AddLogger(
|
|
this IServiceCollection services,
|
|
IHostingEnvironment hostingEnvironment,
|
|
ILoggingConfiguration loggingConfiguration,
|
|
IConfiguration configuration)
|
|
{
|
|
// Create a serilog logger
|
|
var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration, configuration);
|
|
|
|
// This is nessasary to pick up all the loggins to MS ILogger.
|
|
Log.Logger = logger.SerilogLog;
|
|
|
|
// Wire up all the bits that serilog needs. We need to use our own code since the Serilog ext methods don't cater to our needs since
|
|
// we don't want to use the global serilog `Log` object and we don't have our own ILogger implementation before the HostBuilder runs which
|
|
// is the only other option that these ext methods allow.
|
|
// I have created a PR to make this nicer https://github.com/serilog/serilog-extensions-hosting/pull/19 but we'll need to wait for that.
|
|
// Also see : https://github.com/serilog/serilog-extensions-hosting/blob/dev/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs
|
|
|
|
services.AddLogging(configure =>
|
|
{
|
|
configure.AddSerilog(logger.SerilogLog, false);
|
|
});
|
|
|
|
// This won't (and shouldn't) take ownership of the logger.
|
|
services.AddSingleton(logger.SerilogLog);
|
|
|
|
// Registered to provide two services...
|
|
var diagnosticContext = new DiagnosticContext(logger.SerilogLog);
|
|
|
|
// Consumed by e.g. middleware
|
|
services.AddSingleton(diagnosticContext);
|
|
|
|
// Consumed by user code
|
|
services.AddSingleton<IDiagnosticContext>(diagnosticContext);
|
|
services.AddSingleton(loggingConfiguration);
|
|
|
|
return services;
|
|
}
|
|
|
|
internal static ITypeFinder AddTypeFinder(
|
|
this IServiceCollection services,
|
|
ILoggerFactory loggerFactory,
|
|
IWebHostEnvironment webHostEnvironment,
|
|
Assembly entryAssembly,
|
|
IConfiguration config,
|
|
IProfilingLogger profilingLogger)
|
|
{
|
|
|
|
var typeFinderSettings = config.GetSection(Cms.Core.Constants.Configuration.ConfigTypeFinder).Get<TypeFinderSettings>() ?? new TypeFinderSettings();
|
|
|
|
var runtimeHashPaths = new RuntimeHashPaths().AddFolder(new DirectoryInfo(Path.Combine(webHostEnvironment.ContentRootPath, "bin")));
|
|
var runtimeHash = new RuntimeHash(profilingLogger, runtimeHashPaths);
|
|
|
|
var typeFinder = new TypeFinder(
|
|
loggerFactory.CreateLogger<TypeFinder>(),
|
|
new DefaultUmbracoAssemblyProvider(entryAssembly, loggerFactory),
|
|
runtimeHash,
|
|
new TypeFinderConfig(Options.Create(typeFinderSettings))
|
|
);
|
|
|
|
services.AddUnique<ITypeFinder>(typeFinder);
|
|
|
|
return typeFinder;
|
|
}
|
|
|
|
public static TypeLoader AddTypeLoader(
|
|
this IServiceCollection services,
|
|
Assembly entryAssembly,
|
|
IWebHostEnvironment webHostEnvironment,
|
|
IHostingEnvironment hostingEnvironment,
|
|
ILoggerFactory loggerFactory,
|
|
AppCaches appCaches,
|
|
IConfiguration configuration,
|
|
IProfiler profiler)
|
|
{
|
|
var profilingLogger = new ProfilingLogger(loggerFactory.CreateLogger<ProfilingLogger>(), profiler);
|
|
var typeFinder = services.AddTypeFinder(loggerFactory, webHostEnvironment, entryAssembly, configuration, profilingLogger);
|
|
|
|
var typeLoader = new TypeLoader(
|
|
typeFinder,
|
|
appCaches.RuntimeCache,
|
|
new DirectoryInfo(hostingEnvironment.LocalTempPath),
|
|
loggerFactory.CreateLogger<TypeLoader>(),
|
|
profilingLogger
|
|
);
|
|
|
|
services.AddUnique<TypeLoader>(typeLoader);
|
|
|
|
return typeLoader;
|
|
}
|
|
}
|
|
}
|