/// <summary> /// /// </summary> /// <param name="appHost"></param> public void Register(IAppHost appHost) { var inMemoryProvider = new RecursiveInMemoryVirtualPathProvider(appHost); // Create a "Views" directory for dumping all our discovered views in var viewsDir = new InMemoryVirtualDirectory(inMemoryProvider, inMemoryProvider.rootDirectory) { DirName = "Views", files = new List <InMemoryVirtualFile>(), dirs = new List <InMemoryVirtualDirectory>() }; inMemoryProvider.rootDirectory.dirs.Add(viewsDir); foreach (var asm in _assemblies) { foreach (string resource in asm.GetManifestResourceNames()) { // Get just the file name. Internally, ServiceStack dumps all these in a giant "/Views" directory anyway, so let's just do that. string path = string.Join(".", resource.Split('.').Reverse().Take(2).Reverse()); viewsDir.AddFile(path, new StreamReader(asm.GetManifestResourceStream(resource)).ReadToEnd()); } } var razorPlugin = new RazorFormat { VirtualPathProvider = inMemoryProvider, EnableLiveReload = false }; appHost.LoadPlugin(razorPlugin); }
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 virtual void Register(IAppHost appHost) { ValidateCallbackRequirements(appHost); clientSecretStore = () => appHost.TryResolve <IClientSecretStore>() ?? new DefaultClientSecretStore(appSettings); var provider = ProviderFactory(); appHost.LoadPlugin( new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { provider }, GetProviderLoginUrl(appHost)) ); if (defaultServiceClient == null) { return; } appHost.GetContainer().Register <IServiceClient>(defaultServiceClient); appHost.GlobalRequestFilters.Add(ImpersonateServiceClient); }
/// <summary> /// /// </summary> /// <param name="appHost"></param> public void Register(IAppHost appHost) { var inMemoryProvider = new RecursiveInMemoryVirtualPathProvider(appHost); // Create a "Views" directory for dumping all our discovered views in var viewsDir = new InMemoryVirtualDirectory(inMemoryProvider, inMemoryProvider.rootDirectory) { DirName = "Views", files = new List<InMemoryVirtualFile>(), dirs = new List<InMemoryVirtualDirectory>() }; inMemoryProvider.rootDirectory.dirs.Add(viewsDir); foreach (var asm in _assemblies) { foreach (string resource in asm.GetManifestResourceNames()) { // Get just the file name. Internally, ServiceStack dumps all these in a giant "/Views" directory anyway, so let's just do that. string path = string.Join(".", resource.Split('.').Reverse().Take(2).Reverse()); viewsDir.AddFile(path, new StreamReader(asm.GetManifestResourceStream(resource)).ReadToEnd()); } } var razorPlugin = new RazorFormat { VirtualPathProvider = inMemoryProvider, EnableLiveReload = false }; appHost.LoadPlugin(razorPlugin); }
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)); }
} //User-defined configuration public void Register(IAppHost appHost) { //Register Services exposed by this module appHost.RegisterService <AuthService>("/auth", "/auth/{provider}"); appHost.RegisterService <AssignRolesService>("/assignroles"); appHost.RegisterService <UnAssignRolesService>("/unassignroles"); //Load dependent plugins appHost.LoadPlugin(new SessionFeature()); }
public void Register(IAppHost appHost) { foreach (var entry in ImplicitConventions) { var key = entry.Key.Trim('%'); var fmt = entry.Value; var query = new QueryDbFieldAttribute { Template = fmt }.Init(); if (entry.Key.EndsWith("%")) { StartsWithConventions[key] = query; } if (entry.Key.StartsWith("%")) { EndsWithConventions[key] = query; } } appHost.GetContainer().Register <IAutoQuery>(c => new AutoQuery { IgnoreProperties = IgnoreProperties, IllegalSqlFragmentTokens = IllegalSqlFragmentTokens, MaxLimit = MaxLimit, EnableUntypedQueries = EnableUntypedQueries, EnableSqlFilters = EnableRawSqlFilters, OrderByPrimaryKeyOnLimitQuery = OrderByPrimaryKeyOnPagedQuery, QueryFilters = QueryFilters, ResponseFilters = ResponseFilters, StartsWithConventions = StartsWithConventions, EndsWithConventions = EndsWithConventions, UseNamedConnection = UseNamedConnection, }) .ReusedWithin(ReuseScope.None); appHost.Metadata.GetOperationAssemblies() .Each(x => LoadFromAssemblies.Add(x)); ((ServiceStackHost)appHost).ServiceAssemblies.Each(x => { if (!LoadFromAssemblies.Contains(x)) { LoadFromAssemblies.Add(x); } }); if (EnableAutoQueryViewer && appHost.GetPlugin <AutoQueryMetadataFeature>() == null) { appHost.LoadPlugin(new AutoQueryMetadataFeature { MaxLimit = MaxLimit }); } }
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)); }
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) { 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) { AuthService.Init(sessionFactory, authProviders); var unitTest = appHost == null; if (unitTest) { return; } foreach (var registerService in ServiceRoutes) { appHost.RegisterService(registerService.Key, registerService.Value); } RegisterPlugins.ForEach(x => appHost.LoadPlugin(x)); }
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 void Register(IAppHost appHost) { if (StripUpperInLike) { if (ImplicitConventions.TryGetValue("%Like%", out var convention) && convention == CaseInsensitiveLikeFormat) { ImplicitConventions["%Like%"] = CaseSensitiveLikeFormat; } foreach (var attr in EndsWithConventions) { if (attr.Value.Template == CaseInsensitiveLikeFormat) { attr.Value.Template = CaseSensitiveLikeFormat; } } } foreach (var entry in ImplicitConventions) { var key = entry.Key.Trim('%'); var fmt = entry.Value; var query = new QueryDbFieldAttribute { Template = fmt }.Init(); if (entry.Key.EndsWith("%")) { StartsWithConventions[key] = query; } if (entry.Key.StartsWith("%")) { EndsWithConventions[key] = query; } } appHost.GetContainer().Register <IAutoQueryDb>(c => new AutoQuery { IgnoreProperties = IgnoreProperties, IllegalSqlFragmentTokens = IllegalSqlFragmentTokens, MaxLimit = MaxLimit, IncludeTotal = IncludeTotal, EnableUntypedQueries = EnableUntypedQueries, EnableSqlFilters = EnableRawSqlFilters, OrderByPrimaryKeyOnLimitQuery = OrderByPrimaryKeyOnPagedQuery, QueryFilters = QueryFilters, ResponseFilters = ResponseFilters, StartsWithConventions = StartsWithConventions, EndsWithConventions = EndsWithConventions, UseNamedConnection = UseNamedConnection, }) .ReusedWithin(ReuseScope.None); appHost.Metadata.GetOperationAssemblies() .Each(x => LoadFromAssemblies.Add(x)); appHost.ServiceAssemblies.Each(x => { if (!LoadFromAssemblies.Contains(x)) { LoadFromAssemblies.Add(x); } }); if (EnableAutoQueryViewer && appHost.GetPlugin <AutoQueryMetadataFeature>() == null) { appHost.LoadPlugin(new AutoQueryMetadataFeature { MaxLimit = MaxLimit }); } appHost.GetPlugin <MetadataFeature>() ?.AddLink(MetadataFeature.AvailableFeatures, "http://docs.servicestack.net/autoquery", nameof(AutoQueryFeature)); }
public void Register(IAppHost appHost) { appHost.LoadPlugin(new ValidationFeature()); appHost.GetContainer().RegisterValidators(typeof(TTFPlugin).Assembly); appHost.RegisterAs <MappingAlgorithmFactory, IMappingAlgorithmFactory>(); }
public void Register(IAppHost appHost) { appHost.RegisterService <SseService>(); appHost.LoadPlugin(new SessionFeature()); }
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 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()); }
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()); }