Change access rights for Episerver Find UI

As you probably know, Episerver Find has a UI where the editors can see statistics on how their visitors use the search functionality, fine-tune their search results by adding best-bets, related queriessynonyms and boost results as well as get an overview what kind of information is indexed in the Find Index.

To see the menu items in the Episerver Find UI, the user needs to be a member of the following roles: “WebAdmins”, “Administrators”, “SearchAdmins” and these applies to all of the views: Manage, Configure and Overview.

To start with, see if you can setup your users and roles so that only those that should have access to the Find views are has any or these roles.

But I can’t!

Ok, let’s see how we can change this!

These roles come from the property AllowedRoles from EPiServer.Find.UI.FindUIConfiguration which is registered in the IOC for EPiServer.Find.UI.IFindUIConfiguration.

finduiconfiguration

How do I change this?

If you want to change this, you’ll need to change the registration for IFindUIConfiguration to your own implementation. This is easily done as I did with a “ConfigurableModule” my previous blog post about replacing the IContentTypeAdvisor registration.

However I only want to change the property “AllowedRoles” and looking at EPiServer.Find.UI.FindUIConfiguration I can see that the property is not virtual. Hence I can’t make my custom implementation inherit from the original implementation and just override AllowedRoles.

nosuitable

That shouldn’t be a problem? Just add new or copy the entire class!

I could solve that by writing public new string[] AllowedRoles but that is rarely a good practice!

So is copying the existing class and only change the AllowedRoles property, I don’t want to check that my custom implementation is in sync every time I update Episerver Find!

So I’m gonna make sure that my custom implementation wraps the original implementation in a private field.

public class WrappingFindUIConfiguration : IFindUIConfiguration
{
    private readonly IFindUIConfiguration _originalFindUiConfiguration;

    public WrappingFindUIConfiguration()
    {
        _originalFindUiConfiguration = new FindUIConfiguration();
    }

    public string AbsolutePublicProxyPath()
    {
        return _originalFindUiConfiguration.AbsolutePublicProxyPath();
    }
}

This looks better except that I’m now always counting on that Episerver will use the Episerver.Find.UI.FindConfiguration and that it will have an empty constructor.

Reuse the original implementation

To start with, I will create a constructor in my custom implementation that takes IFindUIConfiguration as parameter and set it to the private field. This can be seen in WrappingFindUIConfiguration.

Secondly I will need to make the ConfigurableModule do some more things before replacing the registration.

  1. Find the current registration of IFindUIConfiguration
  2. Remove it from the registration
  3. Register my custom implementation and make sure to use the constructor that takes the IFindUIConfiguration parameter.

To try this out without creating roles, you can simply add a virtual role that is valid as long as the user is member of WebAdmins or Administrators:

<configuration>
    <episerver.framework>
        <virtualRoles addClaims="true">
            <providers>
                <add name="MyCustomFindRole"
                     type="EPiServer.Security.MappedRole, EPiServer.Framework"
                     roles="WebAdmins, Administrators"
                     mode="Any" />
            </providers>
        </virtualRoles>
    <episerver.framework>
<configuration>

 

Leave a comment