#16831: Replacing usage of IsFullyTrusted.

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2010-11-22 14:01:35 -08:00
parent 7c53023eb1
commit e491dd92f4
6 changed files with 48 additions and 60 deletions

View File

@@ -1,35 +1,15 @@
using System;
using System.Linq;
using System.Reflection;
using System.Web.Hosting;
using Orchard.Environment;
using Orchard.Localization;
namespace Orchard.Commands {
internal class CommandHostEnvironment : IHostEnvironment {
internal class CommandHostEnvironment : HostEnvironment {
public CommandHostEnvironment() {
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public bool IsFullTrust {
get { return AppDomain.CurrentDomain.IsFullyTrusted; }
}
public string MapPath(string virtualPath) {
return HostingEnvironment.MapPath(virtualPath);
}
public bool IsAssemblyLoaded(string name) {
return AppDomain.CurrentDomain.GetAssemblies().Any(assembly => new AssemblyName(assembly.FullName).Name == name);
}
public void RestartAppDomain() {
ResetSiteCompilation();
}
public void ResetSiteCompilation() {
public override void ResetSiteCompilation() {
throw new OrchardCommandHostRetryException(T("A change of configuration requires the session to be restarted."));
}
}

View File

@@ -5,6 +5,7 @@ using NHibernate;
using NHibernate.Cfg;
using Orchard.Data;
using Orchard.Data.Providers;
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Environment.ShellBuilders.Models;
using Orchard.FileSystems.AppData;
@@ -21,6 +22,7 @@ namespace Orchard.Data {
public class SessionFactoryHolder : ISessionFactoryHolder {
private readonly ShellSettings _shellSettings;
private readonly ShellBlueprint _shellBlueprint;
private readonly IHostEnvironment _hostEnvironment;
private readonly IDataServicesProviderFactory _dataServicesProviderFactory;
private readonly IAppDataFolder _appDataFolder;
private readonly ISessionConfigurationCache _sessionConfigurationCache;
@@ -33,12 +35,14 @@ namespace Orchard.Data {
ShellBlueprint shellBlueprint,
IDataServicesProviderFactory dataServicesProviderFactory,
IAppDataFolder appDataFolder,
ISessionConfigurationCache sessionConfigurationCache) {
ISessionConfigurationCache sessionConfigurationCache,
IHostEnvironment hostEnvironment) {
_shellSettings = shellSettings;
_shellBlueprint = shellBlueprint;
_dataServicesProviderFactory = dataServicesProviderFactory;
_appDataFolder = appDataFolder;
_sessionConfigurationCache = sessionConfigurationCache;
_hostEnvironment = hostEnvironment;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
@@ -68,7 +72,7 @@ namespace Orchard.Data {
private ISessionFactory BuildSessionFactory() {
Logger.Debug("Building session factory");
if (!(AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted))
if (!_hostEnvironment.IsFullTrust)
NHibernate.Cfg.Environment.UseReflectionOptimizer = false;
Configuration config = GetConfiguration();

View File

@@ -1,16 +1,12 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.IO;
using System.Web;
using System.Web.Hosting;
using Orchard.Mvc;
using Orchard.Services;
using Orchard.Utility.Extensions;
namespace Orchard.Environment
{
public class DefaultHostEnvironment : IHostEnvironment
public class DefaultHostEnvironment : HostEnvironment
{
private readonly IClock _clock;
private readonly IHttpContextAccessor _httpContextAccessor;
@@ -20,27 +16,7 @@ namespace Orchard.Environment
_httpContextAccessor = httpContextAccessor;
}
public bool IsFullTrust
{
get { return AppDomain.CurrentDomain.IsFullyTrusted; }
}
public string MapPath(string virtualPath)
{
return HostingEnvironment.MapPath(virtualPath);
}
public bool IsAssemblyLoaded(string name)
{
return AppDomain.CurrentDomain.GetAssemblies().Any(assembly => new AssemblyName(assembly.FullName).Name == name);
}
public void RestartAppDomain()
{
ResetSiteCompilation();
}
public void ResetSiteCompilation()
public override void ResetSiteCompilation()
{
// Touch web.config
File.SetLastWriteTimeUtc(MapPath("~/web.config"), _clock.UtcNow);

View File

@@ -0,0 +1,26 @@
using System;
using System.Linq;
using System.Reflection;
using System.Web.Hosting;
namespace Orchard.Environment {
public abstract class HostEnvironment : IHostEnvironment {
public bool IsFullTrust {
get { return AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted; }
}
public string MapPath(string virtualPath) {
return HostingEnvironment.MapPath(virtualPath);
}
public bool IsAssemblyLoaded(string name) {
return AppDomain.CurrentDomain.GetAssemblies().Any(assembly => new AssemblyName(assembly.FullName).Name == name);
}
public void RestartAppDomain() {
ResetSiteCompilation();
}
public abstract void ResetSiteCompilation();
}
}

View File

@@ -2,11 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using Autofac;
using Autofac.Core;
using Castle.Core.Logging;
using Orchard.Environment;
using Module = Autofac.Module;
namespace Orchard.Logging {
@@ -16,13 +15,15 @@ namespace Orchard.Logging {
// by default, use Orchard's logger that delegates to Castle's logger factory
moduleBuilder.RegisterType<CastleLoggerFactory>().As<ILoggerFactory>().InstancePerLifetimeScope();
// Register logger type
if (AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted) {
moduleBuilder.RegisterType<TraceLoggerFactory>().As<Castle.Core.Logging.ILoggerFactory>().InstancePerLifetimeScope();
} else {
// if security model does not allow it, fall back to null logger factory
moduleBuilder.RegisterType<NullLogFactory>().As<Castle.Core.Logging.ILoggerFactory>().InstancePerLifetimeScope();
}
moduleBuilder.Register<Castle.Core.Logging.ILoggerFactory>(componentContext => {
IHostEnvironment host = componentContext.Resolve<IHostEnvironment>();
if (host.IsFullTrust)
return new TraceLoggerFactory();
return new NullLogFactory();
})
.As<Castle.Core.Logging.ILoggerFactory>()
.InstancePerLifetimeScope();
// call CreateLogger in response to the request for an ILogger implementation
moduleBuilder.Register(CreateLogger).As<ILogger>().InstancePerDependency();

View File

@@ -153,6 +153,7 @@
<Compile Include="DisplayManagement\Implementation\IShapeDisplayEvents.cs" />
<Compile Include="DisplayManagement\Implementation\IShapeFactoryEvents.cs" />
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
<Compile Include="Environment\HostEnvironment.cs" />
<Compile Include="Environment\DefaultHostEnvironment.cs" />
<Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" />
<Compile Include="Environment\Features\FeatureManager.cs" />