Gravatar for na@alpha-solutions.us

Question by niket, Aug 27, 2015 6:48 PM

How to programatically update security cache?

In coveo for sitecore, is there a way to trigger security cache update when a new user account is created? I have already defined a schedule (every 5 mins) but am wondering if it can be done through code.

1 Reply
Gravatar for slangevin@coveo.com

Answer by Simon, Aug 28, 2015 9:27 AM

Hi,

The best way to affect the service through code is using the Admin Service. If you are using Coveo for Sitecore, then the Admin Service is already installed on your CES machine, you can access the service through port 80, or 443 if you secured it.

http://localhost/AdminService

Add the ?wsdl extension to see the list of functions available.

This said, I am not helping your case since Security cache update is not one of them! But now you know :P

There is already an idea to add it, you can go and vote for it.

Oh, but you need it now right?

Here is a workaround for now, create a vbs file and paste the following:

Option Explicit

Dim Admin: Set Admin = GetAdmin()
Admin.UpdateFileSecurityCache(true)

Function GetAdmin()
  Set GetAdmin = CreateObject("CESAdmin.Admin.7.0")
  Call GetAdmin.Connect("localhost", "default")
  Call GetAdmin.Refresh()
End Function

Simply call this script through code and the cache will refresh.

Cheers,
Simon

Gravatar for slangevin@coveo.com

Comment by Simon, Sep 27, 2016 6:17 PM

Coveo for Sitecore is now using handlers to do the above automatically:

https://developers.coveo.com/display/SitecoreV4/Updating+Security+Cache

If you still wish to go the code way, the Idea mentioned above (to use the Admin Service) is now part of the product. On-Premises, you can now use the Coveo Admin Service. Here is a sample snippet:

public static void CallWebService() 
{ 
  CesMasterInformation ces = new CesMasterInformation(); 
  ces.AcceptedConnections = new CesAcceptedConnection[1]; 
  ces.AcceptedConnections[0] = new CesAcceptedConnection(); 
  ces.AcceptedConnections[0].ConnectionComponent = "ADMIN"; 
  ces.AcceptedConnections[0].ConnectionType = "CMF"; 
  ces.AcceptedConnections[0].ConnectionPort = 52800; 
  ces.Id = "default"; 

  BasicHttpBinding binding = new BasicHttpBinding(); 
  EndpointAddress address = new EndpointAddress("http://[myCoveoServer]/AdminService"); 
  AdminServiceClient client = new AdminServiceClient(binding, address); 

  string descriptor = ""; 
  string securityProvider = "Sitecore Security Provider for myMachine"; 

  client.UpdateSecurityEntity(ces, descriptor, securityProvider); 
} 

1- You will first need to add a Service Reference to your project. Simply add the url of the Admin service : "http://[myCoveoServer]/AdminService". You will then have an AdminService class that you will be able to add to your class, example:

using MyProject.AdminService;

2- The first part of the code creates a CES obejct, you can keep it this way.

3- The second part will create the connection to your Admin Service, do not forget to change the EndpointAddress to the name of your coveo server.

4- The last part creates the descriptor and the Security Provider. In your case, the security Provider will mostly stay the same, but the descriptor will have to be dynamic depending on which role your user changed. There are two types of Descriptor, User and Group. They usually respect the same pattern as in Sitecore but you can use the Content/Security Browser of the Coveo Administration Tools to validate.

Ask a question