Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark 255 posts 612 karma points
    Nov 20, 2013 @ 16:10
    Mark
    0

    IsProtected bug?

    Umbraco 6.1.5, Media Protect 1.1.12. Unlicensed version, running on localhost.

    In the media section I have set up role based protection on a folder. Within that folder I have a number of files. The folder and files have the icon that imply they are protected.

    I'm indexing a lucene index and have cause to add a field using GatheringNodeData. See code below (not streamlined yet as I'm testing it):

    public class ExamineEvents : IApplicationEventHandler
    {
    public ExamineEvents()
    {
    ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].GatheringNodeData += new EventHandler<IndexingNodeDataEventArgs>(ExamineEvents_GatheringNodeData);
    }

    void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
    if (e.IndexType == "content")
    {
    if (Access.IsProtected(int.Parse(e.Node.Attribute("id").Value), e.Node.Attribute("path").Value))
    {
    e.Fields.Add("IsProtected", "true");
    }
    else
    {
    e.Fields.Add("IsProtected", "false");
    }
    }
    else if (e.IndexType == "media")
    {
    if (Access.IsProtected(int.Parse(e.Node.Attribute("id").Value), e.Node.Attribute("path").Value))
    {
    e.Fields.Add("IsProtected", "true");
    }
    else
    {
    e.Fields.Add("IsProtected", "false");
    }
    }
    }

    Any protected content types are correctly assigned IsProtected=true, but all media types (protected or unprotected) are assigned IsProtected=false.

    I did try using:

    if (MediaProtect.Library.Library.IsProtected(int.Parse(e.Node.Attribute("id").Value), e.Node.Attribute("path").Value))

    for the media types, but get a null reference exception. I think because IsProtected calls umbraco.library.IsProtected method, which requires HttpContext. But I'm not sure of this.

    MediaProtect.Access.MediaAccess.IsProtected()

    The above method also fails with null reference exception.

    Is there some other way to check if a node is protected whilst running an Examine / Lucene indexing operation?

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 20, 2013 @ 17:17
    Richard Soeteman
    0

    Hi,

    This is weird. There will be a call to umbraco.library.IsProtected indeed but only when item is of type content. But Media protect uses HTTPContext internally also so that might be the issue. So you are saying that you can't use HTTPContext when indexing using Examine?

    Thanks,

    Richard

  • Mark 255 posts 612 karma points
    Nov 20, 2013 @ 18:10
    Mark
    0

    Making any call to the MediaProtect API is causing a null reference exception when calling IsProtected against a media item within the Examine GatheringNodeData event. We need to add an indexing property to show if a media item is protected or not. Perhaps there is another way to do this?

  • Mark 255 posts 612 karma points
    Nov 20, 2013 @ 18:14
    Mark
    0

    @Richard could we make a database call directly?

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 20, 2013 @ 19:11
    Richard Soeteman
    0

    Hi Mark,

    Will add this to my list to implement also(will not be in the next few days/weeks sorry). I like the way you want to solve this. Most customers I have use the IsProtected method when rendering the overview. This is because you can change the protection without saving the node. Also possible for you to use maybe?

    But protected data is stored in app_data/mediaaccess.config file. Also possible to use that, but not ideal I think.

    Best,

    Richard

  • Mark 255 posts 612 karma points
    Nov 21, 2013 @ 00:47
    Mark
    0

    Hi Richard,

    That's a shame. I was following this post which said it was possible to do what I wanted to do with MediaProtect. I'll have to come up with a work around as I can't wait, unfortunately. Anyway, thanks for coming back to me.

    Mark

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 21, 2013 @ 04:57
    Richard Soeteman
    0

    Hi Mark,

    Did you try that exact method also in that blogpost?

    Thanks,

    Richard

  • Mark 255 posts 612 karma points
    Nov 21, 2013 @ 09:50
    Mark
    0

    Hi Richard,

    The method MediaProtect.Library.AllowedGroups() isn't there. But there is a static MediaProtect.Library.Library.AllowedGroups() method, which is the one I'm trying to use. The method gives the same error as MediaProtect.Library.Library.IsProtected():

    System.NullReferenceException was unhandled
    HResult=-2147467261
    Message=Object reference not set to an instance of an object.
    Source=MediaProtect
    StackTrace:
    at MediaProtect.Configuration.Config.get_MediaAccessFile()
    at .()
    at .(Int32 )
    at MediaProtect.Access.MediaAccess.AllowedGroups(Int32 mediaId, String path)
    InnerException:

    I assume this is the same problem. Is there another way to call those methods? Maybe an instance method rather than static?

    Thanks,
    Mark

  • Mark 255 posts 612 karma points
    Nov 21, 2013 @ 10:16
    Mark
    0

    Strangely, it looks like umbraco.cms.businesslogic.web.Access.IsProtected() method does access httpcontext, so maybe there is something else going on. Although maybe the umbraco method isn't hitting httpcontext because it's accessing a cache...

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 21, 2013 @ 11:08
    Richard Soeteman
    0

    Hi Mark,

    That's the method to use Mediaprotect.Libary is used in XSLT which came before razor. But the HTTPContext is in another method that is used by the library. I think I can rid of the HTTPContext in my own library but it makes calls to Umbraco also.

    But still weird that HTTPContext is throwing exceptions in this index methods.

  • Mark 255 posts 612 karma points
    Nov 21, 2013 @ 11:25
    Mark
    0

    Maybe it isn't httpcontext. Are you able to reproduce the issue?

    Added toExamineIndex.config:

     <IndexSet SetName="SiteSearchIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/SiteSearch/" />

    Added to ExamineSettings.config:

    <add name="SiteSearchIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
    supportUnpublished="false"
    supportProtected="true"
    analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
     <add name="SiteSearchSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" />

    Added this class (uncomment the commented line, also add reference to MediaProtect.dll):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Umbraco.Core;
    using Examine;
    using umbraco.cms.businesslogic.web;

    namespace MyNameSpace
    {
        public class ExamineEvents : IApplicationEventHandler
        {
            public ExamineEvents()
            {
                ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].GatheringNodeData += new EventHandler(ExamineEvents_GatheringNodeData);
            }

            void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
            {
                if (e.IndexType == "content")
                {
                    if (Access.IsProtected(int.Parse(e.Node.Attribute("id").Value), e.Node.Attribute("path").Value))
                    {
                        e.Fields.Add("IsProtected", "true");
                    }
                    else
                    {
                        e.Fields.Add("IsProtected", "false");
                    }
                }
                else if (e.IndexType == "media")
                {
                    //if (MediaProtect.Access.MediaAccess.IsProtected(int.Parse(e.Node.Attribute("id").Value), e.Node.Attribute("path").Value))
                    if (Access.IsProtected(int.Parse(e.Node.Attribute("id").Value), e.Node.Attribute("path").Value))
                    {
                        e.Fields.Add("IsProtected", "true");
                    }
                    else
                    {
                        e.Fields.Add("IsProtected", "false");
                    }
                }
            }

            public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
               
            }

            public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
               
            }

            public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
               
            }
        }
    }

    I'd like to make sure I'm not doing something wrong...

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 21, 2013 @ 11:55
    Richard Soeteman
    0

    Hi Mark,

    I'll setup a dev environment to reproduce thanks for the detailed instructions.

    Thanks,

    Richard

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 21, 2013 @ 12:15
    Richard Soeteman
    0

    Hi Mark when trying to compile I get the following error

    Error 1 No overload for 'ExamineEvents_GatheringNodeData' matches delegate 'System.EventHandler' f:\temp\examinetest\MediaProtectExamine\MediaProtectExamine\ExamineEvents.cs 15 103 MediaProtectExamine

    This error is in the constructor

      public ExamineEvents()
            {
                ExamineManager.Instance.IndexProviderCollection["SiteSearchIndexer"].GatheringNodeData += new EventHandler(ExamineEvents_GatheringNodeData);
            }
    

    Any ideas? Also possible to mail me [email protected]

    Thanks,

    Richard

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 22, 2013 @ 06:56
    Richard Soeteman
    0

    Going back and forth with Mark. The issue was related to the use of HTTPContext in Media protect library indeed. V1.5.1 will solve this.

  • Mark 255 posts 612 karma points
    Nov 22, 2013 @ 10:58
    Mark
    0

    @Richard - thanks for all your help. Problem solved. I'll mark your answer. I'll also order a Media Protect license for this project shortly.

    Mark

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 22, 2013 @ 11:03
    Richard Soeteman
    0

    Hi Mark,

    Thanks for both!

    Best,

    Richard

  • Michael Chart 15 posts 35 karma points
    Apr 29, 2014 @ 12:20
    Michael Chart
    0

    Hi Richard,

    Is v1.5.1 available yet? We are seeing the same issue in our GatheringNodeData event, in a call to MediaProtect.Library.Library.IsProtected.

    Thanks,

    Mike

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Apr 30, 2014 @ 08:12
    Richard Soeteman
    0

    Hi Michael,

    I thought it was released already but it isn't sorry. I will release it next week. If you need the package before send me an email please [email protected] and I'll send it.

    Best,

    Richard

  • Nils Frank 19 posts 89 karma points
    Mar 09, 2017 @ 14:43
    Nils Frank
    0

    Hi

    Im having the same problem, but im running MediaProtect on version 2.0

    I get: The value should not be null. Parametername: httpContext

    On this piece of code inside the GatheringNodeData event:

    bool isProtected = Library.IsProtected(node.Id, node.Path);
    

    Is there anything im missing? Or is this broken again?

    Best regards

    Nils

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Mar 10, 2017 @ 06:56
    Richard Soeteman
    0

    Hi,

    Did you upgrade from a previous version? Mediaprotect V2 just instatiates the concrete object without loading dll's so I am curious what is causing this?

    Best,

    Richard

  • Nils Frank 19 posts 89 karma points
    Mar 10, 2017 @ 07:21
    Nils Frank
    0

    Hi Richard,

    we only installed it from the NuGet Store, so no upgrades.

    Best regards Nils

  • Mário Nunes 7 posts 87 karma points
    Aug 22, 2017 @ 17:28
    Mário Nunes
    0

    Hello,

    I'm having this same issue on Umbraco 7.65 and MediaProtect 2.0.0.
    I'm calling AllowedGroups to add properties to my Examine document index.
    I noticed that after I lauch the site, I can save a file as many times as I want and it's ok. When I try to save another file, I get the error. It's not file related, tested with different files. The error occurs always when I rebuild the index, even on the first file (iteration).

    System.ArgumentNullException occurred
      HResult=0x80004003
      Message=Value cannot be null.
    Parameter name: httpContext
      Source=MediaProtect.Core
      StackTrace:
       at MediaProtect.Core.Helpers.ContextHelper.EnsuredContext()
       at MediaProtect.Access.MediaAccess.AllowedGroups(String fileName)
       at MediaProtect.Library.Library.AllowedGroups(String fileName)
       at CRT.SocialIntranet.Web.Utils.AppEvents.GatheringContentDocumentsData(Object sender, IndexingNodeDataEventArgs e, UmbracoHelper helper) in path 253
       at path.<>c__DisplayClass2_0.<OnApplicationStarted>b__5(Object sender, IndexingNodeDataEventArgs e) in path:line 71
       at Examine.Providers.BaseIndexProvider.OnGatheringNodeData(IndexingNodeDataEventArgs e)
       at UmbracoExamine.UmbracoContentIndexer.OnGatheringNodeData(IndexingNodeDataEventArgs e)
       at Examine.LuceneEngine.Providers.LuceneIndexer.GetDataToIndex(XElement node, String type)
       at Examine.LuceneEngine.Providers.LuceneIndexer.ProcessIndexQueueItem(IndexOperation op, IndexWriter writer)
       at Examine.LuceneEngine.Providers.LuceneIndexer.ProcessQueueItem(IndexOperation item, ICollection`1 indexedNodes, IndexWriter writer)
       at Examine.LuceneEngine.Providers.LuceneIndexer.ForceProcessQueueItems(Boolean block)
    

    Thanks,
    Mário

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Aug 22, 2017 @ 20:44
    Richard Soeteman
    1

    Mediaprotect needs HTTPContext which is not available in Examine. You can request acces rights at runtime.

    Hope this helps,

    Richard

  • Mário Nunes 7 posts 87 karma points
    Aug 23, 2017 @ 10:52
    Mário Nunes
    0

    Hi,

    That helped!

    I was able to instantiate the HttpContext with a call to UmbracoContext.EnsureContext(helper.UmbracoContext.HttpContext, ... )
    Although, it would be much cleaner if I could pass helper.UmbracoContext.HttpContext as a parameter to an overload of your functions. Would that be possible?

    Thanks,
    Mário

Please Sign in or register to post replies

Write your reply to:

Draft