Removed some of the old legacy configs
Signed-off-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
using System.Configuration;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Configuration.Legacy
|
||||
{
|
||||
public class ActiveDirectorySettings : IActiveDirectorySettings
|
||||
{
|
||||
public ActiveDirectorySettings()
|
||||
{
|
||||
ActiveDirectoryDomain = ConfigurationManager.AppSettings["ActiveDirectoryDomain"];
|
||||
}
|
||||
|
||||
public string ActiveDirectoryDomain { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
public class ConnectionStrings : IConnectionStrings
|
||||
{
|
||||
public ConfigConnectionString this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
var settings = ConfigurationManager.ConnectionStrings[key];
|
||||
if (settings == null) return null;
|
||||
return new ConfigConnectionString(settings.ConnectionString, settings.ProviderName, settings.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Configuration.Models
|
||||
{
|
||||
internal class ActiveDirectorySettings : IActiveDirectorySettings
|
||||
{
|
||||
private const string Prefix = Constants.Configuration.ConfigPrefix + "ActiveDirectory:";
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public ActiveDirectorySettings(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public string ActiveDirectoryDomain => _configuration.GetValue<string>(Prefix+"Domain");
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Configuration.Models
|
||||
{
|
||||
public class ConnectionStrings : IConnectionStrings
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public ConnectionStrings(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public ConfigConnectionString this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
var connectionString = _configuration.GetConnectionString(key);
|
||||
var provider = ParseProvider(connectionString);
|
||||
return new ConfigConnectionString(connectionString, provider, key);
|
||||
}
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private string ParseProvider(string connectionString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(connectionString))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var builder = new DbConnectionStringBuilder();
|
||||
|
||||
builder.ConnectionString = connectionString;
|
||||
|
||||
if (builder.TryGetValue("Data Source", out var ds) && ds is string dataSource)
|
||||
{
|
||||
if (dataSource.EndsWith(".sdf"))
|
||||
{
|
||||
return Constants.DbProviderNames.SqlCe;
|
||||
}
|
||||
}
|
||||
|
||||
if (builder.TryGetValue("Server", out var s) && s is string server && !string.IsNullOrEmpty(server))
|
||||
{
|
||||
if (builder.TryGetValue("Database", out var db) && db is string database && !string.IsNullOrEmpty(database))
|
||||
{
|
||||
return Constants.DbProviderNames.SqlServer;
|
||||
}
|
||||
|
||||
if (builder.TryGetValue("AttachDbFileName", out var a) && a is string attachDbFileName && !string.IsNullOrEmpty(attachDbFileName))
|
||||
{
|
||||
return Constants.DbProviderNames.SqlServer;
|
||||
}
|
||||
|
||||
if (builder.TryGetValue("Initial Catalog", out var i) && i is string initialCatalog && !string.IsNullOrEmpty(initialCatalog))
|
||||
{
|
||||
return Constants.DbProviderNames.SqlServer;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException("Cannot determine provider name from connection string", nameof(connectionString));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
public interface IActiveDirectorySettings
|
||||
{
|
||||
string ActiveDirectoryDomain { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
public interface IConnectionStrings
|
||||
{
|
||||
ConfigConnectionString this[string key]
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,14 +50,6 @@ namespace Umbraco.Infrastructure.Configuration
|
||||
};
|
||||
}
|
||||
|
||||
public static ConnectionStrings ConvertConnectionStrings(IConnectionStrings connectionStrings)
|
||||
{
|
||||
return new ConnectionStrings
|
||||
{
|
||||
UmbracoConnectionString = connectionStrings[Constants.System.UmbracoConnectionName].ConnectionString
|
||||
};
|
||||
}
|
||||
|
||||
public static UserPasswordConfigurationSettings ConvertUserPasswordConfiguration(IUserPasswordConfiguration passwordConfiguration)
|
||||
{
|
||||
return new UserPasswordConfigurationSettings
|
||||
|
||||
@@ -49,13 +49,6 @@ namespace Umbraco.Infrastructure.Configuration
|
||||
};
|
||||
}
|
||||
|
||||
public static IConnectionStrings ConvertConnectionStrings(ConnectionStrings connectionStrings)
|
||||
{
|
||||
var result = new TestConnectionStrings();
|
||||
result.AddEntry(Constants.System.UmbracoConnectionName, connectionStrings.UmbracoConnectionString);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IUserPasswordConfiguration ConvertUserPasswordConfiguration(UserPasswordConfigurationSettings passwordConfiguration)
|
||||
{
|
||||
return new TestUserPasswordConfiguration
|
||||
@@ -133,18 +126,6 @@ namespace Umbraco.Infrastructure.Configuration
|
||||
public string Password { get; set; }
|
||||
}
|
||||
|
||||
private class TestConnectionStrings : IConnectionStrings
|
||||
{
|
||||
private IDictionary<string, ConfigConnectionString> _dictionary = new Dictionary<string, ConfigConnectionString>();
|
||||
|
||||
public ConfigConnectionString this[string key] => _dictionary[key];
|
||||
|
||||
public void AddEntry(string key, string connectionString)
|
||||
{
|
||||
_dictionary.Add(key, new ConfigConnectionString(connectionString, string.Empty, key));
|
||||
}
|
||||
}
|
||||
|
||||
private class TestUserPasswordConfiguration : IUserPasswordConfiguration
|
||||
{
|
||||
public int RequiredLength { get; set; }
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Configuration;
|
||||
using Umbraco.Configuration.Legacy;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
@@ -20,7 +22,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose
|
||||
{
|
||||
internal class ModelsBuilderComponent : IComponent
|
||||
{
|
||||
private readonly IModelsBuilderConfig _config;
|
||||
private readonly ModelsBuilderConfig _config;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private readonly LiveModelsProvider _liveModelsProvider;
|
||||
private readonly OutOfDateModelsStatus _outOfDateModels;
|
||||
@@ -28,11 +30,11 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose
|
||||
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
|
||||
private readonly IUmbracoRequestLifetime _umbracoRequestLifetime;
|
||||
|
||||
public ModelsBuilderComponent(IModelsBuilderConfig config, IShortStringHelper shortStringHelper,
|
||||
public ModelsBuilderComponent(IOptions<ModelsBuilderConfig> config, IShortStringHelper shortStringHelper,
|
||||
LiveModelsProvider liveModelsProvider, OutOfDateModelsStatus outOfDateModels, LinkGenerator linkGenerator,
|
||||
IUmbracoRequestLifetime umbracoRequestLifetime, IUmbracoApplicationLifetime umbracoApplicationLifetime)
|
||||
{
|
||||
_config = config;
|
||||
_config = config.Value;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
_liveModelsProvider = liveModelsProvider;
|
||||
_outOfDateModels = outOfDateModels;
|
||||
@@ -76,7 +78,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose
|
||||
private void InstallServerVars()
|
||||
{
|
||||
// register our url - for the backoffice api
|
||||
ServerVariablesParser.Parsing += ServerVariablesParser_Parsing;
|
||||
ServerVariablesParser.Parsing += ServerVariablesParser_Parsing;
|
||||
}
|
||||
|
||||
private void ServerVariablesParser_Parsing(object sender, Dictionary<string, object> serverVars)
|
||||
|
||||
@@ -15,13 +15,6 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose
|
||||
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
|
||||
public sealed class ModelsBuilderComposer : ICoreComposer
|
||||
{
|
||||
private readonly ModelsBuilderConfig _config;
|
||||
|
||||
public ModelsBuilderComposer(IOptions<ModelsBuilderConfig> config)
|
||||
{
|
||||
_config = config.Value;
|
||||
}
|
||||
|
||||
public void Compose(Composition composition)
|
||||
{
|
||||
composition.Components().Append<ModelsBuilderComponent>();
|
||||
@@ -31,44 +24,43 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose
|
||||
composition.RegisterUnique<OutOfDateModelsStatus>();
|
||||
composition.RegisterUnique<ModelsGenerationError>();
|
||||
|
||||
if (_config.ModelsMode == ModelsMode.PureLive)
|
||||
ComposeForLiveModels(composition);
|
||||
else if (_config.EnableFactory)
|
||||
ComposeForDefaultModelsFactory(composition);
|
||||
}
|
||||
|
||||
private void ComposeForDefaultModelsFactory(Composition composition)
|
||||
{
|
||||
composition.RegisterUnique<IPublishedModelFactory>(factory =>
|
||||
{
|
||||
var typeLoader = factory.GetInstance<TypeLoader>();
|
||||
var publishedValueFallback = factory.GetInstance<IPublishedValueFallback>();
|
||||
var types = typeLoader
|
||||
.GetTypes<PublishedElementModel>() // element models
|
||||
.Concat(typeLoader.GetTypes<PublishedContentModel>()); // content models
|
||||
return new PublishedModelFactory(types, publishedValueFallback);
|
||||
var config = factory.GetInstance<IOptions<ModelsBuilderConfig>>().Value;
|
||||
if (config.ModelsMode == ModelsMode.PureLive)
|
||||
{
|
||||
composition.RegisterUnique<IPublishedModelFactory, PureLiveModelFactory>();
|
||||
|
||||
// the following would add @using statement in every view so user's don't
|
||||
// have to do it - however, then noone understands where the @using statement
|
||||
// comes from, and it cannot be avoided / removed --- DISABLED
|
||||
//
|
||||
/*
|
||||
// no need for @using in views
|
||||
// note:
|
||||
// we are NOT using the in-code attribute here, config is required
|
||||
// because that would require parsing the code... and what if it changes?
|
||||
// we can AddGlobalImport not sure we can remove one anyways
|
||||
var modelsNamespace = Configuration.Config.ModelsNamespace;
|
||||
if (string.IsNullOrWhiteSpace(modelsNamespace))
|
||||
modelsNamespace = Configuration.Config.DefaultModelsNamespace;
|
||||
System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(modelsNamespace);
|
||||
*/
|
||||
}
|
||||
else if (config.EnableFactory)
|
||||
{
|
||||
var typeLoader = factory.GetInstance<TypeLoader>();
|
||||
var publishedValueFallback = factory.GetInstance<IPublishedValueFallback>();
|
||||
var types = typeLoader
|
||||
.GetTypes<PublishedElementModel>() // element models
|
||||
.Concat(typeLoader.GetTypes<PublishedContentModel>()); // content models
|
||||
return new PublishedModelFactory(types, publishedValueFallback);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void ComposeForLiveModels(Composition composition)
|
||||
{
|
||||
composition.RegisterUnique<IPublishedModelFactory, PureLiveModelFactory>();
|
||||
|
||||
// the following would add @using statement in every view so user's don't
|
||||
// have to do it - however, then noone understands where the @using statement
|
||||
// comes from, and it cannot be avoided / removed --- DISABLED
|
||||
//
|
||||
/*
|
||||
// no need for @using in views
|
||||
// note:
|
||||
// we are NOT using the in-code attribute here, config is required
|
||||
// because that would require parsing the code... and what if it changes?
|
||||
// we can AddGlobalImport not sure we can remove one anyways
|
||||
var modelsNamespace = Configuration.Config.ModelsNamespace;
|
||||
if (string.IsNullOrWhiteSpace(modelsNamespace))
|
||||
modelsNamespace = Configuration.Config.DefaultModelsNamespace;
|
||||
System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(modelsNamespace);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
@@ -11,9 +12,9 @@ namespace Umbraco.ModelsBuilder.Embedded
|
||||
private readonly ModelsBuilderConfig _config;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public OutOfDateModelsStatus(ModelsBuilderConfig config, IHostingEnvironment hostingEnvironment)
|
||||
public OutOfDateModelsStatus(IOptions<ModelsBuilderConfig> config, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_config = config;
|
||||
_config = config.Value;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,8 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
Services = host.Services;
|
||||
var app = new ApplicationBuilder(host.Services);
|
||||
Configure(app);
|
||||
|
||||
OnFixtureTearDown(() => host.Dispose());
|
||||
}
|
||||
|
||||
#region Generic Host Builder and Runtime
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoMoq;
|
||||
using AutoFixture.Kernel;
|
||||
using AutoFixture.NUnit3;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.BackOffice;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Web.BackOffice.Controllers;
|
||||
using Umbraco.Web.Common.Install;
|
||||
@@ -42,9 +46,9 @@ namespace Umbraco.Tests.UnitTests.AutoFixture
|
||||
.Customize(new ConstructorCustomization(typeof(InstallController), new GreedyConstructorQuery()))
|
||||
.Customize(new ConstructorCustomization(typeof(PreviewController), new GreedyConstructorQuery()))
|
||||
.Customize(new ConstructorCustomization(typeof(BackOfficeController), new GreedyConstructorQuery()))
|
||||
.Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery()))
|
||||
.Customize(new AutoMoqCustomization());
|
||||
.Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery()));
|
||||
|
||||
fixture.Customize(new AutoMoqCustomization());
|
||||
// When requesting an IUserStore ensure we actually uses a IUserLockoutStore
|
||||
fixture.Customize<IUserStore<BackOfficeIdentityUser>>(cc => cc.FromFactory(() => Mock.Of<IUserLockoutStore<BackOfficeIdentityUser>>()));
|
||||
|
||||
@@ -56,9 +60,9 @@ namespace Umbraco.Tests.UnitTests.AutoFixture
|
||||
u => u.FromFactory(
|
||||
() => new UmbracoVersion()));
|
||||
|
||||
var connectionStrings = Mock.Of<IConnectionStrings>();
|
||||
Mock.Get(connectionStrings).Setup(x => x[Constants.System.UmbracoConnectionName]).Returns((ConfigConnectionString)new ConfigConnectionString(string.Empty, string.Empty, string.Empty));
|
||||
fixture.Customize<IConnectionStrings>(x => x.FromFactory(() => connectionStrings ));
|
||||
var connectionStrings = new ConnectionStrings();
|
||||
fixture.Customize<ConnectionStrings>(x => x.FromFactory(() => connectionStrings ));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Configuration.Models;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Configuration.Models
|
||||
{
|
||||
@@ -16,17 +17,11 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Configuration.Models
|
||||
public string ParseProviderName(string connectionString)
|
||||
{
|
||||
var key = Constants.System.UmbracoConnectionName;
|
||||
var configuration = new Mock<IConfiguration>();
|
||||
|
||||
|
||||
//This is the underlying method that is called by Configuration.GetConnectionString(string)
|
||||
if (connectionString != null)
|
||||
var connectionStrings = new ConnectionStrings
|
||||
{
|
||||
configuration.Setup(x => x.GetSection("ConnectionStrings")[key]).Returns(connectionString);
|
||||
}
|
||||
|
||||
|
||||
var connectionStrings = new ConnectionStrings(configuration.Object);
|
||||
UmbracoConnectionString = connectionString
|
||||
};
|
||||
|
||||
var actual = connectionStrings[key];
|
||||
|
||||
|
||||
@@ -5,9 +5,11 @@ using System.Threading.Tasks;
|
||||
using AutoFixture.NUnit3;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Tests.UnitTests.AutoFixture;
|
||||
using Umbraco.Web.BackOffice.Controllers;
|
||||
@@ -69,12 +71,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common
|
||||
[Test]
|
||||
[AutoMoqData]
|
||||
public async Task BackOfficeDefaultExists(
|
||||
[Frozen] IGlobalSettings globalSettings,
|
||||
[Frozen] IOptions<GlobalSettings> globalSettings,
|
||||
[Frozen] IHostingEnvironment hostingEnvironment,
|
||||
[Frozen] ITempDataDictionary tempDataDictionary,
|
||||
BackOfficeController sut)
|
||||
{
|
||||
Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/");
|
||||
globalSettings.Value.UmbracoPath = "/";
|
||||
Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute("/")).Returns("http://localhost/");
|
||||
Mock.Get(hostingEnvironment).SetupGet(x => x.ApplicationVirtualPath).Returns("/");
|
||||
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
using System;
|
||||
using System.DirectoryServices.AccountManagement;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Core.BackOffice;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
|
||||
namespace Umbraco.Web.Security
|
||||
{
|
||||
// TODO: This relies on an assembly that is not .NET Standard (at least not at the time of implementation) :(
|
||||
public class ActiveDirectoryBackOfficeUserPasswordChecker : IBackOfficeUserPasswordChecker
|
||||
{
|
||||
private readonly IActiveDirectorySettings _settings;
|
||||
private readonly IOptions<ActiveDirectorySettings> _activeDirectorySettings;
|
||||
|
||||
public ActiveDirectoryBackOfficeUserPasswordChecker(IActiveDirectorySettings settings)
|
||||
public ActiveDirectoryBackOfficeUserPasswordChecker(IOptions<ActiveDirectorySettings> activeDirectorySettings)
|
||||
{
|
||||
_settings = settings;
|
||||
_activeDirectorySettings = activeDirectorySettings;
|
||||
}
|
||||
|
||||
public virtual string ActiveDirectoryDomain => _settings.ActiveDirectoryDomain;
|
||||
public virtual string ActiveDirectoryDomain => _activeDirectorySettings.Value.Domain;
|
||||
|
||||
public Task<BackOfficeUserPasswordCheckerResult> CheckPasswordAsync(BackOfficeIdentityUser user, string password)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user