Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(config =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                config.Filters.Add(new AuthorizeFilter(policy));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddMvc()
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeFolder("/Pages");
                options.Conventions.AuthorizeFolder("/ModelBases");
            });

            DeploymentConfiguration.ConfigureDatabase(Configuration, services, hostingEnvironment);
            FileManager.ConnectionString = Configuration.GetConnectionString("AzureStorageConnectionString");

            services.AddAuthentication().AddMicrosoftAccount(microsoftOptions =>
            {
                microsoftOptions.ClientId     = Configuration["Authentication-Microsoft-ApplicationId"];
                microsoftOptions.ClientSecret = Configuration["Authentication-Microsoft-Password"];
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("IsEventAuthor", policy => policy.Requirements.Add(new IsAuthorInEventRequirement()));
                options.AddPolicy("IsEventAdmin", policy => policy.Requirements.Add(new IsAdminInEventRequirement()));
                options.AddPolicy("IsGlobalAdmin", policy => policy.Requirements.Add(new IsGlobalAdminRequirement()));
                options.AddPolicy("IsPlayer", policy => policy.Requirements.Add(new IsPlayerInEventRequirement()));
                options.AddPolicy("PlayerCanSeePuzzle", policy => policy.Requirements.Add(new PlayerCanSeePuzzleRequirement()));
                options.AddPolicy("PlayerIsOnTeam", policy => policy.Requirements.Add(new PlayerIsOnTeamRequirement()));
                options.AddPolicy("IsAuthorOfPuzzle", policy => policy.Requirements.Add(new IsAuthorOfPuzzleRequirement()));
                options.AddPolicy("IsEventAdminOrEventAuthor", policy => policy.Requirements.Add(new IsEventAdminOrEventAuthorRequirement()));
                options.AddPolicy("IsEventAdminOrPlayerOnTeam", policy => policy.Requirements.Add(new IsEventAdminOrPlayerOnTeamRequirement()));
                options.AddPolicy("IsEventAdminOrAuthorOfPuzzle", policy => policy.Requirements.Add(new IsEventAdminOrAuthorOfPuzzleRequirement()));
                options.AddPolicy("IsRegisteredForEvent", policy => policy.Requirements.Add(new IsRegisteredForEventRequirement()));
            });

            services.AddScoped <IAuthorizationHandler, IsAuthorInEventHandler>();
            services.AddScoped <IAuthorizationHandler, IsAdminInEventHandler>();
            services.AddScoped <IAuthorizationHandler, IsGlobalAdminHandler>();
            services.AddScoped <IAuthorizationHandler, IsPlayerInEventHandler>();
            services.AddScoped <IAuthorizationHandler, PlayerCanSeePuzzleHandler>();
            services.AddScoped <IAuthorizationHandler, PlayerIsOnTeamHandler>();
            services.AddScoped <IAuthorizationHandler, IsAuthorOfPuzzleHandler>();

            services.AddScoped <IAuthorizationHandler, IsEventAdminOrAuthorOfPuzzleHandler_Admin>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrAuthorOfPuzzleHandler_Author>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrEventAuthorHandler_Admin>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrEventAuthorHandler_Author>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrPlayerOnTeamHandler_Admin>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrPlayerOnTeamHandler_Play>();
            services.AddScoped <IAuthorizationHandler, IsRegisteredForEventHandler_Admin>();
            services.AddScoped <IAuthorizationHandler, IsRegisteredForEventHandler_Author>();
            services.AddScoped <IAuthorizationHandler, IsRegisteredForEventHandler_Player>();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Endpoint routing breaks most of our links because it doesn't include "ambient" route parameters
            // like eventId and eventRole in links -- they'd have to be manually specified everywhere
            services.AddMvc(options =>
            {
                options.EnableEndpointRouting = false;
            });

            services.AddRazorPages()
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.AuthorizeFolder("/Pages");
                options.Conventions.AuthorizeFolder("/ModelBases");
            });

            DeploymentConfiguration.ConfigureDatabase(Configuration, services, _hostEnv);
            FileManager.ConnectionString = Configuration.GetConnectionString("AzureStorageConnectionString");

            services.AddAuthentication().AddMicrosoftAccount(microsoftOptions =>
            {
                microsoftOptions.ClientId     = Configuration["Authentication-Microsoft-ApplicationId"];
                microsoftOptions.ClientSecret = Configuration["Authentication-Microsoft-Password"];
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("IsEventAuthor", policy => policy.Requirements.Add(new IsAuthorInEventRequirement()));
                options.AddPolicy("IsEventAdmin", policy => policy.Requirements.Add(new IsAdminInEventRequirement()));
                options.AddPolicy("IsGlobalAdmin", policy => policy.Requirements.Add(new IsGlobalAdminRequirement()));
                options.AddPolicy("IsPlayer", policy => policy.Requirements.Add(new IsPlayerInEventRequirement()));
                options.AddPolicy("PlayerCanSeePuzzle", policy => policy.Requirements.Add(new PlayerCanSeePuzzleRequirement()));
                options.AddPolicy("PlayerIsOnTeam", policy => policy.Requirements.Add(new PlayerIsOnTeamRequirement()));
                options.AddPolicy("IsAuthorOfPuzzle", policy => policy.Requirements.Add(new IsAuthorOfPuzzleRequirement()));
                options.AddPolicy("IsEventAdminOrEventAuthor", policy => policy.Requirements.Add(new IsEventAdminOrEventAuthorRequirement()));
                options.AddPolicy("IsEventAdminOrPlayerOnTeam", policy => policy.Requirements.Add(new IsEventAdminOrPlayerOnTeamRequirement()));
                options.AddPolicy("IsEventAdminOrAuthorOfPuzzle", policy => policy.Requirements.Add(new IsEventAdminOrAuthorOfPuzzleRequirement()));
                options.AddPolicy("IsRegisteredForEvent", policy => policy.Requirements.Add(new IsRegisteredForEventRequirement()));
            });

            services.AddScoped <IAuthorizationHandler, IsAuthorInEventHandler>();
            services.AddScoped <IAuthorizationHandler, IsAdminInEventHandler>();
            services.AddScoped <IAuthorizationHandler, IsGlobalAdminHandler>();
            services.AddScoped <IAuthorizationHandler, IsPlayerInEventHandler>();
            services.AddScoped <IAuthorizationHandler, PlayerCanSeePuzzleHandler>();
            services.AddScoped <IAuthorizationHandler, PlayerIsOnTeamHandler>();
            services.AddScoped <IAuthorizationHandler, IsAuthorOfPuzzleHandler>();

            services.AddScoped <IAuthorizationHandler, IsEventAdminOrAuthorOfPuzzleHandler_Admin>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrAuthorOfPuzzleHandler_Author>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrEventAuthorHandler_Admin>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrEventAuthorHandler_Author>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrPlayerOnTeamHandler_Admin>();
            services.AddScoped <IAuthorizationHandler, IsEventAdminOrPlayerOnTeamHandler_Play>();
            services.AddScoped <IAuthorizationHandler, IsRegisteredForEventHandler_Admin>();
            services.AddScoped <IAuthorizationHandler, IsRegisteredForEventHandler_Author>();
            services.AddScoped <IAuthorizationHandler, IsRegisteredForEventHandler_Player>();
            services.AddScoped <BackgroundFileUploader>();
            services.AddScoped <AuthorizationHelper>();
        }
Exemplo n.º 3
0
        public void Configure(IWebHostBuilder builder)
        {
            builder.ConfigureServices((context, services) =>
            {
                // Set up to use Azure settings
                IWebHostEnvironment env             = context.HostingEnvironment;
                IConfigurationBuilder configBuilder = new ConfigurationBuilder()
                                                      .SetBasePath(env.ContentRootPath)
                                                      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                                                      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                                                      .AddEnvironmentVariables();
                context.Configuration = configBuilder.Build();

                DeploymentConfiguration.ConfigureDatabase(context.Configuration, services, env);

                services.AddDefaultIdentity <IdentityUser>()
                .AddEntityFrameworkStores <PuzzleServerContext>();
            });
        }