mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#17667: Fixing AccessFrontEnd permission
Work Items: 17667 --HG-- branch : 1.x
This commit is contained in:
@@ -38,9 +38,6 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
//TODO: (erikpo) Should think about moving the slug parameters and get calls and null checks up into a model binder or action filter
|
||||
public ActionResult Item(string blogPath, string postSlug) {
|
||||
if (!_services.Authorizer.Authorize(StandardPermissions.AccessFrontEnd, T("Couldn't view blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
var blogPart = _blogService.Get(blogPath);
|
||||
if (blogPart == null)
|
||||
|
||||
@@ -64,9 +64,16 @@ namespace Orchard.Roles.Services {
|
||||
rolesToExamine = AnonymousRole;
|
||||
}
|
||||
else if (context.User.Has<IUserRoles>()) {
|
||||
rolesToExamine = context.User.As<IUserRoles>().Roles.Concat(AuthenticatedRole);
|
||||
// the current user is not null, so get his roles and add "Authenticated" to it
|
||||
rolesToExamine = context.User.As<IUserRoles>().Roles;
|
||||
|
||||
// when it is a simulated anonymous user in the admin
|
||||
if (!rolesToExamine.Contains(AnonymousRole[0])) {
|
||||
rolesToExamine = rolesToExamine.Concat(AuthenticatedRole);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// the user is not null and has no specific role, then it's just "Authenticated"
|
||||
rolesToExamine = AuthenticatedRole;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation />
|
||||
<TargetFrameworkProfile />
|
||||
<UseIISExpress>false</UseIISExpress>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -70,6 +71,7 @@
|
||||
<Compile Include="Models\UserPartRecord.cs" />
|
||||
<Compile Include="Models\UserStatus.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Security\AccessFrontEndFilter.cs" />
|
||||
<Compile Include="Services\IUserService.cs" />
|
||||
<Compile Include="Services\MembershipService.cs" />
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Users.Security {
|
||||
public class FrontEndFilter : FilterProvider, IAuthorizationFilter {
|
||||
private readonly IAuthorizer _authorizer;
|
||||
|
||||
public FrontEndFilter(IAuthorizer authorizer) {
|
||||
_authorizer = authorizer;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public void OnAuthorization(AuthorizationContext filterContext) {
|
||||
|
||||
var isAuthPage = (filterContext.ActionDescriptor.ActionName == "LogOn"
|
||||
|| filterContext.ActionDescriptor.ActionName == "ChangePassword"
|
||||
|| filterContext.ActionDescriptor.ActionName == "AccessDenied"
|
||||
|| filterContext.ActionDescriptor.ActionName == "Register")
|
||||
&& filterContext.ActionDescriptor.ControllerDescriptor.ControllerName == "Account";
|
||||
|
||||
if (!isAuthPage && !_authorizer.Authorize(StandardPermissions.AccessFrontEnd, T("Can't access this website"))) {
|
||||
filterContext.Result = new HttpUnauthorizedResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user