Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseResponseCompression();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBlazorDebugging();
            }

            // install any modules or themes
            InstallationManager.InstallPackages("Modules,Themes");

            app.UseClientSideBlazorFiles <Client.Startup>();
            app.UseStaticFiles();

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Oqtane V1");
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapFallbackToClientSideBlazor <Client.Startup>("index.html");
            });
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Register localization services
            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddServerSideBlazor();

            // setup HttpClient for server side in a client side compatible fashion ( with auth cookie )
            if (!services.Any(x => x.ServiceType == typeof(HttpClient)))
            {
                services.AddScoped(s =>
                {
                    // creating the URI helper needs to wait until the JS Runtime is initialized, so defer it.
                    var navigationManager   = s.GetRequiredService <NavigationManager>();
                    var httpContextAccessor = s.GetRequiredService <IHttpContextAccessor>();
                    var authToken           = httpContextAccessor.HttpContext.Request.Cookies[".AspNetCore.Identity.Application"];
                    var client = new HttpClient(new HttpClientHandler {
                        UseCookies = false
                    });
                    if (authToken != null)
                    {
                        client.DefaultRequestHeaders.Add("Cookie", ".AspNetCore.Identity.Application=" + authToken);
                    }
                    client.BaseAddress = new Uri(navigationManager.Uri);
                    return(client);
                });
            }

            // register custom authorization policies
            services.AddAuthorizationCore(options =>
            {
                options.AddPolicy("ViewPage", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.View)));
                options.AddPolicy("EditPage", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.Edit)));
                options.AddPolicy("ViewModule", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.View)));
                options.AddPolicy("EditModule", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.Edit)));
                options.AddPolicy("ViewFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.View)));
                options.AddPolicy("EditFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Edit)));
                options.AddPolicy("ListFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Browse)));
            });

            // register scoped core services
            services.AddScoped <SiteState>();
            services.AddScoped <IAuthorizationHandler, PermissionHandler>();
            services.AddScoped <IInstallationService, InstallationService>();
            services.AddScoped <IModuleDefinitionService, ModuleDefinitionService>();
            services.AddScoped <IThemeService, ThemeService>();
            services.AddScoped <IAliasService, AliasService>();
            services.AddScoped <ITenantService, TenantService>();
            services.AddScoped <ISiteService, SiteService>();
            services.AddScoped <IPageService, PageService>();
            services.AddScoped <IModuleService, ModuleService>();
            services.AddScoped <IPageModuleService, PageModuleService>();
            services.AddScoped <IUserService, UserService>();
            services.AddScoped <IProfileService, ProfileService>();
            services.AddScoped <IRoleService, RoleService>();
            services.AddScoped <IUserRoleService, UserRoleService>();
            services.AddScoped <ISettingService, SettingService>();
            services.AddScoped <IPackageService, PackageService>();
            services.AddScoped <ILogService, LogService>();
            services.AddScoped <IJobService, JobService>();
            services.AddScoped <IJobLogService, JobLogService>();
            services.AddScoped <INotificationService, NotificationService>();
            services.AddScoped <IFolderService, FolderService>();
            services.AddScoped <IFileService, FileService>();
            services.AddScoped <ISiteTemplateService, SiteTemplateService>();
            services.AddScoped <ISqlService, SqlService>();
            services.AddScoped <ISystemService, SystemService>();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddDbContext <MasterDBContext>(options =>
                                                    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")
                                                                         .Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString())
                                                                         ));
            services.AddDbContext <TenantDBContext>(options => { });

            services.AddIdentityCore <IdentityUser>(options => { })
            .AddEntityFrameworkStores <TenantDBContext>()
            .AddSignInManager()
            .AddDefaultTokenProviders();

            var localizationSection = Configuration.GetSection("Localization");
            var localizationOptions = localizationSection.Get <LocalizationOptions>();

            services.Configure <LocalizationOptions>(localizationSection);

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 6;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;

                // Lockout settings
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(30);
                options.Lockout.MaxFailedAccessAttempts = 10;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings
                options.User.RequireUniqueEmail = false;
            });

            services.AddAuthentication(IdentityConstants.ApplicationScheme)
            .AddCookie(IdentityConstants.ApplicationScheme);

            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.HttpOnly          = false;
                options.Events.OnRedirectToLogin = context =>
                {
                    context.Response.StatusCode = 401;
                    return(Task.CompletedTask);
                };
            });

            // register custom claims principal factory for role claims
            services.AddTransient <IUserClaimsPrincipalFactory <IdentityUser>, ClaimsPrincipalFactory <IdentityUser> >();

            // register singleton scoped core services
            services.AddSingleton(Configuration);
            services.AddSingleton <IInstallationManager, InstallationManager>();
            services.AddSingleton <ISyncManager, SyncManager>();
            services.AddSingleton <IDatabaseManager, DatabaseManager>();

            // install any modules or themes ( this needs to occur BEFORE the assemblies are loaded into the app domain )
            InstallationManager.InstallPackages("Modules,Themes", _webRoot);

            // register transient scoped core services
            services.AddTransient <IModuleDefinitionRepository, ModuleDefinitionRepository>();
            services.AddTransient <IThemeRepository, ThemeRepository>();
            services.AddTransient <IUserPermissions, UserPermissions>();
            services.AddTransient <ITenantResolver, TenantResolver>();
            services.AddTransient <IAliasRepository, AliasRepository>();
            services.AddTransient <ITenantRepository, TenantRepository>();
            services.AddTransient <ISiteRepository, SiteRepository>();
            services.AddTransient <IPageRepository, PageRepository>();
            services.AddTransient <IModuleRepository, ModuleRepository>();
            services.AddTransient <IPageModuleRepository, PageModuleRepository>();
            services.AddTransient <IUserRepository, UserRepository>();
            services.AddTransient <IProfileRepository, ProfileRepository>();
            services.AddTransient <IRoleRepository, RoleRepository>();
            services.AddTransient <IUserRoleRepository, UserRoleRepository>();
            services.AddTransient <IPermissionRepository, PermissionRepository>();
            services.AddTransient <ISettingRepository, SettingRepository>();
            services.AddTransient <ILogRepository, LogRepository>();
            services.AddTransient <ILogManager, LogManager>();
            services.AddTransient <ILocalizationManager, LocalizationManager>();
            services.AddTransient <IJobRepository, JobRepository>();
            services.AddTransient <IJobLogRepository, JobLogRepository>();
            services.AddTransient <INotificationRepository, NotificationRepository>();
            services.AddTransient <IFolderRepository, FolderRepository>();
            services.AddTransient <IFileRepository, FileRepository>();
            services.AddTransient <ISiteTemplateRepository, SiteTemplateRepository>();
            services.AddTransient <ISqlRepository, SqlRepository>();
            services.AddTransient <IUpgradeManager, UpgradeManager>();

            // load the external assemblies into the app domain, install services
            services.AddOqtane(_runtime,
                               localizationOptions.SupportedCultures.IsNullOrEmpty()
                    ? DefaultSupportedCultures
                    : localizationOptions.SupportedCultures);

            services.AddMvc()
            .AddNewtonsoftJson()
            .AddOqtaneApplicationParts() // register any Controllers from custom modules
            .ConfigureOqtaneMvc();       // any additional configuration from IStart classes.

            if (_useSwagger)
            {
                services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo {
                        Title = "Oqtane", Version = "v1"
                    }); });
            }
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Register localization services
            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddOptions <List <Database> >().Bind(Configuration.GetSection(SettingKeys.AvailableDatabasesSection));

            services.AddServerSideBlazor()
            .AddCircuitOptions(options =>
            {
                if (_env.IsDevelopment())
                {
                    options.DetailedErrors = true;
                }
            });

            // setup HttpClient for server side in a client side compatible fashion ( with auth cookie )
            services.TryAddHttpClientWithAuthenticationCookie();

            // register custom authorization policies
            services.AddOqtaneAuthorizationPolicies();

            // register scoped core services
            services.AddScoped <IAuthorizationHandler, PermissionHandler>()
            .AddOqtaneScopedServices();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddIdentityCore <IdentityUser>(options => { })
            .AddEntityFrameworkStores <TenantDBContext>()
            .AddSignInManager()
            .AddDefaultTokenProviders()
            .AddClaimsPrincipalFactory <ClaimsPrincipalFactory <IdentityUser> >();  // role claims

            services.ConfigureOqtaneIdentityOptions();

            services.AddAuthentication(Constants.AuthenticationScheme)
            .AddCookie(Constants.AuthenticationScheme);

            services.ConfigureOqtaneCookieOptions();

            services.AddAntiforgery(options =>
            {
                options.HeaderName          = Constants.AntiForgeryTokenHeaderName;
                options.Cookie.HttpOnly     = false;
                options.Cookie.Name         = Constants.AntiForgeryTokenCookieName;
                options.Cookie.SameSite     = SameSiteMode.Strict;
                options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
            });

            // register singleton scoped core services
            services.AddSingleton(Configuration)
            .AddOqtaneSingletonServices();

            // install any modules or themes ( this needs to occur BEFORE the assemblies are loaded into the app domain )
            InstallationManager.InstallPackages(_env.WebRootPath, _env.ContentRootPath);

            // register transient scoped core services
            services.AddOqtaneTransientServices();

            // load the external assemblies into the app domain, install services
            services.AddOqtane(_runtime, _supportedCultures);
            services.AddOqtaneDbContext();


            services.AddMvc()
            .AddNewtonsoftJson()
            .AddOqtaneApplicationParts() // register any Controllers from custom modules
            .ConfigureOqtaneMvc();       // any additional configuration from IStart classes.

            services.TryAddSwagger(_useSwagger);
        }