public void Configure(IAppHost appHost) { var AppSettings = appHost.AppSettings; appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(), new IAuthProvider[] { new CredentialsAuthProvider(AppSettings), //Enable UserName/Password Credentials Auth new JwtAuthProvider(AppSettings) { RequireSecureConnection = false, AuthKey = AesUtils.CreateKey(), //Transient Auth Key }, })); appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service //override the default registration validation with your own custom implementation appHost.RegisterAs <CustomRegistrationValidator, IValidator <Register> >(); appHost.Register <ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory appHost.Register <IAuthRepository>(new InMemoryAuthRepository()); //Store Authenticated Users in Memory CreateUser(appHost, "*****@*****.**", "Admin User", "p@55wOrd", roles: new[] { RoleNames.Admin }); }
public void Register(IAppHost appHost) { appHost.RegisterService <RequestLogsService>(AtRestPath); var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity); requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableRequestBodyTracking = EnableRequestBodyTracking; requestLogger.SkipLogging = SkipLogging; requestLogger.RequiredRoles = RequiredRoles; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes; requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes; appHost.Register(requestLogger); if (EnableRequestBodyTracking) { appHost.PreRequestFilters.Insert(0, (httpReq, httpRes) => { httpReq.UseBufferedStream = EnableRequestBodyTracking; }); } appHost.GetPlugin <MetadataFeature>() .AddDebugLink(AtRestPath, "Request Logs"); }
public void Register(IAppHost appHost) { DebugMode = appHost.Config.DebugMode; VirtualFileSources = appHost.VirtualFileSources; appHost.Register(TemplatePages); appHost.CatchAllHandlers.Add(RequestHandler); }
public void Configure(IAppHost appHost) { var AppSettings = appHost.AppSettings; appHost.Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { //new BasicAuthProvider(), //Sign-in with HTTP Basic Auth new JwtAuthProvider(AppSettings) { AuthKey = AesUtils.CreateKey(), RequireSecureConnection = false, }, new CredentialsAuthProvider(), //HTML Form post of UserName/Password credentials new FacebookAuthProvider(AppSettings), new TwitterAuthProvider(AppSettings), })); appHost.Plugins.Add(new RegistrationFeature()); var userRep = new InMemoryAuthRepository(); appHost.Register <IAuthRepository>(userRep); var authRepo = userRep; var newAdmin = new UserAuth { Email = "*****@*****.**", DisplayName = "Admin User" }; var user = authRepo.CreateUserAuth(newAdmin, "p@55wOrd"); authRepo.AssignRoles(user, new List <string> { "Admin" }); }
public void Register(IAppHost appHost) { appHost.Register<INativeTypesMetadata>( new NativeTypesMetadata(appHost.Metadata, MetadataTypesConfig)); appHost.RegisterService<NativeTypesService>(); }
public void Register(IAppHost appHost) { AuthenticateService.Init(sessionFactory, authProviders); AuthenticateService.HtmlRedirect = HtmlRedirect; var unitTest = appHost == null; if (unitTest) { return; } foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } var sessionFeature = RegisterPlugins.OfType <SessionFeature>().First(); sessionFeature.SessionExpiry = SessionExpiry; sessionFeature.PermanentSessionExpiry = PermanentSessionExpiry; appHost.LoadPlugin(RegisterPlugins.ToArray()); if (IncludeAuthMetadataProvider && appHost.TryResolve <IAuthMetadataProvider>() == null) { appHost.Register <IAuthMetadataProvider>(new AuthMetadataProvider()); } authProviders.OfType <IAuthPlugin>().Each(x => x.Register(appHost, this)); }
public void Register(IAppHost appHost) { appHost.RegisterService <RequestLogsService>(AtRestPath); var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity); requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableRequestBodyTracking = EnableRequestBodyTracking; requestLogger.LimitToServiceRequests = LimitToServiceRequests; requestLogger.SkipLogging = SkipLogging; requestLogger.RequiredRoles = RequiredRoles; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes; requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes; appHost.Register(requestLogger); if (EnableRequestBodyTracking) { appHost.PreRequestFilters.Insert(0, (httpReq, httpRes) => { httpReq.UseBufferedStream = EnableRequestBodyTracking; }); } appHost.GetPlugin <MetadataFeature>() ?.AddLink(MetadataFeature.DebugInfo, AtRestPath.TrimStart('/'), "Request Logs"); appHost.GetPlugin <MetadataFeature>() ?.AddLink(MetadataFeature.AvailableFeatures, "http://docs.servicestack.net/request-logger", "Request Logger"); }
public void Register(IAppHost appHost) { hasRegistered = true; AuthenticateService.Init(sessionFactory, AuthProviders); var unitTest = appHost == null; if (unitTest) { return; } if (HostContext.StrictMode) { var sessionInstance = sessionFactory(); if (TypeSerializer.HasCircularReferences(sessionInstance)) { throw new StrictModeException($"User Session {sessionInstance.GetType().Name} cannot have circular dependencies", "sessionFactory", StrictModeCodes.CyclicalUserSession); } } foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } var sessionFeature = RegisterPlugins.OfType <SessionFeature>().First(); sessionFeature.SessionExpiry = SessionExpiry; sessionFeature.PermanentSessionExpiry = PermanentSessionExpiry; appHost.LoadPlugin(RegisterPlugins.ToArray()); if (IncludeAuthMetadataProvider && appHost.TryResolve <IAuthMetadataProvider>() == null) { appHost.Register <IAuthMetadataProvider>(new AuthMetadataProvider()); } AuthProviders.OfType <IAuthPlugin>().Each(x => x.Register(appHost, this)); AuthenticateService.HtmlRedirect = HtmlRedirect; AuthenticateService.HtmlRedirectAccessDenied = HtmlRedirectAccessDenied; AuthenticateService.HtmlRedirectReturnParam = HtmlRedirectReturnParam; AuthenticateService.HtmlRedirectReturnPathOnly = HtmlRedirectReturnPathOnly; AuthenticateService.AuthResponseDecorator = AuthResponseDecorator; if (ValidateFn != null) { AuthenticateService.ValidateFn = ValidateFn; } var authNavItems = AuthProviders.Select(x => (x as AuthProvider)?.NavItem).Where(x => x != null); if (!ViewUtils.NavItemsMap.TryGetValue("auth", out var navItems)) { ViewUtils.NavItemsMap["auth"] = navItems = new List <NavItem>(); } navItems.AddRange(authNavItems); }
public void Register(IAppHost appHost) { appHost.Register <INativeTypesMetadata>( new NativeTypesMetadata(appHost.Metadata, MetadataTypesConfig)); appHost.RegisterService <NativeTypesService>(); }
/// <summary> /// Activate the validation mechanism, so every request DTO with an existing validator /// will be validated. /// </summary> /// <param name="appHost">The app host</param> public void Register(IAppHost appHost) { if (TreatInfoAndWarningsAsErrors) { if (!appHost.GlobalRequestFiltersAsync.Contains(ValidationFilters.RequestFilterAsync)) { appHost.GlobalRequestFiltersAsync.Add(ValidationFilters.RequestFilterAsync); } if (!appHost.GlobalMessageRequestFiltersAsync.Contains(ValidationFilters.RequestFilterAsync)) { appHost.GlobalMessageRequestFiltersAsync.Add(ValidationFilters.RequestFilterAsync); } } else { if (!appHost.GlobalRequestFiltersAsync.Contains(ValidationFilters.RequestFilterAsyncIgnoreWarningsInfo)) { appHost.GlobalRequestFiltersAsync.Add(ValidationFilters.RequestFilterAsyncIgnoreWarningsInfo); } if (!appHost.GlobalMessageRequestFiltersAsync.Contains(ValidationFilters.RequestFilterAsyncIgnoreWarningsInfo)) { appHost.GlobalMessageRequestFiltersAsync.Add(ValidationFilters.RequestFilterAsyncIgnoreWarningsInfo); } if (!appHost.GlobalResponseFiltersAsync.Contains(ValidationFilters.ResponseFilterAsync)) { appHost.GlobalResponseFiltersAsync.Add(ValidationFilters.ResponseFilterAsync); } if (!appHost.GlobalMessageResponseFiltersAsync.Contains(ValidationFilters.ResponseFilterAsync)) { appHost.GlobalMessageResponseFiltersAsync.Add(ValidationFilters.ResponseFilterAsync); } } if (ValidationSource != null) { appHost.Register(ValidationSource); ValidationSource.InitSchema(); } var container = appHost.GetContainer(); var hasValidationSource = ValidationSource != null || container.Exists <IValidationSource>(); if (hasValidationSource && AccessRole != null) { foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } } if (ScanAppHostAssemblies) { container.RegisterValidators(((ServiceStackHost)appHost).ServiceAssemblies.ToArray()); } }
private void RegisterService(IAppHost host) { ServiceDiscovery = Settings.GetDiscoveryClient() ?? new ConsulDiscovery(); ServiceDiscovery.Register(host); // register servicestack discovery services host.Register(ServiceDiscovery); }
public void Register(IAppHost appHost) { appHost.RegisterService<RequestLogsService>(AtRestPath); appHost.Register(RequestLogger ?? new InMemoryRollingRequestLogger(Capacity) { HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes }); }
public void Register(IAppHost appHost) { VaultUri.ThrowIfNullOrEmpty(nameof(VaultUri)); var vaultAuth = GetVaultAuth(); var vaultClient = new VaultClient(vaultAuth, VaultUri, VaultCertificate); appHost.Register <IClientSecretStore>(new VaultClientSecretStore(this, vaultClient)); }
public void Register(IAppHost appHost) { appHost.Register <IAddressValidator>(new AddressValidator()); appHost.Register <IDateStringValidator>(new DateStringValidator(appHost.AppSettings)); appHost.Register <IFullNameValidator>(new FullNameValidator()); appHost.Register <IPasswordValidator>(new PasswordValidator()); appHost.Register <IPhoneValidator>(new PhoneValidator(appHost.AppSettings)); appHost.Register <ITimeStringValidator>(new TimeStringValidator(appHost.AppSettings)); appHost.Register <IUserNameValidator>(new UserNameValidator()); appHost.Register <ICustomEmailValidator>(new CustomEmailValidator()); }
public void Register(IAppHost appHost) { var nativeTypesMeta = new NativeTypesMetadata(appHost.Metadata, MetadataTypesConfig); appHost.Register <INativeTypesMetadata>(nativeTypesMeta); DefaultGenerator = nativeTypesMeta.GetGenerator(); appHost.RegisterService <NativeTypesService>(); }
public void AfterPluginsLoaded(IAppHost appHost) { // Check if an IServiceGatewayFactory has been registered var factory = appHost.TryResolve <IServiceGatewayFactory>(); if (factory is ServiceGatewayFactoryBase factoryBase) { appHost.Register <IServiceGatewayFactory>(new ServiceGatewayFactoryBaseDecorator(HeaderName, factoryBase)); } }
private void RegisterService(IAppHost host) { ServiceDiscovery = Settings.GetDiscoveryClient() ?? new ConsulDiscovery(); ServiceDiscovery.Register(host); // register servicestack discovery services host.Register(ServiceDiscovery); host.GetContainer() .Register <IServiceGatewayFactory>(x => new ConsulServiceGatewayFactory(Settings.GetGateway(), ServiceDiscovery)) .ReusedWithin(ReuseScope.None); }
public void Register(IAppHost appHost) { if (!string.IsNullOrEmpty(AtRestPath)) { appHost.RegisterService <RequestLogsService>(AtRestPath); } var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity); requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableRequestBodyTracking = EnableRequestBodyTracking; requestLogger.LimitToServiceRequests = LimitToServiceRequests; requestLogger.SkipLogging = SkipLogging; requestLogger.RequiredRoles = RequiredRoles; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes; requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes; requestLogger.RequestLogFilter = RequestLogFilter; requestLogger.IgnoreFilter = IgnoreFilter; requestLogger.CurrentDateFn = CurrentDateFn; appHost.Register(requestLogger); if (EnableRequestBodyTracking) { appHost.PreRequestFilters.Insert(0, (httpReq, httpRes) => { #if NETCORE // https://forums.servicestack.net/t/unexpected-end-of-stream-when-uploading-to-aspnet-core/6478/6 if (httpReq.ContentType.MatchesContentType(MimeTypes.MultiPartFormData)) { return; } #endif httpReq.UseBufferedStream = EnableRequestBodyTracking; }); } appHost.ConfigurePlugin <MetadataFeature>( feature => feature.AddDebugLink(AtRestPath, "Request Logs")); appHost.GetPlugin <MetadataFeature>()?.ExportTypes.Add(typeof(RequestLogEntry)); appHost.AddToAppMetadata(meta => { meta.Plugins.RequestLogs = new RequestLogsInfo { RequiredRoles = RequiredRoles, ServiceRoutes = new Dictionary <string, string[]> { { nameof(RequestLogsService), new[] { AtRestPath } }, }, RequestLogger = requestLogger.GetType().Name, }; }); }
private void RegisterService(IAppHost host) { ServiceDiscovery = Settings.GetDiscoveryClient() ?? new ConsulDiscovery(); ServiceDiscovery.Register(host); // register servicestack discovery services host.Register(ServiceDiscovery); host.GetContainer() .Register<IServiceGatewayFactory>(x => new ConsulServiceGatewayFactory(Settings.GetGateway(), ServiceDiscovery)) .ReusedWithin(ReuseScope.None); }
private void ConfigureRequestLogger(IAppHost appHost) { var requestLogger = Logger; requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableRequestBodyTracking = EnableRequestBodyTracking; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes.ToArray(); requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes.ToArray(); appHost.Register(requestLogger); }
public void Register(IAppHost appHost) { //Pre init process // Dependency var container = appHost.GetContainer(); var appSettings = appHost.AppSettings; //Register all Authentication methods you want to enable for this web app. appHost.Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new ApiKeyAuthProvider(appSettings), new CredentialsAuthProvider() { SessionExpiry = new TimeSpan(0, 30, 0) }, //Sign-in with UserName/Password credentials new BasicAuthProvider() { SessionExpiry = new TimeSpan(0, 30, 0) }, //Sign-in with HTTP Basic Auth } ) { IncludeAssignRoleServices = true, MaxLoginAttempts = 5, ServiceRoutes = new Dictionary <Type, string[]> { { typeof(AuthenticateService), new[] { "/auth", "/auth/{provider}" } }, }, GenerateNewSessionCookiesOnAuthentication = true, DeleteSessionCookiesOnLogout = true, IncludeAuthMetadataProvider = false }); //Store User Data into the referenced SQl server var repo = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>()) { UseDistinctRoleTables = true }; container.Register <IAuthRepository>(c => repo); container.Register <IUserAuthRepository>(c => repo); repo.InitSchema(); //Custom validators appHost.Register <IValidator <CreateUser> >(new CreateUserValidator()); //Custom services appHost.RegisterService <UserService>(); }
public void Register(IAppHost appHost) { appHost.RegisterService <RequestLogsService>(AtRestPath); var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity); requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.RequiredRoles = RequiredRoles; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes; requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes; appHost.Register(requestLogger); }
public void Register(IAppHost appHost) { SessionFeature.DefaultSessionFactory = sessionFactory; AuthenticateService.Init(authProviders); var unitTest = appHost == null; if (unitTest) { return; } if (appHost.Config.StrictMode.GetValueOrDefault()) { var sessionInstance = sessionFactory(); if (TypeSerializer.HasCircularReferences(sessionInstance)) { throw new StrictModeException($"User Session {sessionInstance.GetType().Name} cannot have circular dependencies", "sessionFactory", StrictModeCodes.CyclicalUserSession); } } foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } var sessionFeature = RegisterPlugins.OfType <SessionFeature>().First(); sessionFeature.SessionExpiry = SessionExpiry; sessionFeature.PermanentSessionExpiry = PermanentSessionExpiry; appHost.LoadPlugin(RegisterPlugins.ToArray()); if (IncludeAuthMetadataProvider && appHost.TryResolve <IAuthMetadataProvider>() == null) { appHost.Register <IAuthMetadataProvider>(new AuthMetadataProvider()); } authProviders.OfType <IAuthPlugin>().Each(x => x.Register(appHost, this)); AuthenticateService.HtmlRedirect = HtmlRedirect; AuthenticateService.AuthResponseDecorator = AuthResponseDecorator; appHost.GetPlugin <MetadataFeature>() ?.AddLink(MetadataFeature.AvailableFeatures, "http://docs.servicestack.net/authentication-and-authorization", nameof(AuthFeature)); }
public void Register(IAppHost appHost) { var traceFilter = new UrlTraceFilter(); appHost.GlobalRequestFilters.Add(RequestFilters); appHost.OnEndRequestCallbacks.Add(EndRequest); _processor = new ServiceStackClientDiagnosticProcessor() { Filter = traceFilter }; JsonServiceClient.GlobalRequestFilter += _processor.OnBegRequest; JsonServiceClient.GlobalResponseFilter += _processor.OnEndRequest; appHost.Register(traceFilter); _skyWalkingStartup = new SkyWalkingStartup(); _skyWalkingStartup.Start(); }
public void Register(IAppHost appHost) { hasRegistered = true; AuthenticateService.Init(sessionFactory, authProviders); var unitTest = appHost == null; if (unitTest) { return; } if (HostContext.StrictMode) { var sessionInstance = sessionFactory(); if (TypeSerializer.HasCircularReferences(sessionInstance)) { throw new StrictModeException($"User Session {sessionInstance.GetType().Name} cannot have circular dependencies", "sessionFactory", StrictModeCodes.CyclicalUserSession); } } foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } var sessionFeature = RegisterPlugins.OfType <SessionFeature>().First(); sessionFeature.SessionExpiry = SessionExpiry; sessionFeature.PermanentSessionExpiry = PermanentSessionExpiry; appHost.LoadPlugin(RegisterPlugins.ToArray()); if (IncludeAuthMetadataProvider && appHost.TryResolve <IAuthMetadataProvider>() == null) { appHost.Register <IAuthMetadataProvider>(new AuthMetadataProvider()); } authProviders.OfType <IAuthPlugin>().Each(x => x.Register(appHost, this)); AuthenticateService.HtmlRedirect = HtmlRedirect; AuthenticateService.HtmlRedirectReturnParam = HtmlRedirectReturnParam; AuthenticateService.HtmlRedirectReturnPathOnly = HtmlRedirectReturnPathOnly; AuthenticateService.AuthResponseDecorator = AuthResponseDecorator; }
public void Register(IAppHost appHost) { appHost.RegisterService <RequestLogsService>(AtRestPath); var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity); requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableRequestBodyTracking = EnableRequestBodyTracking; requestLogger.LimitToServiceRequests = LimitToServiceRequests; requestLogger.SkipLogging = SkipLogging; requestLogger.RequiredRoles = RequiredRoles; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes; requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes; requestLogger.RequestLogFilter = RequestLogFilter; requestLogger.CurrentDateFn = CurrentDateFn; appHost.Register(requestLogger); if (EnableRequestBodyTracking) { appHost.PreRequestFilters.Insert(0, (httpReq, httpRes) => { #if NETSTANDARD2_0 // https://forums.servicestack.net/t/unexpected-end-of-stream-when-uploading-to-aspnet-core/6478/6 if (httpReq.ContentType.MatchesContentType(MimeTypes.MultiPartFormData)) { return; } #endif httpReq.UseBufferedStream = EnableRequestBodyTracking; }); } appHost.GetPlugin <MetadataFeature>() .AddDebugLink(AtRestPath, "Request Logs"); }
public void Register(IAppHost appHost) { AuthenticateService.Init(sessionFactory, authProviders); AuthenticateService.HtmlRedirect = HtmlRedirect; var unitTest = appHost == null; if (unitTest) { return; } foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } appHost.LoadPlugin(RegisterPlugins.ToArray()); if (IncludeAuthMetadataProvider && appHost.TryResolve <IAuthMetadataProvider>() == null) { appHost.Register <IAuthMetadataProvider>(new AuthMetadataProvider()); } }
public override void Register(IAppHost appHost) { base.Register(appHost); appHost.Register((Templates.ITemplatePages)Pages); appHost.Register(this); }
public void Register(IAppHost appHost) { appHost.RegisterService<RequestLogsService>(AtRestPath); var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity); requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableRequestBodyTracking = EnableRequestBodyTracking; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.RequiredRoles = RequiredRoles; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes; requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes; appHost.Register(requestLogger); if (EnableRequestBodyTracking) { appHost.PreRequestFilters.Insert(0, (httpReq, httpRes) => { httpReq.UseBufferedStream = EnableRequestBodyTracking; }); } }
public void Register(IAppHost appHost) { AuthenticateService.Init(sessionFactory, authProviders); AuthenticateService.HtmlRedirect = HtmlRedirect; var unitTest = appHost == null; if (unitTest) return; foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } var sessionFeature = RegisterPlugins.OfType<SessionFeature>().First(); sessionFeature.SessionExpiry = SessionExpiry; sessionFeature.PermanentSessionExpiry = PermanentSessionExpiry; appHost.LoadPlugin(RegisterPlugins.ToArray()); if (IncludeAuthMetadataProvider && appHost.TryResolve<IAuthMetadataProvider>() == null) appHost.Register<IAuthMetadataProvider>(new AuthMetadataProvider()); }
/// <summary> /// Activate the validation mechanism, so every request DTO with an existing validator /// will be validated. /// </summary> /// <param name="appHost">The app host</param> public void Register(IAppHost appHost) { if (TreatInfoAndWarningsAsErrors) { if (!appHost.GlobalRequestFiltersAsync.Contains(ValidationFilters.RequestFilterAsync)) { appHost.GlobalRequestFiltersAsync.Add(ValidationFilters.RequestFilterAsync); } if (!appHost.GlobalMessageRequestFiltersAsync.Contains(ValidationFilters.RequestFilterAsync)) { appHost.GlobalMessageRequestFiltersAsync.Add(ValidationFilters.RequestFilterAsync); } } else { if (!appHost.GlobalRequestFiltersAsync.Contains(ValidationFilters.RequestFilterAsyncIgnoreWarningsInfo)) { appHost.GlobalRequestFiltersAsync.Add(ValidationFilters.RequestFilterAsyncIgnoreWarningsInfo); } if (!appHost.GlobalMessageRequestFiltersAsync.Contains(ValidationFilters.RequestFilterAsyncIgnoreWarningsInfo)) { appHost.GlobalMessageRequestFiltersAsync.Add(ValidationFilters.RequestFilterAsyncIgnoreWarningsInfo); } if (!appHost.GlobalResponseFiltersAsync.Contains(ValidationFilters.ResponseFilterAsync)) { appHost.GlobalResponseFiltersAsync.Add(ValidationFilters.ResponseFilterAsync); } if (!appHost.GlobalMessageResponseFiltersAsync.Contains(ValidationFilters.ResponseFilterAsync)) { appHost.GlobalMessageResponseFiltersAsync.Add(ValidationFilters.ResponseFilterAsync); } } if (ValidationSource != null) { appHost.Register(ValidationSource); ValidationSource.InitSchema(); } var container = appHost.GetContainer(); var hasValidationSource = ValidationSource != null || container.Exists <IValidationSource>(); if (hasValidationSource && AccessRole != null) { appHost.RegisterServices(ServiceRoutes); } if (ScanAppHostAssemblies) { container.RegisterValidators(((ServiceStackHost)appHost).ServiceAssemblies.ToArray()); } appHost.AddToAppMetadata(metadata => { metadata.Plugins.Validation = new ValidationInfo { HasValidationSource = hasValidationSource.NullIfFalse(), HasValidationSourceAdmin = (container.TryResolve <IValidationSource>() is IValidationSourceAdmin).NullIfFalse(), ServiceRoutes = ServiceRoutes.ToMetadataServiceRoutes(), TypeValidators = !EnableDeclarativeValidation ? null : appHost.ScriptContext.ScriptMethods.SelectMany(x => ScriptMethodInfo.GetScriptMethods(x.GetType(), where : mi => typeof(ITypeValidator).IsAssignableFrom(mi.ReturnType))) .Map(x => x.ToScriptMethodType()), PropertyValidators = !EnableDeclarativeValidation ? null : appHost.ScriptContext.ScriptMethods.SelectMany(x => ScriptMethodInfo.GetScriptMethods(x.GetType(), where : mi => typeof(IPropertyValidator).IsAssignableFrom(mi.ReturnType))) .Map(x => x.ToScriptMethodType()), AccessRole = AccessRole, }; }); appHost.GetPlugin <MetadataFeature>()?.ExportTypes.Add(typeof(ValidationRule)); }
public void Register(IAppHost appHost) { appHost.RegisterService<RequestLogsService>(AtRestPath); var requestLogger = RequestLogger ?? new InMemoryRollingRequestLogger(Capacity); requestLogger.EnableSessionTracking = EnableSessionTracking; requestLogger.EnableResponseTracking = EnableResponseTracking; requestLogger.EnableErrorTracking = EnableErrorTracking; requestLogger.RequiresRole = RequiresRole; requestLogger.ExcludeRequestDtoTypes = ExcludeRequestDtoTypes; requestLogger.HideRequestBodyForRequestDtoTypes = HideRequestBodyForRequestDtoTypes; appHost.Register(requestLogger); }
public void Register(IAppHost appHost) { AuthenticateService.Init(sessionFactory, authProviders); AuthenticateService.HtmlRedirect = HtmlRedirect; var unitTest = appHost == null; if (unitTest) return; foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } RegisterPlugins.ForEach(x => appHost.LoadPlugin(x)); if (IncludeAuthMetadataProvider && appHost.TryResolve<IAuthMetadataProvider>() == null) appHost.Register<IAuthMetadataProvider>(new AuthMetadataProvider()); }
public void Register(IAppHost appHost) { hasRegistered = true; AuthenticateService.Init(sessionFactory, AuthProviders); var unitTest = appHost == null; if (unitTest) { return; } if (HostContext.StrictMode) { var sessionInstance = sessionFactory(); if (TypeSerializer.HasCircularReferences(sessionInstance)) { throw new StrictModeException($"User Session {sessionInstance.GetType().Name} cannot have circular dependencies", "sessionFactory", StrictModeCodes.CyclicalUserSession); } } appHost.RegisterServices(ServiceRoutes); var sessionFeature = RegisterPlugins.OfType <SessionFeature>().First(); sessionFeature.SessionExpiry = SessionExpiry; sessionFeature.PermanentSessionExpiry = PermanentSessionExpiry; appHost.LoadPlugin(RegisterPlugins.ToArray()); if (IncludeAuthMetadataProvider && appHost.TryResolve <IAuthMetadataProvider>() == null) { appHost.Register <IAuthMetadataProvider>(new AuthMetadataProvider()); } AuthProviders.OfType <IAuthPlugin>().Each(x => x.Register(appHost, this)); AuthenticateService.HtmlRedirect = HtmlRedirect; AuthenticateService.HtmlRedirectAccessDenied = HtmlRedirectAccessDenied; AuthenticateService.HtmlRedirectReturnParam = HtmlRedirectReturnParam; AuthenticateService.HtmlRedirectReturnPathOnly = HtmlRedirectReturnPathOnly; AuthenticateService.AuthResponseDecorator = AuthResponseDecorator; if (ValidateFn != null) { AuthenticateService.ValidateFn = ValidateFn; } var authNavItems = AuthProviders.Select(x => (x as AuthProvider)?.NavItem).Where(x => x != null); if (!ViewUtils.NavItemsMap.TryGetValue("auth", out var navItems)) { ViewUtils.NavItemsMap["auth"] = navItems = new List <NavItem>(); } var isDefaultHtmlRedirect = HtmlRedirect == "~/" + LocalizedStrings.Login.Localize(); if (IncludeDefaultLogin && isDefaultHtmlRedirect && !appHost.VirtualFileSources.FileExists("/login.html")) { appHost.VirtualFileSources.GetMemoryVirtualFiles().WriteFile("/login.html", Templates.HtmlTemplates.GetLoginTemplate()); } navItems.AddRange(authNavItems); appHost.AddToAppMetadata(meta => { meta.Plugins.Auth = new AuthInfo { HasAuthSecret = (appHost.Config.AdminAuthSecret != null).NullIfFalse(), HasAuthRepository = appHost.GetContainer().Exists <IAuthRepository>().NullIfFalse(), IncludesRoles = IncludeRolesInAuthenticateResponse.NullIfFalse(), IncludesOAuthTokens = IncludeOAuthTokensInAuthenticateResponse.NullIfFalse(), HtmlRedirect = HtmlRedirect?.TrimStart('~'), AuthProviders = AuthenticateService.GetAuthProviders().Map(x => new MetaAuthProvider { Type = x.Type, Name = x.Provider, NavItem = (x as AuthProvider)?.NavItem, Meta = x.Meta, }) }; }); }
public static void ReloadCsv <T>(this IAppHost appHost) { appHost.Register <List <T> >($"wwwroot/data/{typeof(T).Name.ToLower()}s.csv" .MapHostAbsolutePath() .ReadAllText().FromCsv <List <T> >()); }