示例#1
0
 public WebHelper(HostingConfig hostingConfig, IHttpContextAccessor httpContextAccessor,
                  IShareFileProvider fileProvider)
 {
     _hostingConfig       = hostingConfig;
     _httpContextAccessor = httpContextAccessor;
     _fileProvider        = fileProvider;
 }
        public void Delete(RhspDataID dataID)
        {
            DnsZone dnsZone = HostingConfig.GetSingle <DnsZone>(dataID);

            HostingConfig.Delete <DnsZone>(dataID);
            CreateManager <IscBindManager>().DeleteZone(dnsZone);
        }
示例#3
0
 public async Task Invoke(HttpContext context)
 {
     using (HostingConfig.GetContainer().BeginScope())
     {
         await _next.Invoke(context);
     }
 }
示例#4
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="httpContext">HTTP context</param>
 public WebHelper(IHttpContextAccessor httpContextAccessor, HostingConfig hostingConfig, IHostApplicationLifetime applicationLifetime, IServiceProvider serviceProvider)
 {
     _hostingConfig       = hostingConfig;
     _httpContextAccessor = httpContextAccessor;
     _applicationLifetime = applicationLifetime;
     _serviceProvider     = serviceProvider;
 }
示例#5
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="hostingConfig">Hosting config</param>
 /// <param name="httpContextAccessor">HTTP context accessor</param>
 /// <param name="fileProvider">File provider</param>
 public WebHelper(HostingConfig hostingConfig, IHttpContextAccessor httpContextAccessor,
                  INetProFileProvider fileProvider)
 {
     this._hostingConfig       = hostingConfig;
     this._httpContextAccessor = httpContextAccessor;
     this._fileProvider        = fileProvider;
 }
示例#6
0
 private void deleteWebsiteHost(WebsiteHost websiteHost)
 {
     if (GetDataSchemaVersion <WebsiteHost>(websiteHost.DataID) >= 2)
     {
         HostingConfig.Delete <WebsiteHost>(websiteHost.DataID);
     }
 }
示例#7
0
 public WebHelper(IOptions <HostingConfig> hostingOptions,
                  IHostApplicationLifetime hostApplicationLifetime,
                  IHttpContextAccessor httpContextAccessor)
 {
     _hostingConfig           = hostingOptions.Value;
     _hostApplicationLifetime = hostApplicationLifetime;
     _httpContextAccessor     = httpContextAccessor;
 }
示例#8
0
 public Config()
 {
     ConnectionStrings = new ConnectionStringsConfig();
     Hosting           = new HostingConfig();
     MalApi            = new MalApiConfig();
     Recommendations   = new RecommendationsConfig();
     Html = new HtmlConfig();
 }
示例#9
0
 public WebHelper(HostingConfig hostingConfig,
                  IHttpContextAccessor httpContextAccessor,
                  INopFileProvider fileProvider,
                  NavigationManager uriHelper)
 {
     this._hostingConfig       = hostingConfig;
     this._httpContextAccessor = httpContextAccessor;
     this._fileProvider        = fileProvider;
 }
 private IEnumerable <SecurityTemplate> getQuery()
 {
     return(from r in HostingConfig.GetArray <SecurityTemplate>()
            join w in HostingConfig.GetArray <Website>()
            on r.WebsiteID equals w.DataID
            join c in HostingConfig.GetArray <Customer>()
            on w.CustomerID equals c.DataID
            select SecurityTemplate.Combine(r, Website.Combine(w, c)));
 }
示例#11
0
 /// <summary>
 /// Ctor
 /// </summary>
 public WebHelper(
     IHttpContextAccessor httpContextAccessor,
     HostingConfig hostingConfig,
     IHostApplicationLifetime applicationLifetime
     )
 {
     _hostingConfig       = hostingConfig;
     _httpContextAccessor = httpContextAccessor;
     _applicationLifetime = applicationLifetime;
 }
示例#12
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="httpContext">HTTP context</param>
 public WebHelper(IHttpContextAccessor httpContextAccessor, HostingConfig hostingConfig, IHostApplicationLifetime applicationLifetime, IStoreContext storeContext,
                  IMachineNameProvider machineNameProvider
                  )
 {
     _hostingConfig       = hostingConfig;
     _httpContextAccessor = httpContextAccessor;
     _applicationLifetime = applicationLifetime;
     _storeContext        = storeContext;
     _machineNameProvider = machineNameProvider;
 }
示例#13
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, HostingConfig hostingConfig)
 {
     app.UseHsts();
     app.UseHttpsRedirection();
     app.UseOpenIdAuthority(env, hostingConfig);
     app.UseSwagger();
     app.UseSwaggerUI(c =>
     {
         c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
     });
 }
示例#14
0
            public WebClientNotification(HostingConfig hostingConfig, CountdownEvent receiveEvent, string routingKey)
            {
                var hubConnection = new HubConnection($"{hostingConfig.Scheme}://{hostingConfig.Name}:{hostingConfig.Port}/");
                var hubProxy      = hubConnection.CreateHubProxy("ClientNotificationServiceHub");

                hubProxy.On <object>(routingKey, OnReceive);
                hubConnection.Start().Wait();

                _receiveEvent = receiveEvent;
                _hubProxy     = hubProxy;
            }
示例#15
0
        public IOwinHostingContext CreateOwinHostingContext(HostingConfig hostingConfig)
        {
            var autofacContainerBuilder = new ContainerBuilder();

            var containerModuleScanner = new BaseDirectoryContainerModuleScanner();

            // Поиск всех доступных модулей
            var containerModules = containerModuleScanner.FindContainerModules();

            foreach (var moduleInfo in containerModules)
            {
                var containerModule = CreateContainerModule(moduleInfo);

                // Регистрация очередного модуля
                autofacContainerBuilder.RegisterModule(new AutofacContainerModule(containerModule));
            }

            // Регистрация IoC-модуля для OWIN
            autofacContainerBuilder.RegisterType <AutofacOwinHostingModule>()
            .As <IOwinHostingModule>()
            .SingleInstance();

            // ReSharper disable AccessToModifiedClosure

            // Регистрация самого Autofac-контейнера
            IContainer        autofacRootContainer        = null;
            Func <IContainer> autofacRootContainerFactory = () => autofacRootContainer;

            autofacContainerBuilder.RegisterInstance(autofacRootContainerFactory);
            autofacContainerBuilder.Register(r => r.Resolve <Func <IContainer> >()()).As <IContainer>().SingleInstance();

            // Регистрация обертки над контейнером
            IContainerResolver        containerResolver        = null;
            Func <IContainerResolver> containerResolverFactory = () => containerResolver;

            autofacContainerBuilder.RegisterInstance(containerResolverFactory);
            autofacContainerBuilder.Register(r => r.Resolve <Func <IContainerResolver> >()()).As <IContainerResolver>().SingleInstance();

            // Регистрация контейнера для WebApi
            IDependencyResolver        webApiDependencyResolver        = null;
            Func <IDependencyResolver> webApiDependencyResolverFactory = () => webApiDependencyResolver;

            autofacContainerBuilder.RegisterInstance(webApiDependencyResolverFactory);
            autofacContainerBuilder.Register(r => r.Resolve <Func <IDependencyResolver> >()()).As <IDependencyResolver>().SingleInstance();

            // ReSharper restore AccessToModifiedClosure

            // Построение контейнера зависимостей
            autofacRootContainer     = autofacContainerBuilder.Build();
            containerResolver        = new AutofacContainerResolver(autofacRootContainer, Middleware.AutofacRequestLifetimeScopeOwinMiddleware.TryGetRequestContainer);
            webApiDependencyResolver = new AutofacWebApiDependencyResolver(autofacRootContainer);

            return(new OwinHostingContext(hostingConfig, containerResolver, new AutofacOwinMiddlewareResolver()));
        }
        public void Replace(DnsZone dnsZone)
        {
            // Remove any existing zones with matching name.
            var existing = from dz in HostingConfig.GetArray <DnsZone>()
                           where dz.Name == dnsZone.Name
                           select dz;

            existing.ToList().ForEach(dz => Delete(dz.DataID));

            // Now proceed to create the new zone.
            Create(dnsZone);
        }
        private string getMainConfigFileContent()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("#\r\n# {0}\r\n#\r\n", generatedConfigFileComment);

            // For each zone, add an index to the zone file.
            HostingConfig.GetArray <DnsZone>().ToList().ForEach(
                z => builder.AppendLine(getZoneConfigIndex(z)));

            return(builder.ToString());
        }
        public void Update(SecurityTemplate securityTemplate)
        {
            SecurityTemplate existing = Get(securityTemplate.DataID);

            if (existing.Access != securityTemplate.Access)
            {
                throw new Exception("Access mode cannot be changed once set.");
            }

            enforceConstraints(securityTemplate);
            HostingConfig.Update(securityTemplate);
        }
示例#19
0
 public WebHelper(HostingConfig hostingConfig,
                  IActionContextAccessor actionContextAccessor,
                  IApplicationLifetime applicationLifetime,
                  IHttpContextAccessor httpContextAccessor,
                  IUrlHelperFactory urlHelperFactory)
 {
     _hostingConfig         = hostingConfig;
     _actionContextAccessor = actionContextAccessor;
     _applicationLifetime   = applicationLifetime;
     _httpContextAccessor   = httpContextAccessor;
     _urlHelperFactory      = urlHelperFactory;
 }
示例#20
0
        private void enforceConstraints(Website dirtyWebsite)
        {
            if (string.IsNullOrEmpty(dirtyWebsite.PrimaryHost.Name))
            {
                throw new Exception(
                          "Primary host name cannot be null or empty.");
            }

            if (dirtyWebsite.PrimaryHost.Port != WebsiteHost.DefaultHttpPort)
            {
                throw new Exception(
                          "Primary host must use the default http " +
                          "port (" + WebsiteHost.DefaultHttpPort + ").");
            }

            if (dirtyWebsite.PrimaryHost.Protocol != WebsiteHostProtocol.Http)
            {
                throw new Exception(
                          "Primary host must use the http protocol.");
            }

            if (dirtyWebsite.CustomerID == null)
            {
                throw new Exception(
                          "Customer ID was not defined for website.");
            }

            WebsiteHost[] conflictArray;
            if (ExistsWithAnyHost(dirtyWebsite, out conflictArray))
            {
                throw new Exception(
                          "A website already exists with host names: "
                          + string.Join(", ", conflictArray.Select(h => h.Name).ToArray()) + ".");
            }

            if (dirtyWebsite.PrimaryHostID == null)
            {
                throw new Exception(
                          "Primary host ID was not set.");
            }

            if (HostingConfig.Exists <Website>(dirtyWebsite.DataID))
            {
                CleanWebsite cleanWebsite = getClean(dirtyWebsite.DataID);

                if (cleanWebsite.CustomerID != dirtyWebsite.CustomerID)
                {
                    throw new Exception("Customer cannot be changed.");
                }
            }
        }
        private void enforceUniqueZone(DnsZone zone)
        {
            // Find zones with same name other than the current one.
            var q = from z in HostingConfig.GetArray <DnsZone>()
                    where z.Name == zone.Name
                    where !z.DataID.Equals(zone.DataID)
                    select z;

            if (q.Count() != 0)
            {
                throw new Exception(
                          "A DNS zone with the name '" + zone.Name + "' already exists.");
            }
        }
示例#22
0
 public WebHelper(HostingConfig hostingConfig,
                  IActionContextAccessor actionContextAccessor,
                  IHostApplicationLifetime hostApplicationLifetime,
                  IHttpContextAccessor httpContextAccessor,
                  IAnyFileProvider fileProvider,
                  IUrlHelperFactory urlHelperFactory)
 {
     _hostingConfig           = hostingConfig;
     _actionContextAccessor   = actionContextAccessor;
     _hostApplicationLifetime = hostApplicationLifetime;
     _httpContextAccessor     = httpContextAccessor;
     _fileProvider            = fileProvider;
     _urlHelperFactory        = urlHelperFactory;
 }
        public void Delete(RhspDataID dataID)
        {
            SecurityTemplate securityTemplate = Get(dataID);

            if (!string.IsNullOrEmpty(securityTemplate.Username))
            {
                // Only try to delete the physical rule if the user is specified.
                WindowsUser windowsUser = findWindowsUser(securityTemplate.Username);
                if (windowsUser != null)
                {
                    // Only try to delete when the user is still on the system.
                    deleteFromFileSystem(securityTemplate, windowsUser.Sid);
                }
            }
            HostingConfig.Delete <SecurityTemplate>(dataID);
        }
示例#24
0
        private void processWebsiteHost(WebsiteHost h)
        {
            switch (h.PendingAction)
            {
            case ChildPendingAction.Create:
                HostingConfig.Create(h);
                break;

            case ChildPendingAction.Update:
                HostingConfig.Update(h);
                break;

            case ChildPendingAction.Delete:
                HostingConfig.Delete <WebsiteHost>(h.DataID);
                break;
            }
        }
示例#25
0
        private IEnumerable <TWebsite> getQuery <TWebsite>()
            where TWebsite : Website
        {
            var q = from website in HostingConfig.GetQueryForAllOfType <TWebsite>()
                    join customer in HostingConfig.GetQueryForAllOfType <Customer>()
                    on website.CustomerID equals customer.DataID into customerGroupJoin
                    from joinCustomer in customerGroupJoin.DefaultIfEmpty()
                    join host in HostingConfig.GetQueryForAllOfType <WebsiteHost>()
                    on website.DataID equals host.WebsiteID into hostGroupJoin
                    join dnsZone in HostingConfig.GetQueryForAllOfType <DnsZone>()
                    on website.DataID equals dnsZone.WebsiteID into dnsZoneGroupJoin
                    join security in HostingConfig.GetQueryForAllOfType <SecurityTemplate>()
                    on website.DataID equals security.WebsiteID into securityGroupJoin
                    orderby getVersionBasedPrimaryHostName <TWebsite>(website, hostGroupJoin)
                    select combineWebsite <TWebsite>(
                website,
                joinCustomer,
                hostGroupJoin,
                dnsZoneGroupJoin,
                securityGroupJoin);

            return(q);
        }
示例#26
0
 public void InitRouting(HostingConfig hostingConfig)
 {
 }
        public static PasswordlessLoginBuilder AddOpenIdAuthority(this PasswordlessLoginBuilder builder, IConfiguration configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var hostingConfig = new HostingConfig();

            configuration.Bind(OpenIdAuthorityConstants.ConfigurationSections.Hosting, hostingConfig);
            builder.Services.AddSingleton(hostingConfig);

            var appConfigs = configuration.GetAppConfigs();
            var appService = new DefaultApplicationService(appConfigs);

            builder.Services.TryAddSingleton <IApplicationService>(appService);

            var clients  = AppConfigHelper.GetClientsFromAppConfig(appConfigs);
            var apps     = AppConfigHelper.GetAppsFromClients(clients);
            var appStore = new InMemoryAppStore(apps);

            builder.Services.TryAddSingleton <IAppStore>(appStore);

            var idScopeConfig = configuration.GetSection(OpenIdAuthorityConstants.ConfigurationSections.IdScopes).Get <List <IdScopeConfig> >() ?? new List <IdScopeConfig>();
            var idScopes      = idScopeConfig.Select(x => new IdentityResource(x.Name, x.IncludeClaimTypes)
            {
                Required = x.Required
            }).ToList();

            idScopes.AddRange(new List <IdentityResource>()
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
                new IdentityResources.Email(),
                new IdentityResources.Phone(),
                new IdentityResources.Address(),
            });

            var apiConfigs   = configuration.GetSection(OpenIdAuthorityConstants.ConfigurationSections.Apis).Get <List <ApiConfig> >() ?? new List <ApiConfig>();
            var apiResources = apiConfigs.Select(x => new ApiResource(x.Url, x.IncludeClaimTypes)
            {
                ApiSecrets = x.Secrets?.ToList()?.Select(y => new Secret(y.Sha256())).ToList(),
                Scopes     = x.Scopes?.ToList()?.Select(y => new Scope(y)).ToList()
            }).ToList();

            builder.Services.AddTransient <ISignInService, OpenIdAuthoritySignInService>(); // NOTE: This must replace the service registered by PasswordlessLogin
            builder.Services.TryAddTransient <SimpleIAM.PasswordlessLogin.Services.Password.IReadOnlyPasswordService, SimpleIAM.PasswordlessLogin.Services.Password.DefaultPasswordService>();
            builder.Services.TryAddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();

            builder.Services.AddIdentityServer(options =>
            {
                options.UserInteraction.LoginUrl          = builder.Options.Urls.SignIn;
                options.UserInteraction.LogoutUrl         = builder.Options.Urls.SignOut;
                options.UserInteraction.LogoutIdParameter = OpenIdAuthorityConstants.Configuration.LogoutIdParameter;
                options.UserInteraction.ErrorUrl          = builder.Options.Urls.Error;
                options.Authentication.CookieLifetime     = TimeSpan.FromMinutes(builder.Options.DefaultSessionLengthMinutes);
            })
            .AddDeveloperSigningCredential()     //todo: replace
            .AddInMemoryApiResources(apiResources)
            .AddInMemoryClients(clients)
            .AddProfileService <ProfileService>()
            .AddInMemoryIdentityResources(idScopes);

            builder.Services.AddSingleton <IConfigureOptions <CookieAuthenticationOptions>, ReconfigureCookieOptions>();

            return(builder);
        }
示例#28
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, HostingConfig hostingConfig)
 {
     app.UseHsts();
     app.UseHttpsRedirection();
     app.UseOpenIdAuthority(env, hostingConfig);
 }
示例#29
0
        public static IApplicationBuilder UseOpenIdAuthority(this IApplicationBuilder app, IHostingEnvironment env, HostingConfig hostingConfig)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            hostingConfig = hostingConfig ?? new HostingConfig();

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

            if (hostingConfig.BehindProxy)
            {
                app.UseForwardedHeaders(new ForwardedHeadersOptions
                {
                    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
                });
            }

            // Security
            app.UseXContentTypeOptions();
            app.UseReferrerPolicy(opts => opts.SameOrigin());
            app.UseXXssProtection(options => options.EnabledWithBlockMode());
            app.UseXfo(options => options.Deny());

            app.UseCsp(opts => opts
                       .BlockAllMixedContent()
                       .DefaultSources(s => s.Self())
                       .ScriptSources(s => {
                s.Self();
                var scriptSrcs = (hostingConfig.Csp.ScriptSources ?? new string[] { }).ToList();
                scriptSrcs.Add("sha256-VuNUSJ59bpCpw62HM2JG/hCyGiqoPN3NqGvNXQPU+rY=");
                s.CustomSources(scriptSrcs.ToArray());
            })
                       .StyleSources(s => {
                s.Self();
                s.UnsafeInline();
                if (hostingConfig.Csp.StyleSources != null)
                {
                    s.CustomSources(hostingConfig.Csp.StyleSources);
                }
            })
                       .FontSources(s => {
                s.Self();
                if (hostingConfig.Csp.FontSources != null)
                {
                    s.CustomSources(hostingConfig.Csp.FontSources);
                }
            })
                       .ImageSources(s => {
                s.Self();
                if (hostingConfig.Csp.ImageSources != null)
                {
                    s.CustomSources(hostingConfig.Csp.ImageSources);
                }
            })
                       .FrameAncestors(s => s.None())
                       );
            app.UseMiddleware <SimpleIAM.OpenIdAuthority.Extensions.CspHeaderOverridesMiddleware>();

            var compositeFileProvider = new CompositeFileProvider(
                new EmbeddedFileProvider(typeof(OpenIdAuthorityApplicationBuilderExtensions).GetTypeInfo().Assembly, "SimpleIAM.OpenIdAuthority.wwwroot"),
                env.WebRootFileProvider
                );

            env.WebRootFileProvider = compositeFileProvider;

            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = compositeFileProvider
            });

            app.UseIdentityServer();

            app.UseMvc();

            return(app);
        }
示例#30
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="hostingConfig">Hosting config</param>
 /// <param name="httpContextAccessor">HTTP context accessor</param>
 public WebHelper(HostingConfig hostingConfig, IHttpContextAccessor httpContextAccessor)
 {
     this._hostingConfig       = hostingConfig;
     this._httpContextAccessor = httpContextAccessor;
 }