예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            app.UseMiniProfiler(new MiniProfilerOptions
            {
                RouteBasePath = "~/profiler",
                Storage       = new MemoryCacheStorage(new MemoryCache(new MemoryCacheOptions()), TimeSpan.FromMinutes(60))
            });

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                LoginPath            = new PathString("/"),
                AuthenticationScheme = "Cookie",
                Events = new CookieAuthenticationEvents
                {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                },
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true
            });

            // use DotVVM
            var dotvvmConfiguration = app.UseDotVVM <DotvvmStartup>(env.ContentRootPath);

            // use static files
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(env.WebRootPath)
            });
        }
예제 #2
0
파일: Startup.cs 프로젝트: llenroc/dotvvm
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            var supportedCultures = new[] {
                new CultureInfo("en-US"),
                new CultureInfo("cs-CZ")
            };

            app.UseCookieAuthentication(new CookieAuthenticationOptions {
                LoginPath            = new PathString("/ComplexSamples/Auth/Login"),
                AuthenticationScheme = "Scheme1",
                Events = new CookieAuthenticationEvents {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                }
            });

            app.UseCookieAuthentication(new CookieAuthenticationOptions {
                LoginPath            = new PathString("/ComplexSamples/SPARedirect/login"),
                AuthenticationScheme = "Scheme2",
                Events = new CookieAuthenticationEvents {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                }
            });

            app.UseCookieAuthentication(new CookieAuthenticationOptions {
                AuthenticationScheme = "Scheme3"
            });

            app.UseRequestLocalization(new RequestLocalizationOptions {
                DefaultRequestCulture   = new RequestCulture("en-US"),
                SupportedCultures       = supportedCultures,
                SupportedUICultures     = supportedCultures,
                RequestCultureProviders = new List <IRequestCultureProvider> {
                    new QueryStringRequestCultureProvider {
                        QueryStringKey = "lang"
                    }
                }
            });

            var config = app.UseDotVVM <DotvvmStartup>(GetApplicationPath(env));

            config.RouteTable.Add("AuthorizedPresenter", "ComplexSamples/Auth/AuthorizedPresenter", null, null, () => new AuthorizedPresenter());

            app.UseStaticFiles();
        }
예제 #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication("Scheme1")
            .AddCookie("Scheme1", o => {
                o.LoginPath = new PathString("/ComplexSamples/Auth/Login");
                o.Events    = new CookieAuthenticationEvents {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                };
            });

            services.AddAuthentication("Scheme2")
            .AddCookie("Scheme2", o => {
                o.LoginPath = new PathString("/ComplexSamples/SPARedirect/login");
                o.Events    = new CookieAuthenticationEvents {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                };
            });

            services.AddAuthentication("Scheme3")
            .AddCookie("Scheme3");


            services.AddLocalization(o => o.ResourcesPath = "Resources");

            services.AddDotVVM(options =>
            {
                CommonConfiguration.ConfigureServices(options.Services);
                options.AddDefaultTempStorages("Temp");
            });

            services.Configure <BindingCompilationOptions>(o => {
                o.TransformerClasses.Add(new BindingTestResolvers());
            });

            services.AddSingleton <IGreetingComputationService, HelloGreetingComputationService>();

            services.AddScoped <ViewModelScopedDependency>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CustomJwtOptions>(Configuration.GetSection("CustomJwt"));

            services.AddMvc();
            services.AddDotVVM <DotvvmStartup>();

            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
            {
                options.Events = new CookieAuthenticationEvents
                {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                };
                options.LoginPath = "/Login";
            })
            .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
            {
                var jwt = Configuration.GetSection("CustomJwt").Get <CustomJwtOptions>();

                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = jwt.Issuer,
                    ValidAudience    = jwt.Audience,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwt.Key))
                };
            });

            services.AddHttpContextAccessor();
            services.AddTransient <MvcUtility>();
        }
예제 #5
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 IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry(configuration);

            services.AddDataProtection();
            services.AddAuthorization();
            services.AddWebEncoders();

            services.AddDotVVM <DotvvmStartup>();

            services
            .AddAuthentication("Cookie")
            .AddCookie("Cookie", options =>
            {
                options.LoginPath = new PathString("/");
                options.Events    = new CookieAuthenticationEvents
                {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                };
            });

            services.AddMemoryCache();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.Configure <MiniProfilerOptions>(options =>
            {
                options.RouteBasePath = "/profiler";
                options.Storage       = new MemoryCacheStorage(new MemoryCache(new MemoryCacheOptions()), TimeSpan.FromMinutes(60));
            });

            return(WindsorRegistrationHelper.CreateServiceProvider(InitializeWindsor(), services));
        }
예제 #6
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)
        {
            services.AddMvc();
            services.AddNodeServices();
            services.AddDataProtection();
            services.AddAuthorization();
            services.AddWebEncoders();
            services.AddAutoMapper();
            services.AddDotVVM(options =>
            {
                options.AddDefaultTempStorages("Temp");
            });
            services.AddOptions();
            // services.AddDataAccess<MyAppContext>();
            var configurationSection = Configuration.GetSection("ConnectionStrings:DataAccessPostgreSqlProvider").Value;

            // var configureOptions = services.BuildServiceProvider().GetRequiredService<IConfigureOptions<ConnectionStrings>>();
            services.AddDbContext <MyAppContext>(options =>
            {
                // options.UseOpenIddict();
                options.UseNpgsql(
                    configurationSection,
                    b => b.MigrationsAssembly("Electroweb")
                    );
            });


            //AUTH

            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => {
                options.Events = new CookieAuthenticationEvents
                {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                };
                options.LoginPath = new PathString("/login");
            });


            // Add converter to DI
            // services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
            //llamar a los repositorios
            services.AddTransient <ITipoCableRepository, TipoCableRepository>();
            services.AddTransient <IDetalleTipoCableRepository, DetalleTipoCableRepository>();
            services.AddTransient <ITipoNovedadRepository, TipoNovedadRepository>();
            services.AddTransient <ITipoEquipoRepository, TipoEquipoRepository>();
            services.AddTransient <IDetalleTipoNovedadRepository, DetalleTipoNovedadRepository>();
            services.AddTransient <IEmpresaRepository, EmpresaRepository>();
            services.AddTransient <IDispositivoRepository, DispositivoRepository>();
            services.AddTransient <IEmpresaRepository, EmpresaRepository>();
            services.AddTransient <ICiudadRepository, CiudadRepository>();
            services.AddTransient <IDepartamentoRepository, DepartamentoRepository>();
            services.AddTransient <IMaterialRepository, MaterialRepository>();
            services.AddTransient <IEstadoRepository, EstadoRepository>();
            services.AddTransient <IElementoRepository, ElementoRepository>();
            services.AddTransient <IElementoCableRepository, ElementoCableRepository>();
            services.AddTransient <IEquipoElementoRepository, EquipoElementoRepository>();
            services.AddTransient <ILongitudElementoRepository, LongitudElementoRepository>();

            services.AddTransient <INovedadRepository, NovedadRepository>();
            services.AddTransient <IFotoRepository, FotoRepository>();
            services.AddTransient <IUsuarioRepository, UsuarioRepository>();

            services.AddTransient <IPerdidaRepository, PerdidaRepository>();
            //Ciudad Empresa
            services.AddTransient <ICiudad_EmpresaRepository, Ciudad_EmpresaRepository>();

            services.AddTransient <ILocalizacionElementoRepository, LocalizacionElementoRepository>();

            services.AddScoped <MasterDetailsPdfReport>();
            services.AddDirectoryBrowser();
            //agregar todo las interaces y sus implementacions
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            // var context = serviceProvider.GetRequiredService<MyAppContext>();
            var masterdetail  = serviceProvider.GetRequiredService <MasterDetailsPdfReport>();
            var elemntservice = serviceProvider.GetRequiredService <IElementoRepository>();

            MasterDetailsPdfReport._IelementosRepository = elemntservice;
            //  DbInitializer.Initialize(context);

            //  string wwwroot=Path.Combine("wwwroot");
            // string TheUrl = "http://54.86.105.4/";
            // string remote = GetHtmlPage(TheUrl);

            //  MasterDetailsPdfReport.CreateMasterDetailsPdfReport(wwwroot);
        }
예제 #7
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 IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.AddSingleton(Configuration);
            services.AddSingleton((IConfigurationRoot)Configuration);

            services.AddDataProtection();
            services.AddAuthorization();
            services.AddWebEncoders();

            services.AddDotVVM(options =>
            {
                options.AddDefaultTempStorages("Temp");
                options.AddMiniProfilerEventTracing();
                options.AddApplicationInsightsTracing();

                var dynamicDataConfig = new AppDynamicDataConfiguration();
                options.AddDynamicData(dynamicDataConfig);
            });

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <AppUser, AppRole>()
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();

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

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

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

            services
            .AddAuthentication(AuthenticationConstants.AUTHENTICATION_TYPE_NAME)
            .AddCookie(AuthenticationConstants.AUTHENTICATION_TYPE_NAME, options =>
            {
                // Cookie settings
                options.Cookie.HttpOnly   = true;
                options.Cookie.Expiration = TimeSpan.FromDays(150);
                options.LoginPath         = new PathString("/Default3"); // If the LoginPath is not set here, ASP.NET Core will default to /Account/Login
                options.LogoutPath        = "/Account/Logout";           // If the LogoutPath is not set here, ASP.NET Core will default to /Account/Logout
                options.AccessDeniedPath  = "/Account/AccessDenied";     // If the AccessDeniedPath is not set here, ASP.NET Core will default to /Account/AccessDenied
                options.SlidingExpiration = true;
                options.Events            = new CookieAuthenticationEvents
                {
                    OnRedirectToReturnUrl    = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
                };
            });

            services.AddMemoryCache();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            return(WindsorRegistrationHelper.CreateServiceProvider(InitializeWindsor(), services));
        }
예제 #8
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)
        {
            services.AddDataProtection();
            services.AddResponseCompression(opt => opt.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "image/svg+xml" }));

            var adminPolicy = new AuthorizationPolicyBuilder(new[] { CookieAuthenticationDefaults.AuthenticationScheme })
                              .RequireAuthenticatedUser()
                              .RequireRole(new[] { nameof(Roles.Administrator) })
                              .Build();

            var userPolicy = new AuthorizationPolicyBuilder(new[] { CookieAuthenticationDefaults.AuthenticationScheme })
                             .RequireAuthenticatedUser()
                             .Build();

            services.AddAuthorization(options =>
            {
                options.AddPolicy(nameof(Roles.User), userPolicy);
                options.AddPolicy(nameof(Roles.Administrator), adminPolicy);
            });

            services.AddWebEncoders();

            services.Configure <AppSettings>(Configuration);

            services.AddDbContext <BootstrapDbContext>(opt =>
            {
                opt.UseInMemoryDatabase("BootstrapDb");
                opt.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning));
            });

            //services.AddDbContext<BootstrapDbContext>(opt => {
            //    var bootstrapDb = Configuration.GetValue<string>(nameof(AppSettings.BootstrapDb));
            //    opt.UseSqlServer(bootstrapDb, o => o.UseRowNumberForPaging());
            //    opt.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning));
            //});

            services.AddIdentity <User, Role>(config =>
            {
                config.Password.RequireDigit           = false;
                config.Password.RequiredLength         = 0;
                config.Password.RequiredUniqueChars    = 0;
                config.Password.RequireLowercase       = false;
                config.Password.RequireUppercase       = false;
                config.Password.RequireNonAlphanumeric = false;
            })
            .AddEntityFrameworkStores <BootstrapDbContext>()
            .AddDefaultTokenProviders();

            services
            .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
            {
                options.LoginPath = new PathString("/login");
                options.Events    = new CookieAuthenticationEvents
                {
                    OnRedirectToReturnUrl    = async c => await DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToAccessDenied = async c => await DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
                    OnRedirectToLogin        = async c => await DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnRedirectToLogout       = async c => await DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
                    OnValidatePrincipal      = async c => await ValidateAsync(c)
                };
            });

            services
            .ConfigureApplicationCookie(options => options.LoginPath = new PathString("/login"));

            services.AddScoped <ExampleRecordService>();
            services.AddScoped <SettingsService>();
            services.AddScoped <IDbInitializer, DbInitializer>();

            services.AddDotVVM();
        }