public static string ResolveLayoutPath(string path, File file) { if (path.StartsWith("~") || path.StartsWith("/")) { path = HttpContext.Current.Server.MapPath(path); } else if (file != null) { path = file.RootedPath.Substring(0, file.RootedPath.LastIndexOf("\\")) + "\\" + path; } else { path = HttpContext.Current.Server.MapPath(RebelSettings.GetSettings().RebelFolders.TemplateFolder) + "\\" + path; } return(path); }
/// <summary> /// Authenticates the request by reading the FormsAuthentication cookie and setting the /// context and thread principle object /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void AuthenticateRequest(object sender, EventArgs e) { var app = (HttpApplication)sender; var http = new HttpContextWrapper(app.Context); //we need to determine if the path being requested is an rebel path, if not don't do anything var settings = RebelSettings.GetSettings(); var backOfficeRoutePath = string.Concat(settings.RebelPaths.BackOfficePath, "/"); var installerRoutePath = string.Concat("Install", "/"); //Retreive Route Url var routeUrl = ""; var routeData = RouteTable.Routes.GetRouteData(http); if (routeData != null) { var route = routeData.Route as Route; if (route != null) { routeUrl = route.Url; } } if (routeUrl.StartsWith(installerRoutePath, StringComparison.CurrentCultureIgnoreCase) || routeUrl.StartsWith(backOfficeRoutePath, StringComparison.CurrentCultureIgnoreCase)) { var ticket = http.GetRebelAuthTicket(); if (ticket != null && !ticket.Expired && http.RenewRebelAuthTicket()) { //create the Rebel user identity var identity = new RebelBackOfficeIdentity(ticket); //set the principal object var principal = new GenericPrincipal(identity, identity.Roles); app.Context.User = principal; Thread.CurrentPrincipal = principal; } } }
public static void Initialize() { using (new WriteLockDisposable(Locker)) { using (DisposableTimer.TraceDuration <PluginManager>("Start Initialise", "End Initialise")) { var settings = RebelSettings.GetSettings(); try { LogHelper.TraceIfEnabled <PluginManager>("Codegen dir is {0}", () => HttpRuntime.CodegenDir); } catch { LogHelper.TraceIfEnabled <PluginManager>("Was going to log Codegendir but couldn't get it from HttpRuntime"); } var pluginPath = HostingEnvironment.MapPath(settings.PluginConfig.PluginsPath); _pluginFolder = new DirectoryInfo(pluginPath); _shadowCopyType = settings.PluginConfig.ShadowCopyType; //default is bin _shadowCopyFolder = new DirectoryInfo(HostingEnvironment.MapPath("~/bin")); if (_shadowCopyType == PluginManagerShadowCopyType.OverrideDefaultFolder) { var shadowCopyPath = HostingEnvironment.MapPath(settings.PluginConfig.ShadowCopyPath); //if override is set, then use the one defined in config _shadowCopyFolder = new DirectoryInfo(shadowCopyPath); } else if (IsFullTrust() && _shadowCopyType == PluginManagerShadowCopyType.UseDynamicFolder) { //if in full trust and use dynamic folder, then set to CodeGen folder _shadowCopyFolder = new DirectoryInfo(AppDomain.CurrentDomain.DynamicDirectory); } var referencedPlugins = new List <PluginDefinition>(); var pluginFiles = Enumerable.Empty <FileInfo>(); try { //ensure folders are created Directory.CreateDirectory(_pluginFolder.FullName); if (_shadowCopyType != PluginManagerShadowCopyType.UseDynamicFolder) { Directory.CreateDirectory(_shadowCopyFolder.FullName); } Directory.CreateDirectory(Path.Combine(_pluginFolder.FullName, PackagesFolderName)); using (DisposableTimer.TraceDuration <PluginManager>("Finding plugin DLLs", "Finding plugin DLLs completed")) { //get list of all DLLs in plugins (not in bin!) //this will match the plugin folder pattern pluginFiles = _pluginFolder.GetFiles("*.dll", SearchOption.AllDirectories) .ToArray() // -> this magically reduces the time by about 100ms .Where(x => x.Directory.Parent != null && (IsPackageLibFolder(x.Directory))) .ToList(); } } catch (Exception ex) { var fail = new ApplicationException("Could not initialise plugin folder", ex); LogHelper.Error <PluginManager>(fail.Message, fail); //throw fail; } try { //Detect if there are any changes to plugins and perform any cleanup if in full trust using the dynamic folder if (DetectAndCleanStalePlugins(pluginFiles, _shadowCopyFolder)) { //if plugins changes have been detected, then shadow copy and re-save the cache files LogHelper.TraceIfEnabled <PluginManager>("Shadow copying assemblies"); //shadow copy files referencedPlugins .AddRange(pluginFiles.Select(plug => new PluginDefinition(plug, GetPackageFolderFromPluginDll(plug), PerformFileDeployAndRegistration(plug, true), plug.Directory.Parent.Name == "Core"))); //save our plugin hash value WriteCachePluginsHash(pluginFiles); //save our plugins list WriteCachePluginsList(pluginFiles); var codeBase = typeof(PluginManager).Assembly.CodeBase; var uri = new Uri(codeBase); var path = uri.LocalPath; var binFolder = Path.GetDirectoryName(path); if (_shadowCopyFolder.FullName.InvariantEquals(binFolder)) { LogHelper.Warn <PluginManager>("Performance: An app-pool recycle is likely to occur shortly because plugin changes were detected and shadow-copied to the bin folder"); } } else { LogHelper.TraceIfEnabled <PluginManager>("No plugin changes detected"); referencedPlugins .AddRange(pluginFiles.Select(plug => new PluginDefinition(plug, GetPackageFolderFromPluginDll(plug), PerformFileDeployAndRegistration(plug, false), plug.Directory.Parent.Name == "Core"))); } } catch (UnauthorizedAccessException) { //throw the exception if its UnauthorizedAccessException as this will //be because we cannot copy to the shadow copy folder, or update the rebel plugin hash/list files. throw; } catch (Exception ex) { var fail = new ApplicationException("Could not initialise plugin folder", ex); LogHelper.Error <PluginManager>(fail.Message, fail); //throw fail; } ReferencedPlugins = referencedPlugins; } } }
/// <summary> /// Default constructor that uses the standard RebelComponentRegistrar as the IComponentRegistrar /// </summary> /// <param name="httpApp"></param> public RebelContainerBuilder(TWebApp httpApp) { _httpApp = httpApp; _settings = RebelSettings.GetSettings(); _componentRegistrar = new RebelComponentRegistrar(); }
/// <summary>Builds the dependency demands required by this implementation. </summary> /// <param name="builder">The <see cref="IContainerBuilder"/> .</param> /// <param name="builderContext"></param> public void Build(IContainerBuilder builder, IBuilderContext builderContext) { //raise the building event OnContainerBuilding(new ContainerBuilderEventArgs(builder)); //register all of the abstract web types builder.AddDependencyDemandBuilder(new WebTypesDemandBuilder(_httpApp)); var typeFinder = new TypeFinder(); builder.ForInstanceOfType(typeFinder) .ScopedAs.Singleton(); //register the rebel settings builder.ForFactory(x => RebelSettings.GetSettings()) .KnownAsSelf() .ScopedAs.Singleton(); //only have one instance ever //register our MVC types builder.AddDependencyDemandBuilder(new MvcTypesDemandBuilder(typeFinder)); // Register the IRoutableRequestContext builder.For <HttpRequestScopedCache>().KnownAs <AbstractScopedCache>().ScopedAs.Singleton(); builder.For <HttpRuntimeApplicationCache>().KnownAs <AbstractApplicationCache>().ScopedAs.Singleton(); builder.For <HttpRequestScopedFinalizer>().KnownAs <AbstractFinalizer>().ScopedAs.Singleton(); //builder.For<DefaultFrameworkContext>().KnownAs<IFrameworkContext>().ScopedAs.Singleton(); builder.For <RebelApplicationContext>().KnownAs <IRebelApplicationContext>().ScopedAs.Singleton(); builder.For <RoutableRequestContext>().KnownAs <IRoutableRequestContext>().ScopedAs.HttpRequest(); builder.For <DefaultBackOfficeRequestContext>().KnownAs <IBackOfficeRequestContext>().ScopedAs.HttpRequest(); // TODO: Ensure this isn't created manually anywhere but tests, only via a factory: builder.ForType<IRebelRenderModel, RebelRenderContext>().Register().ScopedPerHttpRequest(); builder.For <DefaultRenderModelFactory>().KnownAs <IRenderModelFactory>(). ScopedAs.Singleton(); // Register Hive provider //builder.AddDependencyDemandBuilder(new HiveDemandBuilder()); builder.AddDependencyDemandBuilder(new Hive.DemandBuilders.HiveDemandBuilder()); // Register Persistence provider loader //builder.AddDependencyDemandBuilder(new Framework.Persistence.DependencyManagement.DemandBuilders.LoadFromPersistenceConfig()); builder.AddDependencyDemandBuilder(new Hive.DemandBuilders.LoadFromPersistenceConfig()); // Register Cms bootstrapper // TODO: Split RebelContainerBuilder between Cms and Frontend variants / needs builder.For <CmsBootstrapper>().KnownAsSelf(); // Register Frontend bootstrapper builder.ForFactory( x => new RenderBootstrapper( x.Resolve <IRebelApplicationContext>(), x.Resolve <IRouteHandler>(RenderRouteHandler.SingletonServiceName), x.Resolve <IRenderModelFactory>()) ) .KnownAsSelf(); //register all component areas, loop through all found package folders //TODO: All other places querying for packages use the NuGet IO FileManager stuff, not the standard .Net IO classes var pluginFolder = new DirectoryInfo(_httpApp.Server.MapPath(_settings.PluginConfig.PluginsPath)); foreach (var package in pluginFolder.GetDirectories(PluginManager.PackagesFolderName) .SelectMany(x => x.GetDirectories() .Where(PluginManager.IsPackagePluginFolder))) { //register an area for this package builder.For <PackageAreaRegistration>() .KnownAsSelf() .WithNamedParam("packageFolder", package); } //register the RoutingEngine builder .For <DefaultRoutingEngine>() .KnownAs <IRoutingEngine>() .ScopedAs.HttpRequest(); //register the package context builder .ForFactory(x => new DefaultPackageContext(x.Resolve <RebelSettings>(), HostingEnvironment.MapPath)) //.For<DefaultPackageContext>() .KnownAs <IPackageContext>() .ScopedAs.Singleton(); //register the PropertyEditorFactory builder.For <PropertyEditorFactory>() .KnownAs <IPropertyEditorFactory>() .ScopedAs.Singleton(); //register the ParameterEditorFactory builder.For <ParameterEditorFactory>() .KnownAs <IParameterEditorFactory>() .ScopedAs.Singleton(); //register the SecurityService builder.ForFactory( x => new SecurityService( x.Resolve <IMembershipService <User> >(), x.Resolve <IMembershipService <Member> >(), x.Resolve <IPermissionsService>(), x.Resolve <IPublicAccessService>())) .KnownAs <ISecurityService>(); //register the MembershipService builder.ForFactory( x => { var frameworkContext = x.Resolve <IFrameworkContext>(); var hiveManager = x.Resolve <IHiveManager>(); MembershipProvider membershipProvider = Membership.Providers["UsersMembershipProvider"]; return(new MembershipService <User, UserProfile>( frameworkContext, hiveManager, "security://user-profiles", "security://user-groups", FixedHiveIds.UserProfileVirtualRoot, membershipProvider, _settings.MembershipProviders)); }) .KnownAs <IMembershipService <User> >() .ScopedAs.Singleton(); builder.ForFactory( x => new MembershipService <Member, MemberProfile>( x.Resolve <IFrameworkContext>(), x.Resolve <IHiveManager>(), "security://member-profiles", "security://member-groups", FixedHiveIds.MemberProfileVirtualRoot, Membership.Providers["MembersMembershipProvider"], _settings.MembershipProviders) ) .KnownAs <IMembershipService <Member> >() .ScopedAs.Singleton(); builder.ForFactory( x => new PermissionsService( x.Resolve <IHiveManager>(), x.Resolve <IEnumerable <Lazy <Permission, PermissionMetadata> > >(), x.Resolve <IMembershipService <User> >())) .KnownAs <IPermissionsService>() .ScopedAs.Singleton(); builder.ForFactory( x => new PublicAccessService( x.Resolve <IHiveManager>(), x.Resolve <IMembershipService <Member> >(), x.Resolve <IFrameworkContext>())) .KnownAs <IPublicAccessService>() .ScopedAs.Singleton(); //register the CmsAttributeTypeRegistry builder.For <CmsAttributeTypeRegistry>() .KnownAs <IAttributeTypeRegistry>() .ScopedAs.Singleton(); //component registration _componentRegistrar.RegisterTasks(builder, typeFinder); _componentRegistrar.RegisterTreeControllers(builder, typeFinder); _componentRegistrar.RegisterPropertyEditors(builder, typeFinder); _componentRegistrar.RegisterParameterEditors(builder, typeFinder); _componentRegistrar.RegisterEditorControllers(builder, typeFinder); _componentRegistrar.RegisterMenuItems(builder, typeFinder); _componentRegistrar.RegisterSurfaceControllers(builder, typeFinder); _componentRegistrar.RegisterDashboardFilters(builder, typeFinder); _componentRegistrar.RegisterDashboardMatchRules(builder, typeFinder); _componentRegistrar.RegisterPermissions(builder, typeFinder); _componentRegistrar.RegisterMacroEngines(builder, typeFinder); //register the registrations builder.For <ComponentRegistrations>().KnownAsSelf(); //register task manager builder.For <ApplicationTaskManager>().KnownAsSelf().ScopedAs.Singleton(); //register our model mappings and resolvers builder.AddDependencyDemandBuilder(new ModelMappingsDemandBuilder()); //TODO: More stuff should happen with the TextManager here (e.g. db access and whatnot) //The user may later override settings, most importantly the LocalizationConfig.CurrentTextManager delegate to implement different environments //The text manager is assumed to be set up by the framework var textManager = LocalizationConfig.TextManager; LocalizationWebConfig.ApplyDefaults <TWebApp>(textManager, overridesPath: "~/App_Data/Rebel/LocalizationEntries.xml"); LocalizationWebConfig.SetupMvcDefaults(setupMetadata: false); //The name of the assembly that contains common texts textManager.FallbackNamespaces.Add("Rebel.Cms.Web"); OnContainerBuildingComplete(new ContainerBuilderEventArgs(builder)); }
static AuthenticationExtensions() { _settings = RebelSettings.GetSettings(); }
public IDictionary <string, string> GetData() { return(RebelSettings.GetSettings().Applications.ToDictionary(x => x.Alias, y => y.Name)); }