Insights

How To Clone A Security Role In Sitecore

Cloning A Security Role In Sitecore

Let's face it, at some point in your Sitecore career you will be asked to "clone" a security role. And by that, I mean creating a new group with the same memberships as another.

This might not seem like much and in most cases, you can do this with a few clicks. What if the role you're "cloning" has 30+ memberships as you are utilizing AD role integration? Uh yeah, no thank you. It'd be a tedious process and we don't have the time for that.

Steps To Clone A Security Role

So out-of-the-box Sitecore does not have any method for cloning which is unfortunate but this method I've found to make it easier. I should note, that before doing any of these changes I fully recommend taking a snapshot/package of your existing security roles prior to doing the change.

Step 1

Create the new role you want. It's important to have the role in the system before proceeding.

Step 2

Open up the Role Manager, and on the right side click Serialize All Roles. This will store all the roles, in text files, under \App_Data\serialization\security.

Sitecore Role Manager - Serialize All Roles

Step 3

If you open up one of these roles, you'll see two pieces of data. The name and the rolename. The name pertains to the role you're looking at. And rolename is the member of that role.

----role----
name: sitecore\Sitecore Client Users

----role-in-role----
rolename: sitecore\Analytics Content Profiling

----role-in-role----
rolename: sitecore\Analytics Maintaining

----role-in-role----
rolename: sitecore\Analytics Personalization

----role-in-role----
rolename: sitecore\Analytics Reporting

----role-in-role----
rolename: sitecore\Analytics Testing

It's important to understand that the membership for what a role is a part of is not stored in that custom group but rather as a member of the role it's in. Feels a bit backwards we know, but that's how it's done.

For example. If you have a custom role that's a member of 20 other roles, if you were to open up that custom role you won't see anything listed other than the name. You have to open up each role it's a member of to see it listed, which is why cloning is such a pain.

Step 4

So how does cloning work? Good old search and replace. For example, if the role you are cloning is called sitecore\Custom Role A and the role you created in Step 1 is called sitecore\Custom Role B you're going to do a search and replace it in files. Tools like Notepad ++ and VS Code have this capability.

Search for:

----role-in-role----
rolename: sitecore\Custom Role A

Replace within files:

----role-in-role----
rolename: sitecore\Custom Role A

----role-in-role----
rolename: sitecore\Custom Role B

This will add Custom Role B to all the security roles that Custom Role A is a member of.

Now we just need to get it back into Sitecore.

Step 5

Open up Role Manager again and this time click Revert All Roles. It will prompt you what the import will do.

Sitecore Role Manager - Revert All Roles

Once the process is done, open up the membership of your new role and you should see all the roles it's a member of listed.

👋 Hey Sitecore Enthusiasts!

Sign up to our bi-weekly newsletter for a bite-sized curation of valuable insight from the Sitecore community.

What’s in it for you?

  • Stay up-to-date with the latest Sitecore news
  • New to Sitecore? Learn tips and tricks to help you navigate this powerful tool
  • Sitecore pro? Expand your skill set and discover troubleshooting tips
  • Browse open careers and opportunities
  • Get a chance to be featured in upcoming editions
  • Learn our secret handshake
  • And more!
Sitecore Snack a newsletter by Fishtank Consulting
 

Meet David Austin

Development Team Lead | Sitecore Technology MVP x 3

📷🕹️👪

David is a decorated Development Team Lead with Sitecore Technology MVP and Coveo MVP awards, as well as Sitecore CDP & Personalize Certified. He's worked in IT for 25 years; everything ranging from Developer to Business Analyst to Group Lead helping manage everything from Intranet and Internet sites to facility management and application support. David is a dedicated family man who loves to spend time with his girls. He's also an avid photographer and loves to explore new places.

Connect with David