Search code examples
authenticationpermissionshandlerorchardcms

How to implement IAuthorizationServiceEventHandler in Orchard CMS?


I have difficulties with the implementation of IAuthorizationServiceEventHandler in Orchard CMS.

The issue here is that i want to check for specific permissions (permissions defined by my module) but the parameters of the handler methods (type Orchard.Security.CheckAccessContext) do not provide the feature name of the permission being checked.

Why is that so or is this a bug?

Surely i can name my permission like MyModuleName.PermissionName or use another type of name encoding but i think this is not practical as we already have the feature name linked to the permission in the DB for example.


Solution

  • Hmm, after reconsidering my approach and watching the call stack the issue is no more an issue.

    My question was based on the thinking that i need to compare aContext.Permission.Name provided by e.g. IAuthorizationServiceEventHandler.Complete() with the permission names of my module.

    But since the instance aContext.Permission provided by by e.g. IAuthorizationServiceEventHandler.Complete() is the instance passed to the related IAuthorizationService.TryCheckAccess() call i can do a simple comparison like

    if (aContext.Permission == MyModule.Permission.PermissionA) { ... }
    

    and it works because both instances have the same pointer address.