SaaS CMS has officially launched! Learn more now.

Problems with EntitySecurityHandler.Instance.AccessRightsSet


Im working on getting EPiServer Find to index the community entities but im having problems with reindexing when access rights is changed. When a group is added to the access rights i would like that to be added to the index right away.

I have tried to add an eventhandler to EntitySecurityHandler.Instance.AccessRightsSet and EntitySecurityHandler.Instance.AccessRightsRemoved but it seems that the changes that was made is not there at that point.

My code looks something like this:

            EntitySecurityHandler.Instance.AccessRightsSet += InstanceOnAccessRightsSet;

        private void InstanceOnAccessRightsSet(IEntityEventArgs args)
            var forum = args.Entity as Forum;
            if (forum == null)


I did a bit of decompiling and dug around in EPiServers code it seems that the AccessRightsSet event is triggered after the update of the accessrights but before the database cache is invalidated and the entity that is sent to the eventhandler is the exact same as before the change in access rights.


    public virtual void SetAccessRights(ISecurableEntity securableEntity, IGroup group, IAccessRights rights)
      EntityValidator.ValidateIsCommittedEntity((IEntity) securableEntity, "securableEntity");
      EntityValidator.ValidateIsCommittedEntity((IEntity) group, "group");
      EntityValidator.ValidateIsNotNull((object) rights, "rights");
      EntitySecurityFactory.Instance.SetAccessRights(securableEntity, group, rights);
      CacheHandler.Instance.RemoveCachedObject("EPiServer Common", "GetAccessRights", ServiceLocator.Current.GetInstance<IEntityTypeResolver>().GetTypeID(securableEntity.GetType(), false).ToString(), securableEntity.ID.ToString(), "group", group.ID.ToString());
      CacheHandler.Instance.RemoveCachedObject("EPiServer Common", "GetOwnerGroups", IEntityTypeResolverExtensions.GetTypeName(ServiceLocator.Current.GetInstance<IEntityTypeResolver>(), securableEntity.GetType()), securableEntity.ID.ToString());


    protected internal virtual void SetAccessRights(ISecurableEntity securableEntity, IGroup group, IAccessRights rights)
      IDatabaseHandler databaseHandler = ServiceLocator.Current.GetInstance<IDatabaseHandler>();
      databaseHandler.ExecuteTransaction((Action) (() =>
        IDatabaseHandlerExtensions.ExecuteNonQuery(databaseHandler, "spEPiServerCommonEntitySecuritySetGroupAccessRights", (object) IEntityTypeResolverExtensions.GetTypeID(ServiceLocator.Current.GetInstance<IEntityTypeResolver>(), securableEntity.GetType()), (object) securableEntity.ID, (object) group.ID, (object) rights.AccessLevel);

Anyone got any ideas on how to get around this?

Jan 10, 2013 10:41

As a workaround, can't you refresh the object in your event handler? Call CacheHandler.RemoveCachedObject in a way similar to what EntitySecurityHandler.SetAccessRights does, and then re-load the entity instead of using the instance you get with the eventargs.

Jan 23, 2013 14:19
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.