示例#1
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((context, config) =>
        {
            config
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: false, reloadOnChange: true);
            context.Configuration = config.Build();
        })
        .ConfigureServices((context, services) =>
        {
            services.AddDbContext <DocStoreContext>(options =>
                                                    options.UseSqlServer(context.Configuration.GetConnectionString("DefaultConnection")));
            services.AddSingleton(typeof(StorConfig), StorConfigFactory.GetStorConfig(context.Configuration.GetValue <string>("StorConfigFilePath")));

            services.AddSingleton <MetadataRepository>();
            services.AddSingleton <DocumentRepository>();
            services.AddSingleton <SecurityRepository>();
            services.AddSingleton <GroupRepository>();
            services.AddSingleton <AccessRepository>();
            services.AddSingleton <BuisnessAreaRepository>();

            services.AddLogging(configure => configure.AddEventSourceLogger());

            services.AddHostedService <Worker>();
            services.AddHostedService <QueueService>();
        })
        .ConfigureLogging((context, logging) =>
        {
            logging.ClearProviders();

            logging.AddEventLog(settings =>
            {
                settings.LogName = "DocStore.Worker";
            });
            if (context.HostingEnvironment.IsDevelopment())
            {
                logging.SetMinimumLevel(LogLevel.Trace);
                logging.AddConsole();
            }
            else
            {
                logging.SetMinimumLevel(LogLevel.Information);
            }
        });
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Admins baseAdmins = new Admins();

            Configuration.GetSection("AdminGroups").Bind(baseAdmins);
            services.AddDbContext <DocStoreContext>(options =>
                                                    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddSingleton(typeof(StorConfig), StorConfigFactory.GetStorConfig(Configuration.GetValue <string>("StorConfigFilePath")));
            services.AddSingleton(typeof(Admins), baseAdmins);
            services.AddScoped <MetadataRepository>();
            services.AddScoped <DocumentRepository>();
            services.AddScoped <SecurityRepository>();
            services.AddScoped <GroupRepository>();
            services.AddScoped <AccessRepository>();
            services.AddScoped <BuisnessAreaRepository>();
            services.AddLogging(configure => configure.AddEventSourceLogger());
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
            services.AddAuthentication(authOptions =>
            {
                authOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
                authOptions.DefaultScheme          = IISDefaults.AuthenticationScheme;
            })
            .AddAzureAdBearer(options => Configuration.Bind("AzureAd", options));
            services.AddAuthorization(options =>
            {
                //Standard User Policy
                options.AddPolicy("AzAppUser", policy => policy
                                  .RequireAuthenticatedUser()
                                  .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                                  .RequireRole("AzDocStoreUser")
                                  .Build());
                options.AddPolicy("ADAppUser", policy => policy
                                  .RequireAuthenticatedUser()
                                  .AddAuthenticationSchemes(IISDefaults.AuthenticationScheme)
                                  .RequireRole("ADDocStoreUser")
                                  .Build());

                //Admin User Policy
                options.AddPolicy("AzAppAdmin", policy => policy
                                  .RequireAuthenticatedUser()
                                  .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                                  .RequireRole("AzDocStoreAdmin")
                                  .Build());
                options.AddPolicy("ADAppAdmin", policy => policy
                                  .RequireAuthenticatedUser()
                                  .AddAuthenticationSchemes(IISDefaults.AuthenticationScheme)
                                  .RequireRole("ADDocStoreAdmin")
                                  .Build());

                //Auditor User Policy
                options.AddPolicy("AzAppAuditor", policy => policy
                                  .RequireAuthenticatedUser()
                                  .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                                  .RequireRole("AzDocStoreAuditor")
                                  .Build());
                options.AddPolicy("ADAppAuditor", policy => policy
                                  .RequireAuthenticatedUser()
                                  .AddAuthenticationSchemes(IISDefaults.AuthenticationScheme)
                                  .RequireRole("ADDocStoreAuditor")
                                  .Build());
            });
        }