Hello,
I defined couple of virtual roles and some permission types in the system I am working on. The virtual roles are there in order to assign permissions to the roles using Permissions for Functions. After doing these I can assign specific permissions for the user role.
<virtualRolesaddClaims="true">
<providers>
(Other Episerver roles) <addname="CustomRole"type="EPiServer.Security.MappedRole, EPiServer.Framework"roles="CustomRole"mode="Any" />
</providers>
</virtualRoles>
The virtual roles are assigned to CurrentPrinciple under runtime by adding a Claim to the user. The claim is defined as:
public static ClaimsIdentity CustomRole => new ClaimsIdentity(new[] { new Claim(ClaimTypes.Role, "CustomRole") });
And added to user by
var user = EPiServer.Security.PrincipalInfo.CurrentPrincipal as ClaimsPrincipal; user?.AddIdentity(CustomRole);
I can then query the database with
PrincipalInfo.Current.IsPermitted(CustomPermissions.Permission)
and it works as expected as long as I am logged in as Episerver admin. However, IsPermitted function returns always false if the user is anoynmous even though the user has the claim "CustomRole".
Am I missing something in order to use IsPermitted function for anonymous users?
Thanks in advance.