mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
- Moving Authorization service to the new event system.
--HG-- branch : dev
This commit is contained in:
@@ -74,7 +74,7 @@
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Routes.cs" />
|
||||
<Compile Include="Security\Authorization.cs" />
|
||||
<Compile Include="Security\AuthorizationEventHandler.cs" />
|
||||
<Compile Include="Services\IPageService.cs" />
|
||||
<Compile Include="Routing\IPageSlugConstraint.cs" />
|
||||
<Compile Include="Services\PageService.cs" />
|
||||
|
@@ -7,8 +7,11 @@ using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Pages.Security {
|
||||
[UsedImplicitly]
|
||||
public class Authorization : AuthorizationServiceEvents {
|
||||
public override void Adjust(CheckAccessContext context) {
|
||||
public class AuthorizationEventHandler : IAuthorizationServiceEventHandler, IDependency {
|
||||
public void Checking(CheckAccessContext context) { }
|
||||
public void Complete(CheckAccessContext context) { }
|
||||
|
||||
public void Adjust(CheckAccessContext context) {
|
||||
if (context.Granted == false &&
|
||||
context.Content.Is<Page>() &&
|
||||
OwnerVariationExists(context.Permission) &&
|
@@ -13,13 +13,13 @@ namespace Orchard.Roles.Services {
|
||||
[UsedImplicitly]
|
||||
public class RolesBasedAuthorizationService : IAuthorizationService {
|
||||
private readonly IRoleService _roleService;
|
||||
private readonly IEnumerable<IAuthorizationServiceEvents> _events;
|
||||
private readonly IAuthorizationServiceEventHandler _authorizationServiceEventHandler;
|
||||
private static readonly string[] AnonymousRole = new[] { "Anonymous" };
|
||||
private static readonly string[] AuthenticatedRole = new[] { "Authenticated" };
|
||||
|
||||
public RolesBasedAuthorizationService(IRoleService roleService, IEnumerable<IAuthorizationServiceEvents> events) {
|
||||
public RolesBasedAuthorizationService(IRoleService roleService, IAuthorizationServiceEventHandler authorizationServiceEventHandler) {
|
||||
_roleService = roleService;
|
||||
_events = events;
|
||||
_authorizationServiceEventHandler = authorizationServiceEventHandler;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
@@ -35,9 +35,7 @@ namespace Orchard.Roles.Services {
|
||||
|
||||
public bool TryCheckAccess(Permission permission, IUser user, IContent content) {
|
||||
var context = new CheckAccessContext { Permission = permission, User = user, Content = content };
|
||||
|
||||
_events.Invoke(x => x.Checking(context), Logger);
|
||||
|
||||
_authorizationServiceEventHandler.Checking(context);
|
||||
|
||||
for (var adjustmentLimiter = 0; adjustmentLimiter != 3; ++adjustmentLimiter) {
|
||||
if (!context.Granted && context.User != null) {
|
||||
@@ -83,10 +81,10 @@ namespace Orchard.Roles.Services {
|
||||
}
|
||||
|
||||
context.Adjusted = false;
|
||||
_events.Invoke(x => x.Adjust(context), Logger);
|
||||
_authorizationServiceEventHandler.Adjust(context);
|
||||
}
|
||||
|
||||
_events.Invoke(x => x.Complete(context), Logger);
|
||||
_authorizationServiceEventHandler.Complete(context);
|
||||
|
||||
return context.Granted;
|
||||
}
|
||||
|
@@ -214,7 +214,7 @@
|
||||
<Compile Include="Mvc\Wrappers\HttpRequestBaseWrapper.cs" />
|
||||
<Compile Include="Mvc\Wrappers\HttpResponseBaseWrapper.cs" />
|
||||
<Compile Include="OrchardException.cs" />
|
||||
<Compile Include="Security\IAuthorizationServiceEvents.cs" />
|
||||
<Compile Include="Security\IAuthorizationServiceEventHandler.cs" />
|
||||
<Compile Include="Security\MembershipSettings.cs" />
|
||||
<Compile Include="Security\StandardPermissions.cs" />
|
||||
<Compile Include="Security\OrchardSecurityException.cs" />
|
||||
|
@@ -1,8 +1,9 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Events;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Security {
|
||||
public interface IAuthorizationServiceEvents : IEvents {
|
||||
public interface IAuthorizationServiceEventHandler : IEventHandler {
|
||||
void Checking(CheckAccessContext context);
|
||||
void Adjust(CheckAccessContext context);
|
||||
void Complete(CheckAccessContext context);
|
||||
@@ -15,10 +16,4 @@ namespace Orchard.Security {
|
||||
public bool Granted { get; set; }
|
||||
public bool Adjusted { get; set; }
|
||||
}
|
||||
|
||||
public abstract class AuthorizationServiceEvents : IAuthorizationServiceEvents {
|
||||
public virtual void Checking(CheckAccessContext context) { }
|
||||
public virtual void Adjust(CheckAccessContext context) { }
|
||||
public virtual void Complete(CheckAccessContext context) { }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user