User Rights on pages ..
Hi,
How do I check programtically to see who the current user is ...For example who is logged in. I also need to know through the API how I check to see if a user has the rights to view a page. For example, if user A has the right to view page X. Can you please provide an example on these two things.
1. how to get the current user
2. how to check to see if the user has rights to view a particular page.
Thanks in advance.
jon
Hello Jon,
1. You can use SecurityManager.GetCurrentUser() method.
2. The PageNode implements ISecuredObject, so you can call pagenode.Permissions to to get all permissions for a given page. There is extension method IsGranted that you can use to check permissions for a given user
You can take a look at our dev manual - Security section.
All the best,
Ivan Dimitrov
the Telerik team
ISecured Object doesn't let me pass in a page name. What I need to do is check to see if user X has permissions on a certain page. For example, does user 1 have View persmissions on page X...
How do I do this using the API ?
Thanks in advance,
jon
Hi Jon,
First you need to get the PageNode. You can use the fluent or standard API to do this. Please make sure that you have reference to using Telerik.Sitefinity.Security. IsGranted is an extension. It has 4 overloads, so you can pass the secured object and the principal in one of them
IsGranted(this ISecuredObject item, string permissionSet, Guid[] principals, int actions)
Best wishes,
Ivan Dimitrov
the Telerik team
Could you provide a code example of checking to see if a user has view rights on a specific page. Its still not clear...
Thanks in advance.
Jon
Hello Jon,
Please see the below attached code sample, showing how to get all Pages that a certain Role has View rights to. I hope it gives you a hint on how to achieve the desired functionality.
var fluent = App.WorkWith();
var roleManager = RoleManager.GetManager(
"AppRoles"
);
var everyoneRole = roleManager.GetRole(
"Everyone"
);
SecurityConfig cfg = Config.Get<SecurityConfig>();
var permSet = cfg.Permissions[SecurityConstants.Sets.Pages.SetName];
int
actionMask = permSet.Actions[SecurityConstants.Sets.Pages.View].Value;
var pages = fluent.Pages().Where(page => page.IsGranted(SecurityConstants.Sets.Pages.View,
new
Guid[] everyoneRole.Id , actionMask)).Get();