/// <summary>
        /// Selects all guids of descendant web pages for the given web page.
        /// </summary>
        /// <param name="entityId">
        /// The webpage Id.
        /// </param>
        /// <param name="contentMap">
        /// The content map.
        /// </param>
        /// <param name="predicates">
        /// <see cref="IEnumerable"/> of predicates to determine whether a web page should be included in the results. Executed in order with short circuiting.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable"/> of the web page GUIDs for descendant web pages.
        /// </returns>
        private static IEnumerable <Guid> SelectAllDescendantWebpagesWithPredicates(Guid entityId, ContentMap contentMap, IEnumerable <Predicate <WebPageNode> > predicates)
        {
            EntityNode entity;

            if (!contentMap.TryGetValue(new EntityReference("adx_webpage", entityId), out entity))
            {
                return(Enumerable.Empty <Guid>());
            }

            var rootWebpage = entity as WebPageNode;

            if (rootWebpage == null)
            {
                return(Enumerable.Empty <Guid>());
            }

            // if it's a content page, we want to start at it's root page so we can navigate down the web page hierarchy
            if (rootWebpage.IsRoot == false)
            {
                if (rootWebpage.RootWebPage == null)
                {
                    // just return this web page, can't reach any others
                    return(new List <Guid>()
                    {
                        rootWebpage.Id
                    });
                }

                rootWebpage = rootWebpage.RootWebPage;
            }

            var unprocessedNodes = new Queue <WebPageNode>();
            var webPageGuids     = new List <Guid>();

            unprocessedNodes.Enqueue(rootWebpage);
            while (unprocessedNodes.Count > 0)
            {
                WebPageNode currWebPage = unprocessedNodes.Dequeue();

                foreach (var childWebPage in currWebPage.WebPages)
                {
                    unprocessedNodes.Enqueue(childWebPage);
                }

                if (currWebPage.LanguageContentPages != null)
                {
                    foreach (var contentPage in currWebPage.LanguageContentPages)
                    {
                        unprocessedNodes.Enqueue(contentPage);
                    }
                }

                if (predicates.All(predicate => predicate(currWebPage)))
                {
                    webPageGuids.Add(currWebPage.Id);
                }
            }

            return(webPageGuids);
        }
        private DirectoryTreeNode GetTree(WebPageNode directory, ILookup <EntityReference, IGrouping <EntityReference, Tuple <Entity, DirectoryType> > > parentLookup)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            var directoryEntityReference = directory.ToEntityReference();

            var langContext = HttpContext.Current.GetContextLanguageInfo();
            Func <WebPageNode, bool> langFilter = page => page.IsRoot.HasValue && page.IsRoot.Value;

            var nodeSubTrees = directory.WebPages
                               .Where(child => child.Website.Id == Website.Id)
                               .Where(child => TryAssertSecurity(child, CrmEntityRight.Read))
                               .Where(langContext.IsCrmMultiLanguageEnabled ? langFilter : child => true)
                               .Select(child => GetTree(child, parentLookup));

            var entitySubTrees = parentLookup[directoryEntityReference]
                                 .SelectMany(grouping => grouping)
                                 .Where(child => TryAssertSecurity(child.Item1, CrmEntityRight.Read))
                                 .Select(child => GetTree(child.Item1, child.Item2, parentLookup));

            return(new DirectoryTreeNode(directory.ToEntity())
            {
                name = string.IsNullOrWhiteSpace(directory.Title) ? directory.Name : directory.Title,
                hash = new DirectoryContentHash(directoryEntityReference, true).ToString(),
                read = true,
                write = TryAssertSecurity(directory, CrmEntityRight.Change),
                dirs = nodeSubTrees
                       .Concat(entitySubTrees)
                       .OrderBy(node => node.name)
                       .ToArray()
            });
        }
        /// <summary>
        /// Get the rules for the page.
        /// </summary>
        /// <param name="webPage">
        /// The web page.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable"/> of <see cref="WebPageAccessControlRuleNode"/>.
        /// </returns>
        private static IEnumerable <WebPageAccessControlRuleNode> GetRulesForPage(WebPageNode webPage)
        {
            if (webPage.Parent != null)
            {
                foreach (var rule in GetRulesForPage(webPage.Parent))
                {
                    yield return(rule);
                }
            }

            if (webPage.IsReference)
            {
                yield break;
            }

            foreach (var rule in webPage.WebPageAccessControlRules)
            {
                if (rule.PublishingStates.Any())
                {
                    if (rule.PublishingStates.Any(publishingState => publishingState.Name == webPage.PublishingState.Name))
                    {
                        yield return(rule);
                    }
                }
                else
                {
                    yield return(rule);
                }
            }
        }
        /// <summary>
        /// Checks for the circular reference over web pages.
        /// </summary>
        /// <param name="page">Webpage node to check for circular reference.</param>
        private bool?CircularReferenceCheck(WebPageNode page)
        {
            var pageDetails = new Dictionary <Guid, string>();

            if (page.IsCircularReference == null)
            {
                while (page.Parent != null)
                {
                    if (pageDetails.ContainsKey(page.Id) && page.Id != Guid.Empty)
                    {
                        page.IsCircularReference = true;
                        return(true);
                    }
                    else
                    {
                        pageDetails.Add(page.Id, page.Name);
                    }

                    page = page.Parent;
                }

                page.IsCircularReference = false;
            }

            return(page.IsCircularReference);
        }
 /// <summary>
 /// Figures out whether the given web page is a translated content WebPage and its language matches the current active portal language.
 /// If multi-language is not enabled, then true will always be returned.
 /// </summary>
 /// <param name="page">WebPageNode to check.</param>
 /// <param name="langContext">The language context.</param>
 /// <returns>Whether the given web page matches the current active portal language.</returns>
 private bool IsValidLanguageContentPage(WebPageNode page, ContextLanguageInfo langContext)
 {
     if (langContext.IsCrmMultiLanguageEnabled)
     {
         return(page.IsRoot != true && page.WebPageLanguage != null && page.WebPageLanguage.Id == langContext.ContextLanguage.EntityReference.Id);
     }
     return(true);
 }
Exemple #6
0
        private static bool IsPartialUrlMatch(WebPageNode page, string path)
        {
            var decodedPath = HttpUtility.UrlDecode(path);

            return(page != null &&
                   (string.Equals(page.PartialUrl, path, StringComparison.InvariantCultureIgnoreCase) ||
                    string.Equals(page.PartialUrl, decodedPath, StringComparison.InvariantCultureIgnoreCase)));
        }
        protected CrmSiteMapNode GetAccessibleNodeOrAccessDeniedNode(ContentMap map, WebPageNode page, IContentMapEntityUrlProvider provider, bool excludeFromSecurityValidation = false)
        {
            if (excludeFromSecurityValidation)
            {
                return(GetNode(map, page, provider) ?? GetAccessDeniedNodeInternal());
            }

            return(ReturnNodeIfAccessible(GetNode(map, page, provider), GetAccessDeniedNodeInternal));
        }
        protected virtual string GetUrl(WebPageNode page)
        {
            var applicationPath = GetApplicationPath(page);

            if (applicationPath != null)
            {
                return(applicationPath.ExternalUrl ?? applicationPath.AbsolutePath);
            }

            return(null);
        }
        protected virtual CrmSiteMapNode GetNode(ContentMap map, WebPageNode webPageNode, HttpStatusCode statusCode, IContentMapEntityUrlProvider provider, bool includeReturnUrl = false)
        {
            var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo();

            WebPageNode GetLanguageNode()
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, string.Format("SiteMapProvider.GetNode Lang:{0} ", webPageNode.IsRoot != false ? "root" : webPageNode.WebPageLanguage.PortalLanguage.Code));
                var languageNode = webPageNode.LanguageContentPages.FirstOrDefault(p => p.WebPageLanguage.PortalLanguage.Code == contextLanguageInfo.ContextLanguage.Code);

                return(languageNode ?? webPageNode);
            }

            var page = contextLanguageInfo.IsCrmMultiLanguageEnabled ? GetLanguageNode() : webPageNode;

            var template = page.PageTemplate;

            if (template == null)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Web Page with id '{0}' does not have the required Page Template.", page.Id));

                return(null);
            }

            var returnUrl = includeReturnUrl && HttpContext.Current != null
                                ? "&ReturnUrl={0}".FormatWith(System.Web.Security.AntiXss.AntiXssEncoder.UrlEncode(HttpContext.Current.Request.Url.PathAndQuery))
                                : string.Empty;

            var rewriteUrl = template.Type == (int)PageTemplateNode.TemplateType.WebTemplate && template.WebTemplateId != null
                                ? template.UseWebsiteHeaderAndFooter.GetValueOrDefault(true) ? "~/Pages/WebTemplate.aspx" : "~/Pages/WebTemplateNoMaster.aspx"
                                : template.RewriteUrl;

            var entity = page.ToEntity(GetEntityType("adx_webpage"));
            var url    = provider.GetUrl(map, page);

            var node = new CrmSiteMapNode(
                this,
                url,
                url,
                !string.IsNullOrWhiteSpace(page.Title) ? page.Title : page.Name,
                page.Summary,
                "{0}?pageid={1}{2}".FormatWith(rewriteUrl, page.Id, returnUrl),
                page.ModifiedOn.GetValueOrDefault(DateTime.UtcNow),
                entity,
                statusCode);

            if (template.WebTemplateId != null)
            {
                node["adx_webtemplateid"] = template.WebTemplateId.Id.ToString();
            }

            return(node);
        }
        /// <summary> The is inactive path. </summary>
        /// <param name="page"> The page. </param>
        /// <returns> The <see cref="bool"/>. </returns>
        private static bool IsInactivePath(WebPageNode page)
        {
            if (page == null)
            {
                return(false);
            }
            if (page.IsCircularReference == true)
            {
                return(true);
            }

            return(page.IsReference || IsInactivePath(page.Parent));
        }
        protected virtual DirectoryContent GetDirectoryContent(WebPageNode node)
        {
            if (node == null)
            {
                return(null);
            }

            var info = new WebPageNodeDirectory(ContentMapFileSystem, ContentMap, node).Info;

            info.rel = null;

            return(info.read && info.url != null ? info : null);
        }
        /// <summary>
        /// Gets the application path for the webpage.
        /// </summary>
        /// <param name="webPage">
        /// The web page.
        /// </param>
        /// <param name="additionalPartialUrl">
        /// Optional additional Partial Url to be added to the webpage url.
        /// </param>
        /// <returns>
        /// The <see cref="ApplicationPath"/>.
        /// </returns>
        private static ApplicationPath GetApplicationPath(WebPageNode webPage, string additionalPartialUrl = null)
        {
            var partialUrl = webPage.PartialUrl;

            if (!string.IsNullOrEmpty(additionalPartialUrl))
            {
                partialUrl = string.Format("{0}/{1}", partialUrl, additionalPartialUrl);
            }
            if (webPage.Parent != null)
            {
                return(AdxEntityUrlProvider.JoinApplicationPath(GetApplicationPath(webPage.Parent).PartialPath, partialUrl));
            }
            return(ApplicationPath.FromPartialPath(partialUrl));
        }
        /// <summary>
        /// Returns application path url by joining the partial url and partial path of parent url.
        /// </summary>
        /// <param name="parent">Contains Parent page of Webpage node.</param>
        /// <param name="partialUrl">Contains partial url of Webpage node.</param>
        private ApplicationPath InternalJoinApplicationPath(WebPageNode parent, string partialUrl)
        {
            var applicationPathUrl = ApplicationPath.FromPartialPath(string.Empty);
            var parentUrl          = InternalGetApplicationPath(parent);

            if (parentUrl == null)
            {
                ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Parent is Null. PartialUrl = {0}", partialUrl));
                return(null);
            }

            applicationPathUrl = JoinApplicationPath(parentUrl.PartialPath, partialUrl);
            return(applicationPathUrl);
        }
Exemple #14
0
        private static UrlMappingResult <WebPageNode> FilterResultsOnLanguage(IEnumerable <WebPageNode> pages, Func <WebPageNode, bool> predicate, WebPageLookupOptions lookupOption, ContextLanguageInfo contextLanguageInfo)
        {
            var         results = pages.Where(predicate);
            WebPageNode retval  = null;

            if (contextLanguageInfo != null && contextLanguageInfo.IsCrmMultiLanguageEnabled)
            {
                if (lookupOption == WebPageLookupOptions.LanguageContentOnly)
                {
                    // when we have only a root webpage and 0 localized webpages.
                    // for example: creating new child page via portal CMS.
                    if (results.Where(p => p.IsRoot == false).Count() == 0)
                    {
                        retval = results.FirstOrDefault();
                    }
                    else
                    {
                        var websiteLanguageId = contextLanguageInfo.ContextLanguage.EntityReference.Id;
                        retval = results.FirstOrDefault(p => p.WebPageLanguage != null && p.WebPageLanguage.Id == websiteLanguageId && p.IsRoot == false);
                    }
                }
                else if (lookupOption == WebPageLookupOptions.RootOnly)
                {
                    retval = results.FirstOrDefault(p => p.IsRoot == true);
                }
                else
                {
                    retval = results.FirstOrDefault();
                }

                // If the found page is content, but the root page is deactivated, then return null as if the page itself doesn't exist.
                if (retval != null && retval.IsRoot == false && (retval.RootWebPage == null || retval.RootWebPage.IsReference))
                {
                    retval = null;
                }
            }
            else
            {
                // If multi-language is not supported, then do legacy behavior of returning first result.
                retval = results.FirstOrDefault();
            }

            // select only root pages or pages where isroot = null (MLP is not supported)
            var duplicateCheckArray = results.Where(p => p.IsRoot != false).ToArray();

            return(duplicateCheckArray.Length > 1
                                ? UrlMappingResult <WebPageNode> .DuplicateResult(retval)
                                : UrlMappingResult <WebPageNode> .MatchResult(retval));
        }
        /// <summary> Determines whether page is service and should be ignored by access control rules. </summary>
        /// <param name="page"> The page. </param>
        /// <returns> The <see cref="bool"/>. </returns>
        private static bool IsServicePage(WebPageNode page)
        {
            if (page?.Website == null)
            {
                return(false);
            }

            var servicePages = page.Website.SiteMarkers
                               .Where(marker => marker.Name == ContentMapCrmSiteMapProvider.AccessDeniedPageSiteMarkerName ||
                                      marker.Name == ContentMapCrmSiteMapProvider.NotFoundPageSiteMarkerName)
                               .Select(marker => marker.WebPage);

            var isRoot = page.IsRoot.GetValueOrDefault();             // MLP

            return(servicePages.Any(servicePage => isRoot || page.RootWebPage == null ? page.Id == servicePage.Id : page.RootWebPage.Id == servicePage.Id));
        }
        public WebPageNodeDirectory(ContentMapFileSystem fileSystem, ContentMap contentMap, WebPageNode node) : base(fileSystem)
        {
            if (contentMap == null)
            {
                throw new ArgumentNullException("contentMap");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            ContentMapFileSystem = fileSystem;
            ContentMap           = contentMap;
            Node = node;
            ContentMapUrlProvider = fileSystem.ContentMapUrlProvider;
        }
Exemple #17
0
        /// <summary> The to site marker target. </summary>
        /// <param name="webPageNode"> The web page node. </param>
        /// <returns> The <see cref="ISiteMarkerTarget"/>. </returns>
        private ISiteMarkerTarget ToSiteMarkerTarget(WebPageNode webPageNode)
        {
            if (webPageNode == null)
            {
                return(null);
            }

            var urlProvider      = this.Dependencies.GetUrlProvider();
            var securityProvider = this.Dependencies.GetSecurityProvider();
            var serviceContext   = this.Dependencies.GetServiceContext();
            var entity           = webPageNode.AttachTo(serviceContext);

            var portalViewEntity = new PortalViewEntity(serviceContext, entity, securityProvider, urlProvider);
            var siteMarkerTarget = new SiteMarkerTarget(entity, portalViewEntity, urlProvider.GetApplicationPath(serviceContext, entity));

            return(siteMarkerTarget);
        }
        private ApplicationPath InternalGetApplicationPath(WebPageNode page)
        {
            var parent     = page.Parent;
            var partialUrl = page.PartialUrl;
            var url        = ApplicationPath.FromPartialPath(string.Empty);

            if (parent == null || parent.IsReference)
            {
                // Home page (with partial url "/") are not expected to have a parent page.
                if (partialUrl == "/")
                {
                    return(ApplicationPath.FromPartialPath(partialUrl));
                }

                var traceMessage = parent == null?string.Format("Parent is Null. Page.Id = {0}", page.Id) : string.Format("Parent is Reference. Page.Id = {0}, ParentId = {1}", page.Id, parent.Id);

                ADXTrace.Instance.TraceWarning(TraceCategory.Application, traceMessage);
                return(null);
            }

            Version currentVersion   = page.Website.CurrentBaseSolutionCrmVersion;
            Version centaurusVersion = BaseSolutionVersions.CentaurusVersion;

            if (currentVersion.Major >= centaurusVersion.Major && currentVersion.Minor >= centaurusVersion.Minor)
            {
                url = InternalJoinApplicationPath(parent, partialUrl);
            }

            else
            {
                if (CircularReferenceCheck(page) == true)
                {
                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Circular reference with page {0}", page.Id));
                    return(url);
                }
                else
                {
                    url = InternalJoinApplicationPath(parent, partialUrl);
                }
            }

            return(url);
        }
        /// <summary> The get rules for page. </summary>
        /// <param name="webPage"> The web page. </param>
        /// <param name="useInheritance">true to aggregate rules from parent pages</param>
        /// <returns> The rules. </returns>
        private static IEnumerable <WebPageAccessControlRuleNode> GetRulesForPage(WebPageNode webPage, bool useInheritance)
        {
            if (useInheritance && webPage.Parent != null)
            {
                foreach (var rule in GetRulesForPage(webPage.Parent, true))
                {
                    yield return(rule);
                }
            }

            // Guard against null reference exception. This might happen if WebPage is a translated content, but for whatever reason has no root web page.
            if (webPage.WebPageAccessControlRules != null)
            {
                foreach (var rule in webPage.WebPageAccessControlRules)
                {
                    yield return(rule);
                }
            }
        }
 /// <summary>
 /// Is the web page url defined.
 /// </summary>
 /// <param name="webPage">
 /// The web page.
 /// </param>
 /// <param name="additionalPartialUrl">
 /// Optional additional Partial Url to be added to the webpage url.
 /// </param>
 /// <returns>
 /// If the webpage has a URL defined or not.
 /// </returns>
 private static bool IsWebPageUrlDefined(WebPageNode webPage, string additionalPartialUrl = null)
 {
     if (webPage == null)
     {
         ADXTrace.Instance.TraceWarning(TraceCategory.Monitoring, "Web Page url is not defined. Web Page is null");
         return(false);
     }
     try
     {
         var applicationPath = GetApplicationPath(webPage, additionalPartialUrl);
         var newPath         = ApplicationPath.FromPartialPath(WebsitePathUtility.ToAbsolute(new Entity("adx_website", webPage.Website.Id), applicationPath.PartialPath));
         return(newPath != null);
     }
     catch (Exception e)
     {
         // if the application path wasn't a real path then it will throw an exception so just return false
         ADXTrace.Instance.TraceWarning(TraceCategory.Monitoring, string.Format("IsWebPageUrlDefined caught exception, returning false - {0}", e));
         return(false);
     }
 }
        public ContentMapFileSystemContext(IEntityDirectoryFileSystem fileSystem, ContentMap contentMap, WebPageNode root, IDirectory current) : base(fileSystem)
        {
            if (contentMap == null)
            {
                throw new ArgumentNullException("contentMap");
            }
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            if (current == null)
            {
                throw new ArgumentNullException("current");
            }

            ContentMap = contentMap;
            Root       = root;
            _current   = current;

            _tree = new Lazy <DirectoryTreeNode>(GetTree, LazyThreadSafetyMode.None);
        }
        private ApplicationPath GetApplicationPath(WebPageNode page)
        {
            var websiteRelativeUrl = InternalGetApplicationPath(page);

            if (websiteRelativeUrl == null)
            {
                return(null);
            }

            var path    = websiteRelativeUrl.PartialPath;
            var appPath = ApplicationPath.FromPartialPath(path);

            if (appPath.ExternalUrl != null)
            {
                return(appPath);
            }

            var canonicalPath = appPath.AppRelativePath.EndsWith("/")
                                ? appPath
                                : ApplicationPath.FromAppRelativePath("{0}/".FormatWith(appPath.AppRelativePath));

            return(canonicalPath);
        }
        /// <summary> The try assert. </summary>
        /// <param name="page"> The page. </param>
        /// <param name="right"> The right. </param>
        /// <param name="useScope">Pass true if you need to determine web file permissions throught parent web page</param>
        /// <returns> The <see cref="bool"/>. </returns>
        public virtual bool TryAssert(WebPageNode page, CrmEntityRight right, bool useScope)
        {
            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Testing right {0} on web page '{1}' ({2}).", right, page.Name, page.Id));

            if (!Roles.Enabled)
            {
                ADXTrace.Instance.TraceError(TraceCategory.Application, "Roles are not enabled for this application. Allowing Read, but not Change.");

                // If roles are not enabled on the site, grant Read, deny Change.
                return(right == CrmEntityRight.Read);
            }

            // Ignore access control rules for service pages like not found or access denied
            if (right == CrmEntityRight.Read && IsServicePage(page))
            {
                return(true);
            }

            // If the chain of pages from the current page up to the root page contains an inactive page, deny the assertion
            if (IsInactivePath(page))
            {
                return(false);
            }

            var userRoles = this.GetUserRoles();

            // when we use rule scope we're checking permissions for parent page of web file
            //	and we need to check permissions only for one level
            var useInheritance = !useScope;

            // Get all rules applicable to the page and its parent path, grouping equivalent rules. (Rules that
            // target the same web page and confer the same right are equivalent.)
            var ruleGroupings =
                from rule in this.GetRulesApplicableToWebPage(page, useInheritance)
                where rule.WebPage != null && rule.Right != null
                group rule by new { WebPageId = rule.WebPage.Id, Right = ParseRightOption(rule.Right.Value) } into ruleGrouping
            select ruleGrouping;

            // Order the rule groupings so that all GrantChange rules will be evaluated first.
            ruleGroupings = ruleGroupings.OrderByDescending(grouping => grouping.Key.Right, new RightOptionComparer());

            foreach (var ruleGrouping in ruleGroupings)
            {
                // Collect the names of all the roles that apply to this rule grouping
                var ruleGroupingRoles = ruleGrouping.SelectMany(
                    rule => rule.WebRoles.Where(role => BelongsToWebsite(page.Website, role))
                    .Select(role => role.Name));

                // Determine if the user belongs to any of the roles that apply to this rule grouping
                var userIsInAnyRoleForThisRule = ruleGroupingRoles.Any(role => userRoles.Any(userRole => userRole == role));

                // If the user belongs to one of the roles...
                if (userIsInAnyRoleForThisRule)
                {
                    // ...and the rule is GrantChange...
                    if (ruleGrouping.Key.Right == RightOption.GrantChange)
                    {
                        ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("User has right Change on web page ({0}). Permission granted.", ruleGrouping.Key.WebPageId));

                        // ...the user has all rights.
                        return(true);
                    }
                }

                // If the user does not belong to any of the roles, the rule restricts read, and the desired right
                // is read...
                else if (ruleGrouping.Key.Right == RightOption.RestrictRead && right == CrmEntityRight.Read)
                {
                    if (useScope && ruleGrouping.Any(rule => rule.Scope.HasValue && (ScopeOption)rule.Scope.Value == ScopeOption.ExcludeDirectChildWebFiles))
                    {
                        // Ignore read restriction for web files where scope is ExcludeDirectChildWebFiles
                        ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Ignoring web page ({0}) read restriction due to ExcludeDirectChildWebFiles", ruleGrouping.Key.WebPageId));
                    }
                    else
                    {
                        if (page.Parent == null && page.PartialUrl == "/")
                        {
                            ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("\"Restrict Read\" right on web page({0}) ({1}).", ruleGrouping.Key.WebPageId, page.Name));
                        }
                        ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("User does not have right Read due to read restriction on web page ({0}). Permission denied.", ruleGrouping.Key.WebPageId));

                        // ...the user has no right.
                        return(false);
                    }
                }
            }

            ADXTrace.Instance.TraceInfo(TraceCategory.Application, "No access control rules apply to the current user and page. Allowing Read, but not Change.");

            // If none of the above rules apply, grant Read by default, and deny Change by default.
            return(right == CrmEntityRight.Read);
        }
        /// <summary> The get rules applicable to web page. </summary>
        /// <param name="webPage"> The web page. </param>
        /// <param name="useInheritance">true to aggregate rules from parent pages</param>
        /// <returns> The rules. </returns>
        protected virtual IEnumerable <WebPageAccessControlRuleNode> GetRulesApplicableToWebPage(WebPageNode webPage, bool useInheritance)
        {
            var rules = GetRulesForPage(webPage, useInheritance);

            var stateSpecificRules = new List <WebPageAccessControlRuleNode>();
            var statelessRules     = new List <WebPageAccessControlRuleNode>();
            var restrictReadRules  = new List <WebPageAccessControlRuleNode>();

            foreach (var rule in rules)
            {
                if (rule.Right == (int)RightOption.GrantChange)
                {
                    var webPagePublishingState = webPage.PublishingState != null ? webPage.PublishingState.Name : null;

                    if (rule.PublishingStates.Any(ps => ps.Name == webPagePublishingState))
                    {
                        stateSpecificRules.Add(rule);
                    }
                    else
                    {
                        statelessRules.Add(rule);
                    }
                }
                else
                {
                    restrictReadRules.Add(rule);
                }
            }

            // if any state specific rules exist, ignore the stateless rules

            if (stateSpecificRules.Any())
            {
                foreach (var rule in stateSpecificRules)
                {
                    yield return(rule);
                }
            }
            else
            {
                foreach (var rule in statelessRules)
                {
                    yield return(rule);
                }
            }

            foreach (var rule in restrictReadRules)
            {
                yield return(rule);
            }
        }
Exemple #25
0
        /// <summary> The try get page node from site marker node. </summary>
        /// <param name="siteMarkerName"> The site marker name. </param>
        /// <param name="contentMap"> The content map. </param>
        /// <param name="targetNode"> The target node. </param>
        /// <returns> The <see cref="bool"/>. </returns>
        private bool TryGetPageNodeFromSiteMarkerNode(string siteMarkerName, ContentMap contentMap, out WebPageNode targetNode)
        {
            var website = HttpContext.Current.GetWebsite().Entity;
            IDictionary <EntityReference, EntityNode> siteMarkers;

            targetNode = null;

            if (!contentMap.TryGetValue("adx_sitemarker", out siteMarkers))
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, "No Sitemarkers found on Content Map");
                return(false);
            }

            var siteMarkerNode = siteMarkers.Values
                                 .Cast <SiteMarkerNode>()
                                 .FirstOrDefault(e => e.Website.Id == website.Id && e.Name == siteMarkerName);

            if (siteMarkerNode == null || siteMarkerNode.WebPage == null)
            {
                return(false);
            }

            if (!contentMap.TryGetValue(siteMarkerNode.WebPage, out targetNode))
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("No WebPage found on Sitemarker:{0}", siteMarkerNode.Id));
                return(false);
            }

            if (!this.Language.IsCrmMultiLanguageEnabled)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("WebPage found for Sitemarker:{0} Page:{1}", siteMarkerNode.Id, targetNode.Id));
                return(true);
            }

            // MLP - Find the content webpage for the current language from the target page
            var contentWebPage = targetNode.LanguageContentPages.FirstOrDefault(p => p.WebPageLanguage == this.Language.ContextLanguage.WebsiteLanguageNode);

            if (contentWebPage != null)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("WebPage found for Sitemarker:{0} Language:{1}", siteMarkerNode.Id, this.Language.ContextLanguage.Lcid));
                targetNode = contentWebPage;
                return(true);
            }

            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("No WebPage found for Sitemarker:{0} Language:{1}", siteMarkerNode.Id, this.Language.ContextLanguage.Lcid));
            return(false);
        }
 protected virtual CrmSiteMapNode GetNode(ContentMap map, WebPageNode page, IContentMapEntityUrlProvider provider)
 {
     return(GetNode(map, page, HttpStatusCode.OK, provider));
 }
 /// <summary>
 /// Checks if the web page is a root page.
 /// </summary>
 /// <param name="webPageNode">The web page node.</param>
 /// <returns>Whether the web page is a root web page.</returns>
 private static bool IsRootWebPage(WebPageNode webPageNode)
 {
     // if IsRoot == null, MLP is disabled and root pages are the same as content pages
     return(webPageNode.IsRoot == true || webPageNode.IsRoot == null);
 }