More in this section

Forums / General Discussions / User Rights on pages ..

User Rights on pages ..

6 posts, 0 answered
  1. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    22 Feb 2011
    Link to this post
    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
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Feb 2011
    Link to this post
    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
  3. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    28 Feb 2011
    Link to this post
    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
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Mar 2011
    Link to this post
    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
  5. Jon
    Jon avatar
    41 posts
    Registered:
    20 Oct 2010
    01 Mar 2011
    Link to this post
    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
  6. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    08 Mar 2011
    Link to this post
    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.

    Copy Code
    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();

    All the best,
    Boyan Barnev
    the Telerik team
6 posts, 0 answered