#17322: Restricting access to webconsole to default tenant.

--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-04-06 14:50:17 -07:00
parent ea11a4d2c9
commit 5e10feb156
3 changed files with 41 additions and 32 deletions

View File

@@ -4,10 +4,12 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Commands; using Orchard.Commands;
using Orchard.Environment.Configuration;
using Orchard.Experimental.ViewModels; using Orchard.Experimental.ViewModels;
using Orchard.Environment.Extensions; using Orchard.Environment.Extensions;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Security;
using Orchard.Themes; using Orchard.Themes;
using Orchard.UI.Admin; using Orchard.UI.Admin;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
@@ -15,11 +17,15 @@ using Orchard.Utility.Extensions;
namespace Orchard.Experimental.Controllers { namespace Orchard.Experimental.Controllers {
[Themed, Admin, OrchardFeature("Orchard.Experimental.WebCommandLine")] [Themed, Admin, OrchardFeature("Orchard.Experimental.WebCommandLine")]
public class CommandsController : Controller { public class CommandsController : Controller {
private readonly ShellSettings _shellSettings;
private readonly ICommandManager _commandManager; private readonly ICommandManager _commandManager;
public CommandsController(ICommandManager commandManager, IOrchardServices services) { public CommandsController(ShellSettings shellSettings, ICommandManager commandManager, IOrchardServices services) {
_shellSettings = shellSettings;
_commandManager = commandManager; _commandManager = commandManager;
Services = services; Services = services;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
} }
@@ -33,11 +39,17 @@ namespace Orchard.Experimental.Controllers {
} }
public ActionResult Execute() { public ActionResult Execute() {
if (_shellSettings.Name != ShellSettings.DefaultName || !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to use the web console")))
return new HttpUnauthorizedResult();
return View("Execute", new CommandsExecuteViewModel()); return View("Execute", new CommandsExecuteViewModel());
} }
[HttpPost] [HttpPost]
public ActionResult Execute(CommandsExecuteViewModel model) { public ActionResult Execute(CommandsExecuteViewModel model) {
if (_shellSettings.Name != ShellSettings.DefaultName || !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to use the web console")))
return new HttpUnauthorizedResult();
try { try {
using (var writer = new StringWriter()) { using (var writer = new StringWriter()) {
var commandLine = model.CommandLine.Trim(); var commandLine = model.CommandLine.Trim();

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Core.Contents.Controllers; using Orchard.Core.Contents.Controllers;
using Orchard.Localization; using Orchard.Localization;

View File

@@ -8,7 +8,6 @@ using Orchard.Logging;
using Orchard.MultiTenancy.Services; using Orchard.MultiTenancy.Services;
using Orchard.MultiTenancy.ViewModels; using Orchard.MultiTenancy.ViewModels;
using Orchard.Security; using Orchard.Security;
using Orchard.UI.Notify;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
namespace Orchard.MultiTenancy.Controllers { namespace Orchard.MultiTenancy.Controllers {
@@ -105,40 +104,39 @@ namespace Orchard.MultiTenancy.Controllers {
[HttpPost, ActionName("Edit")] [HttpPost, ActionName("Edit")]
public ActionResult EditPost(TenantEditViewModel viewModel) { public ActionResult EditPost(TenantEditViewModel viewModel) {
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Couldn't edit tenant")))
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Couldn't edit tenant"))) return new HttpUnauthorizedResult();
return new HttpUnauthorizedResult();
if ( !EnsureDefaultTenant() ) if ( !EnsureDefaultTenant() )
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == viewModel.Name); var tenant = _tenantService.GetTenants().FirstOrDefault(ss => ss.Name == viewModel.Name);
if (tenant == null) if (tenant == null)
return HttpNotFound(); return HttpNotFound();
if (!ModelState.IsValid) { if (!ModelState.IsValid) {
return View(viewModel); return View(viewModel);
} }
try { try {
_tenantService.UpdateTenant( _tenantService.UpdateTenant(
new ShellSettings new ShellSettings
{ {
Name = tenant.Name, Name = tenant.Name,
RequestUrlHost = viewModel.RequestUrlHost, RequestUrlHost = viewModel.RequestUrlHost,
RequestUrlPrefix = viewModel.RequestUrlPrefix, RequestUrlPrefix = viewModel.RequestUrlPrefix,
DataProvider = viewModel.DataProvider, DataProvider = viewModel.DataProvider,
DataConnectionString = viewModel.DatabaseConnectionString, DataConnectionString = viewModel.DatabaseConnectionString,
DataTablePrefix = viewModel.DatabaseTablePrefix, DataTablePrefix = viewModel.DatabaseTablePrefix,
State = tenant.State State = tenant.State
}); });
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
catch (Exception exception) { catch (Exception exception) {
this.Error(exception, T("Failed to edit tenant: {0} ", exception.Message), Logger, Services.Notifier); this.Error(exception, T("Failed to edit tenant: {0} ", exception.Message), Logger, Services.Notifier);
return View(viewModel); return View(viewModel);
} }
} }
[HttpPost] [HttpPost]