This is a migrated thread and some comments may be shown as answers.

[Solved] Security Trimming with custom AuthorizeAttribute

0 Answers 25 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mickaël
Top achievements
Rank 1
Mickaël asked on 11 May 2012, 08:01 AM
Hey everybody,

First of all, big kudos for your components, I'm kinda new to the technology, and it's a pleasure to work with them.
Now I'm faced with a problem you may know how to resolve.

I have a custom AuthorizeAttribute which looks like this :
public class MyAuthorizeAttribute : AuthorizeAttribute
{
    public IDependency Dependency
    {
        get;
        set;
    }
 
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        return Dependency != null;
    }
}

The Dependency, of type IDependency, is injected by Autofac whenever an action which has this filter is called.

The problem is this dependency is not injected when the Securoty Trimming feature if the menu checks if a user has access to an action. I've been looking into the code to see if there was a way to modify the way your component creates the instances of the filters, but couldn't find it.

Is there a way to do so?
If not, I'm thinking of disabling the securoty trimming feature and manually check in my View if the current user has access to some of the menu items and (not) render them depending on the result.

Hope I was clear,
Thanks heaps.

Mickaƫl
Tags
Menu
Asked by
Mickaël
Top achievements
Rank 1
Share this question
or