Coveo for Sitecore: Security identities issue with Active Directory

Coming up on 3 months since switching to Coveo for Sitecore and everything is going very well, but I was encountering a minor nuisance issue with new employees not having permissions to access
search results on my Intranet search pages. The problem is that I’m using Active Directory for user management. With AD, the users aren’t pushed to Coveo when they are added. It has something to do with the implementation of the LDAP module. As a work around, I’ve been manually forcing a reload of security identities on Monday mornings (Control Panel --> Coveo --> Actions --> Synchronize Sitecore Permissions --> Update All). However this solution is less than ideal as I have to manually be responsible for executing this step every week. Plus if an employee started mid-week, this may not be sufficient for catching all scenarios. Working with Coveo’s excellent support team, the solution proposed was to utilize Sitecore’s URL Agent to call the Synchronizing of Sitecore Permissions. The code is really simple to write:


protected void Page_Load(object sender, EventArgs e)
        {
            if (IsOffPeak())
            {
                Reload_Coveo_Permissions();
            }
        }

        public void Reload_Coveo_Permissions(){
           Sitecore.Diagnostics.Log.Info("****Reloading Coveo permissions****", this);
           IExpandedPermissionsManager expandedPermissionsManager = new ExpandedPermissionsManager();
           expandedPermissionsManager.UpdateAllEntities();
           Sitecore.Diagnostics.Log.Info("****FINISHED loading Coveo permissions****", this);
            
        }

        public bool IsOffPeak(){
            bool isOffPeakHours = false;
            DateTime today = DateTime.Now;
            Sitecore.Diagnostics.Log.Info(string.Format("****IsOffPeak check: {0}", today), this);
            if(today.Hour < 7 || today.Hour > 19){
                isOffPeakHours = true;
            }

            return isOffPeakHours;
        }
I configured my URL Agent to run every 5 hours. However, I didn’t want it running during office hours so I added an off peak hours checker. This only allows for the code to execute between the hours of 7pm and 7am.


<agent interval="05:00:00" method="Run" type="Sitecore.Tasks.UrlAgent">
    <param desc="url" />http://<yoursitecoreinstance>/scheduledtasks/CoveoSecuritySync.aspx
    <logactivity>true</logactivity>
  </yoursitecoreinstance></agent>

Comments