public static void RegisterAuth(MVCRefereeConfigurationBuilder configuration)
        {
            //Ensure all actions on this controller require the user to be authenticated
            configuration.RegisterClassMethods <DinnerController>(a => a.AuthorizedBy <Authenticated>());

            //Ensure that the create action on this controller can only be called by users with the"Host" role
            configuration.RegisterEach <DinnerController>(c => c.Create(), c => c.Create(default(DinnerEditModel))).With(a => a.AuthorizedBy <HasRoles>(r => r.Roles("Host")));

            //Ensure that the delete action on this controller invokes a custom authorizer that checks in the database to see what roles
            //Are required for the activity named "Delete"
            configuration.Register(a => a.Method <DinnerController>(c => c.Delete(default(int))).Name("Delete").AuthorizedBy <RolesInDatabase>());

            //Ensure both edit actions on this controller invokes a custom authorizer. The call to "As<EditDinner>" will ensure the authorize method of the authorizer will recieve an instance of the EditDinner class.
            //This instance will be be built using parameters from the method.
            configuration.RegisterEach <DinnerController>(a => a.Edit(0), a => a.Edit(default(DinnerEditModel)))
            .With(a => a.As <EditDinner>().AuthorizedBy <EditDinnerAuthorizer>());
        }
Beispiel #2
0
        public static void RegisterAuth(MVCRefereeConfigurationBuilder configuration)
        {
            //We can also register all methods in a class at once, using the RegisterClassMethods method
            configuration.RegisterClassMethods <AccountController>(a => a.AuthorizedBy <Authenticated>());

            //Overriding the login action since it needs to be anonymous. By calling AuthorizedBy<AllowAnonymous> all other registered authorizers will be ignored
            configuration.Register(a => a.Method <AccountController>(c => c.Login("")).AuthorizedBy <AllowAnonymous>());

            //For streamlined syntax, multiple methods can be registered using the RegisterEach method
            configuration.RegisterEach <AccountController>(
                c => c.Login(""),
                c => c.Login(null, ""),
                c => c.Register(null),
                c => c.Register(),
                c => c.ExternalLogin("", ""),
                c => c.ExternalLoginCallback(""),
                c => c.ExternalLoginConfirmation(null, ""),
                c => c.ExternalLoginFailure()
                ).With(a => a.AuthorizedBy <AllowAnonymous>());
        }
 public static void RegisterAuth(MVCRefereeConfigurationBuilder builder)
 {
     builder.RegisterClassMethods <RolesController>(a => a.AuthorizedBy <Authenticated>());
 }