More in this section

Forums / Developing with Sitefinity / Intra Site - permissions

Intra Site - permissions

4 posts, 0 answered
  1. Zahid Ali
    Zahid Ali avatar
    47 posts
    Registered:
    16 Nov 2009
    25 Nov 2009
    Link to this post
    Hi,

    Can someone offer any help with regards to implementing permissions on the Intra Site module.

    I've created the contacts module following this webinar: Introduction to Sitefinity Intra-Site Module Creation - unfortunately the webinar doesn't cover the permissions topic.

    Most of the threads on this topic seem to be quite old - I need some help for the 3.7 version.

    Any help would be much appreciated. Thanks in advance.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Nov 2009
    Link to this post
    Hi Zahid Ali,

    You can download the sample contacts module for Sitefinity 3.6 architecture which has basic permissions implementation.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Zahid Ali
    Zahid Ali avatar
    47 posts
    Registered:
    16 Nov 2009
    25 Nov 2009
    Link to this post
    Hi Ivan,

    This is the example i'm currently working with - but not having much luck.

    The approach used in webinar is quite different to the one used here. Is there any guide for this bit?

    thanks.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    26 Nov 2009
    Link to this post
    Hello Zahid Ali,

    Below is  complete implementation for custom permissions for an intrasite module. You can find detailed explanation of all classes and methods from these posts.

    manager class.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Security.Permissions;
    using Telerik.Cms.Engine.Security;
    using System.Configuration;
    using Telerik;
     
    /// <summary>
    /// Summary description for TelerikManager
    /// </summary>
    public class TelerikManager : ManagerBase<BaseProvider>
     {
           public TelerikManager()
           {
           }
            
            #region Constructors
     
           public TelerikManager(string providerName)
                : base(providerName)
            {
     
            }
     
            #endregion
     
            #region Base overrides
            /// <summary>
            /// Overriden. Gets the default provider for module
            /// </summary>
            public override string DefaultProvider
            {
                get
                {
                  
                    if (!string.IsNullOrEmpty(ConfigHelper.Handler.DefaultProvider))
                        return ConfigHelper.Handler.DefaultProvider;
                    return String.Empty;
                }
            }
     
            /// <summary>
            /// Overriden. Gets the module name
            /// </summary>
            public override string ModuleName
            {
                get
                {
     
                    return "CustomTelerikModule";
                }
            }
     
             ///<summary>
             ///Gets the permissions.
             ///</summary>
             ///<value>The permissions.</value>
            public GlobalPermissions Permissions
            {
                get
                {
                    return (GlobalPermissions)TelerikManager.SecurityRoots[base.Provider.Name];
                }
            }
     
             ///<summary>
             ///Gets the security roots.
             ///</summary>
             ///<value>The security roots.</value>
            public static Dictionary<String, ISecured> SecurityRoots
            {
                get
                {
                    if (securityRoots == null)
                    {
                        securityRoots = new Dictionary<String, ISecured>(Providers.Count);
                        foreach (string name in Providers.Keys)
                            securityRoots.Add(name, new GlobalPermissions(name));
                    }
                    return securityRoots;
                }
            }
     
            /// <summary>
            /// Overriden. Gets the collection of all providers for this module
            /// </summary>
            protected override ProviderSettingsCollection ProvidersSettings
            {
                get
                {
                    return ConfigHelper.Handler.Providers;
                }
            }
     
            /// <summary>
            /// Gets the providers.
            /// </summary>
            /// <value>The providers.</value>
            public static IDictionary<String, BaseProvider> Providers
            {
                get
                {
                    if (providers == null)
                        providers = new TelerikManager().GetProviders();
                    return providers;
                }
            }
     
     
            #endregion
     
            #region Security Methods
     
            /// <summary>
            /// Gets the permission.
            /// </summary>
            /// <returns></returns>
            public GlobalPermission GetPermission()
            {
                return new GlobalPermission(this.Permissions);
            }
     
            /// <summary>
            /// Gets the permission.
            /// </summary>
            /// <param name="requestRights">The request rights.</param>
            /// <returns></returns>
            public GlobalPermission GetPermission(int requestRights)
            {
                return new GlobalPermission(this.Permissions, requestRights);
            }
     
     
            #endregion
     
            #region Private fields
     
            string providerName;
            private static IDictionary<String, BaseProvider> providers;
            private static Dictionary<String, ISecured> securityRoots;
     
            #endregion
    }

    base provider

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Configuration.Provider;
    using System.Collections.Specialized;
     
    /// <summary>
    /// Summary description for BaseProvider
    /// </summary>
    public abstract class BaseProvider : ProviderBase
    {
     
        #region Properties
     
        /// <summary>
        /// Gets the name of the security provider
        /// </summary>
        public virtual string SecurityProviderName
        {
            get
            {
                return this.securityProviderName;
            }
        }
     
        #endregion
     
        #region Initialization
     
         
        public override void Initialize(string name, NameValueCollection config)
        {
            base.Initialize(name, config);
            this.securityProviderName = config["SecurityProviderName"];
        }
     
        #endregion
     
        #region Private fields
     
        private string securityProviderName;
     
        #endregion
     
     
    }

    GlobalPermissions class

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Security.Permissions;
     
    /// <summary>
    /// Summary description for GlobalPermissions
    /// </summary>
    public class GlobalPermissions : SecuredBase
    {
        /// <summary>
        /// Initializes a new instance of <see cref="GlobalPermissions"/> class for a
        /// specified provider name.
        /// </summary>
        /// <param name="providerName">the name of the provider</param>
        public GlobalPermissions(string providerName)
        {
            // THIS WILL WORK IN CASE YOU HAVE ONE PROVIDER
            this.rootId = new Guid("E48BA2BE-B022-4949-BBE7-E70C7A14462E");
            this.securityManager = new Telerik.Security.SecurityManager();
            this.rights = TelerikRights.Instance;
        }
     
        /// <summary>Read-only property. Gets the ID of the secured object.</summary>
        /// <value><see cref="Guid"/> object.</value>
        public override Guid ID
        {
            get
            {
                return this.rootId;
            }
        }
     
        private Guid rootId;
     
    }

    GlobalPermission class

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Security.Permissions;
    using Telerik.Security;
     
    /// <summary>
    /// Summary description for GlobalPermission
    /// </summary>
    public class GlobalPermission : ApplicationPermission
    {
        /// <summary>
        ///     Initializes a new instance of the <see cref="GlobalPermission"/> class for the
        ///     specified provider name.
        /// </summary>
        /// <param name="providerName">The name of the provider for which the permissions will be checked.</param>
        public GlobalPermission(string providerName)
            : this(new GlobalPermissions(providerName))
        {
        }
     
        /// <summary>
        ///     Initializes a new instance of the <see cref="GlobalPermission"/> class with
        ///     the specified secured object.
        /// </summary>
        /// <param name="secObj"><see cref="GlobalPermissions"/> secured object.</param>
        public GlobalPermission(GlobalPermissions secObj)
            : base(secObj, 0)
        {
        }
     
        /// <summary>
        ///     Initializes a new instance of the <see cref="GlobalPermission"/> class for the
        ///     specified provider name and rights.
        /// </summary>
        /// <param name="providerName">The name of the provider for which the permissions will be checked.</param>
        /// <param name="requestedRights">The requested righths to check permissions for.</param>
        public GlobalPermission(string providerName, int requestedRights)
            : this(new GlobalPermissions(providerName), requestedRights)
        {
        }
     
        /// <summary>
        ///     Initializes a new instance of the <see cref="GlobalPermission"/> class for the
        ///     specified secured object and rights.
        /// </summary>
        /// <param name="secObj"><see cref="GlobalPermissions"/> secured object.</param>
        /// <param name="requestedRights">The requested righths to check permissions for.</param>
        public GlobalPermission(GlobalPermissions secObj, int requestedRights)
            : base(secObj, requestedRights)
        {
        }
     
        /// <summary>
        /// Checks if the current user has granted permissions.
        /// </summary>
        /// <returns>true if has permissions; otherwise false.</returns>
        public override bool CheckDemand()
        {
            if (SecurityManager.IsCurrentUserUnrestricted())
                return true;
     
            return base.CheckDemand();
        }
     
    }

    implementing custom rights

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Security.Permissions;
     
    /// <summary>
    /// Summary description for TelerikRights
    /// </summary>
    public class TelerikRights : Rights
    {
     
        //adding custom permissions
     
        [LocalRight("View")]
        public static int View
        {
            get
            {
                return 1;
            }
        }
     
     
        [LocalRight("ModifyItem")]
        public static int ModifyItem
        {
            get
            {
                return 2;
            }
        }
     
        [LocalRight("ManagePermissions")]
        public static int ManagePermissions
        {
            get
            {
                return 4;
            }
        }
     
        [LocalRight("SomethingElse")]
        public static int SomethingElse
        {
            get
            {
                return 8;
     
            }
        }
     
     
        public static TelerikRights Instance
        {
            get
            {
                return obj;
            }
        }
     
     
        private static TelerikRights obj = new TelerikRights();
     
    }


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered