//Event handler for page access rights change
        public void OnContentSecuritySaved(object sender, ContentSecurityEventArg contentSecurityEventArgs)
        {
            var contentLink = contentSecurityEventArgs.ContentLink;
            var content     = _contentLoader.Get <IContent>(contentLink);

            if (content is PageData)
            {
                UpdateIndexAfterPageAccessRightsChange(content);
            }
        }
예제 #2
0
        public void UpdateIndex_AclChangeOnPublishedContent_CallsUpdate()
        {
            var link = Factory.GetPageReference();
            var args = new ContentSecurityEventArg(link, new ContentAccessControlList(), SecuritySaveType.None);

            var versionRepoMock = new Mock <IContentVersionRepository>();

            versionRepoMock
            .Setup(m => m.LoadPublished(link))
            .Returns(new ContentVersion(default, default, default, default, default, default, default, default, default, default));
예제 #3
0
        private void OnContentSecuritySaved(object sender, ContentSecurityEventArg e)
        {
            var configuration = StaticWebConfiguration.CurrentSite;

            if (configuration == null || !configuration.Enabled)
            {
                return;
            }

            bool?useTemporaryAttribute = configuration.UseTemporaryAttribute.HasValue ? false : configuration.UseTemporaryAttribute;
            var  staticWebService      = ServiceLocator.Current.GetInstance <IStaticWebService>();

            staticWebService.GeneratePagesDependingOnContent(configuration, e.ContentLink, useTemporaryAttribute, IGNORE_HTML_DEPENDENCIES);
        }
예제 #4
0
 private void UpdateSecurity(object sender, ContentSecurityEventArg e)
 {
     Task.Run(() =>
     {
         if (SiteCreationServiceBase.IsSettingUpSite())
         {
             return;
         }
         var content = _contentRepository.Value.Get <IContent>(e.ContentLink);
         if (LuceneConfiguration.CanIndexContent(content))
         {
             _indexingHandler.Value.ProcessRequest(new IndexRequestItem(content));
         }
     });
 }
        /// <summary>
        /// Handles the <see cref="IContentSecurityRepository.ContentSecuritySaved"/> event and logs the changes.
        /// </summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">ContentSecuritySaved event <see cref="ContentSecurityEventArg"/> where from the log message is created</param>
        private void ContentSecuritySaved(object sender, ContentSecurityEventArg e)
        {
            try
            {
                // what access rights changes were made, target can be user or group (including visitor groups if those are set to be usable to protect content)
                var permissions = e.ContentSecurityDescriptor?.Entries?.Select(entry => $"{entry.EntityType}: {entry.Name} access level set to: {entry.Access}.");

                // this is always null/empty, why? one would assume we would get the creator info here
                //string creator = e.ContentSecurityDescriptor.Creator;

                // this is guranteed to return a valid principal, so use this instead of creator
                string userFromContext = PrincipalInfo.CurrentPrincipal.Identity.Name;

                // create the message of the access rights change
                string msg = $"Access rights changed by '{userFromContext}' to content id {e.ContentLink}, save type: {e.SecuritySaveType}. Following changes were made: {string.Join(" ", permissions)}";

                // log also using the logger implementation
                if (Logger.IsInformationEnabled())
                {
                    Logger.Information(msg);
                }

                // the logged data to activity log
                // we could have multiple keys for example to format the data in the 'change log' view
                // now simply push everything into one key
                Dictionary <string, string> activityData = new Dictionary <string, string>
                {
                    { "Message", msg }
                };

                var activity = new ContentSecurityActivity(e.SecuritySaveType, activityData);

                var result = _activityRepository.SaveAsync(activity).GetAwaiter().GetResult();

                if (Logger.IsDebugEnabled())
                {
                    Logger.Debug($"New activity saved with id: {result}.");
                }
            }
            catch (Exception ex)
            {
                // important to handle exceptions here so that it will not cause issues in the UI even if this fails
                Logger.Error("Failed to handle content security saved event.", ex);
            }
        }
        internal static void UpdateIndex(object sender, ContentSecurityEventArg e)
        {
            Logger.Debug($"ACL changed for '{e.ContentLink}'");

            var published = VersionRepository.LoadPublished(e.ContentLink);

            if (published == null)
            {
                Logger.Debug("Previously unpublished, do nothing");
                return;
            }

            if (ContentLoader.TryGet(e.ContentLink, out IContent content))
            {
                Logger.Debug("Valid content, update index");
                EPiIndexer.Update(content);
            }
        }
예제 #7
0
 private void ContentSecuritySaved(object sender, ContentSecurityEventArg e)
 {
     _htmlCache.ContentChanged(e.ContentLink);
     _htmlCache.ChildrenListingChanged(_contentLoader.Get <IContent>(e.ContentLink).ParentLink);
 }