예제 #1
0
        public static IAuthorizationService Configure(Action <MVCRefereeConfigurationBuilder> builderConfiguration)
        {
            var builder = new MVCRefereeConfigurationBuilder(new AuthorizerFactory(), new ActivityFactory());

            builderConfiguration.Invoke(builder);
            return(Configure(builder));
        }
예제 #2
0
        public static MvcAuthorizationService ServiceBuilder(MVCRefereeConfigurationBuilder conf)
        {
            var configuration = conf.Build();

            var service = new MvcAuthorizationService(configuration.AuthorizerResolver, configuration.ActivityResolver,
                                                      new AuthorizationFailureManager(conf.ActivityRegistrations));

            return(service);
        }
예제 #3
0
        public static IAuthorizationService Configure(MVCRefereeConfigurationBuilder builder)
        {
            var configuration = builder.Build();
            var service       = new MvcAuthorizationService(configuration.AuthorizerResolver, configuration.ActivityResolver,
                                                            new AuthorizationFailureManager(builder.ActivityRegistrations));
            var filter = new AuthorizeActivity(service, GlobalFilters.Filters);

            GlobalFilters.Filters.Add(filter);
            CurrentAuthorizationService = service;
            return(service);
        }
예제 #4
0
        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>());
        }
예제 #5
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>());
        }
예제 #6
0
 public static void RegisterAuth(MVCRefereeConfigurationBuilder builder)
 {
     builder.RegisterClassMethods <RolesController>(a => a.AuthorizedBy <Authenticated>());
 }