public override void Process(HttpRequestArgs args) { //when using a path such as /Controller.aspx/Blahblahblah, Sitecore's parsing of FilePath can break if Blahblahblah is too long RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(args.Context)); if (routeData != null) //!SitecoreMvcAreaRegistration.SitecoreAreaName.Equals(routeData.DataTokens["area"]))) { args.Url.FilePath = args.Context.Request.Url.LocalPath; if (!(routeData.Route is SitecoreRoute)) { args.Context.Items["SitecoreOn"] = false; args.AbortPipeline(); } else { SiteContext site = Context.Site; if (site != null && !SiteManager.CanEnter(site.Name, (Account)Context.User)) { base.Process(args); } } } else { base.Process(args); } }
public void TestIsPageEditorEditingWithExtraAssertions() { //this does not work for SiteManager.GetSite("shell") //var shellAttributes = new StringDictionary // { // {"name", "shell"}, // {"domain", "sitecore"} // }; //var shell = new FakeSiteContext(shellAttributes); //SiteContextFactory.Sites.Add(shell.SiteInfo); //Assert site configuration defined in app.config Factory.GetSite("shell").Should().NotBeNull(); Factory.GetSite("shell").Domain.Name.Should().NotBeNullOrWhiteSpace(); SiteManager.GetSite("shell").Should().NotBeNull(); var fakeSiteContext = new FakeSiteContext( new StringDictionary { { "name", "mywebsite" }, { "enableWebEdit", "true" }, { "database", "web" }, { "masterDatabase", "master" }, }); fakeSiteContext.Name.Should().Be("mywebsite"); using (new SiteContextSwitcher(fakeSiteContext)) { SiteManager.CanEnter("shell", Context.User).Should().BeTrue(); //check prerequisites Context.Site.Name.Should().Be("mywebsite"); Context.Site.EnableWebEdit.Should().BeTrue(); Context.Site.Database.Name.Should().Be("web"); Context.Site.MasterDatabase.Name.Should().Be("master"); Settings.CommerceServer.StandaloneEdition.Should().BeFalse(); Settings.WebEdit.Enabled.Should().BeTrue(); //act Context.Site.SetDisplayMode(DisplayMode.Edit, DisplayModeDuration.Remember); //assert Context.Site.DisplayMode.Should().Be(DisplayMode.Edit); Context.PageMode.IsPageEditorEditing.Should().BeTrue(); } }
public override void Process(HttpRequestArgs args) { if (Context.Database == null || Context.Site == null) return; // Not checking IDAM authentication of content editors if ((new[] { "shell", "login", "admin" }).Contains(Context.Site.Name)) return; // force login only for normal website usage, not for preview / debugging / experienceediting / profiling if (!Context.PageMode.IsNormal) return; if (Context.User.IsAuthenticated) return; if (!SiteManager.CanEnter(Context.Site.Name, Context.User)) return; if (Context.Item != null && Context.Item.Access.CanRead()) return; if (Context.Item == null && args.PermissionDenied) { // generate nonces and set temporary cookie var state = Guid.NewGuid().ToString("N"); var nonce = Guid.NewGuid().ToString("N"); var cookie = new CookieHelper(Settings.TempCookieName, args.Context); cookie.SetValue("state", state); cookie.SetValue("nonce", nonce); cookie.SetValue("returnUrl", args.Context.Request.Url.ToString()); cookie.Save(); var request = new AuthorizeRequest(Settings.AuthorizeEndpoint); var url = request.CreateAuthorizeUrl( clientId: Settings.ClientId, responseType: "code", scope: Settings.Scope, redirectUri: Settings.SignInCallbackUrl, state: state, nonce: nonce); // Redirect the user to the login page of the identity provider WebUtil.Redirect(url); } }
public override void Process(HttpRequestArgs args) { //don't do backend if (Sitecore.Context.Domain.Name.ToLower().Contains("sitecore") || !Sitecore.Context.PageMode.IsNormal) { return; } // Get the site context SiteContext site = Sitecore.Context.Site; // Check if the current user has sufficient rights to enter this page if (!SiteManager.CanEnter(site.Name, Sitecore.Context.User)) { return; } string prefix = args.StartPath; if (args.LocalPath.Contains(Sitecore.Context.Site.StartPath)) { prefix = String.Empty; } if (Sitecore.Context.Database == null) { return; } // Get the item using securityDisabler for restricted items such as permission denied items Item contextItem = null; using (new SecurityDisabler()) { if (Context.Database == null || args.Url.ItemPath.Length == 0) { return; } string path = MainUtil.DecodeName(args.Url.ItemPath); Item item = args.GetItem(path); if (item == null) { path = args.LocalPath; item = args.GetItem(path); } if (item == null) { path = MainUtil.DecodeName(args.LocalPath); item = args.GetItem(path); } string str2 = (site != null) ? site.RootPath : string.Empty; if (item == null) { path = FileUtil.MakePath(str2, args.LocalPath, '/'); item = args.GetItem(path); } if (item == null) { path = MainUtil.DecodeName(FileUtil.MakePath(str2, args.LocalPath, '/')); item = args.GetItem(path); } if (item == null) { Item root = ItemManager.GetItem(site.RootPath, Language.Current, Sitecore.Data.Version.Latest, Context.Database, SecurityCheck.Disable); if (root != null) { string path2 = MainUtil.DecodeName(args.LocalPath); item = this.GetSubItem(path2, root); } } if (item == null) { int index = args.Url.ItemPath.IndexOf('/', 1); if (index >= 0) { Item root = ItemManager.GetItem(args.Url.ItemPath.Substring(0, index), Language.Current, Sitecore.Data.Version.Latest, Context.Database, SecurityCheck.Disable); if (root != null) { string path3 = MainUtil.DecodeName(args.Url.ItemPath.Substring(index)); item = this.GetSubItem(path3, root); } } } if (((item == null) && args.UseSiteStartPath) && (site != null)) { item = args.GetItem(site.StartPath); } contextItem = item; } //Item contextItem = Sitecore.Context.Item; if (contextItem == null) { return; } User u = Sitecore.Context.User; bool isAllowed = AuthorizationManager.IsAllowed(contextItem, AccessRight.ItemRead, u); if (isAllowed) { return; } string rawURL = HttpContext.Current.Server.HtmlEncode(HttpContext.Current.Request.RawUrl); if (site.LoginPage.Length > 0) // Redirect the user { WebUtil.Redirect(string.Format("{0}?returnUrl={1}", site.LoginPage, rawURL)); } }