* Doesn't make much sense to have Concrete on IRegister, only on IFactory * Handle FilesTreeController requires IFileSystem of type PhysicalFileSystem * Handle registration of default MediaFileSystem without using RegisterUniqueFor * Remove RegisterFor / RegisterUniqueFor from IRegister * Switch over from LightInject to wrappers around MSDI * Made mapper dependencies more explicit * Remove registration for AngularJsonMediaTypeFormatter It's dependencies aren't registered so container validation fails * Resolve lifetime issue for EnsureValidSessionId by service locating else resolve scoped in singleton * Make registration more explicit for backoffice UserManager * Make install step registrations more explicit * Disable service provider validation so site can launch Maybe this is a problem maybe not, we build about 8000 service providers so maybe everything is fine later... * Further cleanup of IFactory interface * Further cleanup of IRegister interface * Revert "Make registration more explicit for backoffice UserManager" This reverts commit 7215fe836103c597cd0873c66737a79b91ed4c49. * Resolve issue where NewInstallStep would fail to reset password for "SuperUser" Before MSDI, somehow BackOfficeIdentityOptions would be configured with token provider map from IdentityBuilder.AddDefaultTokenProviders. After switchover those config actions are lost. Subclass IdentityBuilder to ensure BackOfficeIdentityOptions doesn't miss config setup upstream. * Initialize current. * Add todo to turn container validation back on. * Migrated ScopeFileSystemsTests to integration tests Signed-off-by: Bjarke Berg <mail@bergmania.dk> * Resolve issue where MediaFileSystem was skipping ShadowFileSystem * Attempt to fix ScopeFileSystemsTests on azure devops Signed-off-by: Bjarke Berg <mail@bergmania.dk> * Be interesting to know what the actual full path is in pipeline. * Clarify intent of CreateMediaTest Doesn't help resolve weird UnauthorizedAccessException but it cuts so much cognitive overhead for the future. * Use ILoggerfactory rather than mock for the manually constructed file PhysicalFileSystem * Maybe resolve failing test on azure pipeline. Co-authored-by: Bjarke Berg <mail@bergmania.dk>
104 lines
4.9 KiB
C#
104 lines
4.9 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.Extensions.Options;
|
|
using Umbraco.Core;
|
|
using Umbraco.Core.BackOffice;
|
|
using Umbraco.Core.Configuration.Models;
|
|
using Umbraco.Core.Security;
|
|
using Umbraco.Core.Serialization;
|
|
using Umbraco.Infrastructure.BackOffice;
|
|
using Umbraco.Net;
|
|
using Umbraco.Web.BackOffice.Filters;
|
|
using Umbraco.Web.BackOffice.Security;
|
|
using Umbraco.Web.Common.AspNetCore;
|
|
using Umbraco.Web.Common.Security;
|
|
|
|
namespace Umbraco.Extensions
|
|
{
|
|
|
|
public static class BackOfficeServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds the services required for running the Umbraco back office
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
public static void AddUmbracoBackOffice(this IServiceCollection services)
|
|
{
|
|
services.AddAntiforgery();
|
|
|
|
// TODO: We had this check in v8 where we don't enable these unless we can run...
|
|
//if (runtimeState.Level != RuntimeLevel.Upgrade && runtimeState.Level != RuntimeLevel.Run) return app;
|
|
|
|
services.AddSingleton<IFilterProvider, OverrideAuthorizationFilterProvider>();
|
|
services
|
|
.AddAuthentication(Constants.Security.BackOfficeAuthenticationType)
|
|
.AddCookie(Constants.Security.BackOfficeAuthenticationType);
|
|
// TODO: Need to add more cookie options, see https://github.com/dotnet/aspnetcore/blob/3.0/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs#L45
|
|
|
|
services.ConfigureOptions<ConfigureBackOfficeCookieOptions>();
|
|
}
|
|
|
|
public static void AddUmbracoPreview(this IServiceCollection services)
|
|
{
|
|
services.AddSignalR();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds the services required for using Umbraco back office Identity
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
public static void AddUmbracoBackOfficeIdentity(this IServiceCollection services)
|
|
{
|
|
services.AddDataProtection();
|
|
|
|
services.TryAddScoped<IIpResolver, AspNetCoreIpResolver>();
|
|
|
|
services.BuildUmbracoBackOfficeIdentity()
|
|
.AddDefaultTokenProviders()
|
|
.AddUserStore<BackOfficeUserStore>()
|
|
.AddUserManager<IBackOfficeUserManager, BackOfficeUserManager>()
|
|
.AddSignInManager<BackOfficeSignInManager>()
|
|
.AddClaimsPrincipalFactory<BackOfficeClaimsPrincipalFactory<BackOfficeIdentityUser>>();
|
|
|
|
// Configure the options specifically for the UmbracoBackOfficeIdentityOptions instance
|
|
services.ConfigureOptions<ConfigureBackOfficeIdentityOptions>();
|
|
services.ConfigureOptions<ConfigureBackOfficeSecurityStampValidatorOptions>();
|
|
}
|
|
|
|
private static BackOfficeIdentityBuilder BuildUmbracoBackOfficeIdentity(this IServiceCollection services)
|
|
{
|
|
// Borrowed from https://github.com/dotnet/aspnetcore/blob/master/src/Identity/Extensions.Core/src/IdentityServiceCollectionExtensions.cs#L33
|
|
// The reason we need our own is because the Identity system doesn't cater easily for multiple identity systems and particularly being
|
|
// able to configure IdentityOptions to a specific provider since there is no named options. So we have strongly typed options
|
|
// and strongly typed ILookupNormalizer and IdentityErrorDescriber since those are 'global' and we need to be unintrusive.
|
|
|
|
// TODO: Could move all of this to BackOfficeComposer?
|
|
|
|
// Services used by identity
|
|
services.TryAddScoped<IUserValidator<BackOfficeIdentityUser>, UserValidator<BackOfficeIdentityUser>>();
|
|
services.TryAddScoped<IPasswordValidator<BackOfficeIdentityUser>, PasswordValidator<BackOfficeIdentityUser>>();
|
|
services.TryAddScoped<IPasswordHasher<BackOfficeIdentityUser>>(
|
|
services => new BackOfficePasswordHasher(
|
|
new LegacyPasswordSecurity(),
|
|
services.GetRequiredService<IJsonSerializer>()));
|
|
services.TryAddScoped<IUserConfirmation<BackOfficeIdentityUser>, DefaultUserConfirmation<BackOfficeIdentityUser>>();
|
|
services.TryAddScoped<IUserClaimsPrincipalFactory<BackOfficeIdentityUser>, UserClaimsPrincipalFactory<BackOfficeIdentityUser>>();
|
|
services.TryAddScoped<UserManager<BackOfficeIdentityUser>>();
|
|
|
|
// CUSTOM:
|
|
services.TryAddScoped<BackOfficeLookupNormalizer>();
|
|
services.TryAddScoped<BackOfficeIdentityErrorDescriber>();
|
|
|
|
return new BackOfficeIdentityBuilder(services);
|
|
}
|
|
}
|
|
}
|