The restrictions on the creation of the roles is hardcoded into the "Create Role" dialog box. You have a couple of options to work around this.
Directly at database level
Create the roles as you normally would using spaces, then update the role name with hyphens in the aspnet_Roles
table in the core
database:
UPDATE [dbo].[aspnet_Roles]
SET [RoleName] = 'sitecore\role-with-hyphen',
[LoweredRoleName] = 'sitecore\role-with-hyphen'
WHERE [RoleName] = 'sitecore\role with spaces'
In most cases, creating Roles will not be a frequent task, so updating the database directly should not be an issue. Additionally, you can package up roles and security using the Sitecore Package Designer and/or they should be serialized using TDS or Unicorn.
Override the Create Role dialog
If you are uncomfortable updating SQL tables directly, then you can override the Create Role dialog.
- Make a copy of
website\sitecore\shell\Applications\Security\RoleManager\NewRole.xaml.xml and place it in the website\sitecore\shell\Override folder
- Edit the file and change the
inherits
attribute to your own class, e.g. <Sitecore.Shell.Applications.Security.RoleManager.NewRole x:inherits="MyProject.Custom.Security.RoleManager.NewRolePage,MyProject.Custom">
- Create a class, inherit from
Sitecore.Shell.Applications.Security.RoleManager.NewRolePage
and override the OK_Click
method.
public class NewRolePage : DialogPage
{
protected override void OK_Click()
{
string text = this.Name.Text;
if (!SecurityUtil.IsValidRoleName(ref text)) /* update this check with the requierd logic */
{
SheerResponse.Alert("The role name \"{0}\" contains illegal characters.\n\nThe role name can only contain the following characters: A-Z, a-z, 0-9, ampersand and space.", new string[1]
{
text
});
}
else
{
SheerResponse.SetDialogValue("{0}\\{1}".FormatWith((object) this.Domain.SelectedValue, (object) text));
base.OK_Click();
}
}
}
Assigning Security
These solutions have not been thoroughly tested, and it would be wise to heed the advice the Mark provided in his answer, but the following is possible:
- Roles can be deleted, with or without hyphens
- Roles can be assigned to other roles without or without hyphens (Role in Roles)
- Access can be assigned to item using Security Editor and viewed using the Access Viewer
- Roles can be packages using the Package Designer and then installed using the Installation Wizard
I have tested this in Sitecore 8.1 update-1 and Sitecore 8.2 update-6.
The main area of caution would be any unexpected exceptions connected with internal implementation, but note that Sitecore stores Permission details against items as a string. If you had roles set up in Active Directory with hyphens for example, then Sitecore would use the role name (i.e. not use a GUID as an identifier).
However, all that said, since these are roles in Sitecore which you have control over, then I highly recommend you forgo the use of hyphens in role names and just use spaces. Since you mention "membership and roles database that is used in multiple applications", I highly recommend you do not apply security against non-Sitecore roles. Instead, create a [matching] role in Sitecore, apply security to this role, and then make the external role a member of this role.