using fluentsecurity in modular system mvc 4

456 Views Asked by At

I have an MVC application named app_ui in my solution as a startup project, and some other applications in solution as modules. Then in startup project I access to modules and their actions by routetable. I use fluentsecurity for authorization and configure it in Global.asax for controllers in app_ui and everything works perfectly. But for controllers and actions in modules I can not add config to fluentsecurity and want to know how to add set policy for them.

1

There are 1 best solutions below

1
Kristoffer Ahl On BEST ANSWER

You can do this using Profiles in FluentSecurity 2.0 (beta1)! Here is a link to the documentation: https://github.com/kristofferahl/FluentSecurity/wiki/Profiles

1) Create a profile in your module

public class AdminAreaSecurityProfile : SecurityProfile
{
    public override void Configure()
    {
        For<UserAdminController>().RequireRole(UserRole.Administrator)
        For<BlogAdminController>().RequireRole(UserRole.Editor)
    }
}

2) Scan for profiles from the main application

SecurityConfigurator.Configure(configuration =>
{
    configuration.GetAuthenticationStatusFrom(() => HttpContext.Current.User.Identity.IsAuthenticated);

    configuration.Scan(scan =>
    {
        scan.AssembliesFromApplicationBaseDirectory();
        scan.LookForProfiles();
    });
});