More in this section

Forums / Developing with Sitefinity / Custom Membership Provider...

Custom Membership Provider...

5 posts, 0 answered
  1. Timothy Masson
    Timothy Masson avatar
    7 posts
    Registered:
    17 Oct 2004
    06 Jul 2007
    Link to this post
    Hi,
    I have a unique requirement that users be able to authenticate against an existing datastore, or the sitefinity store. I realized that in order to accomplish this, I could simply override the ValidateUser function of the Telerik Membership provider in Telerik.DataAccess.ASPNetProviders.TelerikMembershipProvider. I wrote the following code to wrap it up:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Telerik.DataAccess.AspnetProviders;
    using System.Web.Security;
    using System.Configuration;

    namespace FOOWebSecurity
    {
        public class FOOMembershipProvider : Telerik.DataAccess.AspnetProviders.TelerikMembershipProvider
        {
            public override bool ValidateUser(string username, string password)
            {
                bool success = base.ValidateUser(username, password);
                if (success)
                    return success;
                else
                {
                    //...custom validation for FOO...
                }

            }

        }
    }

    and set the web.config file to use the new membership provider dll.

    It compiles, the site runs, but when I log into the admin page -using a sitefinity account (not a custom one) - the admin page doesn't load certain controls.
    Essentially, in the Sitefinity/Admin/Default.aspx.cs page, the following line fails
    the perm.CheckDemand:

    Telerik.Cms.Security.GlobalPermission perm =

    new Telerik.Cms.Security.GlobalPermission(Telerik.Cms.Security.GlobalRights.ManageUsers);

    if (perm.CheckDemand())

    {

    // Dashboard box 3 - Users

    inTrayInfo = new UsersInTrayInfo("Users", "Recently registered");

    inTrayInfo.SortBy = "CreationDate";

    inTrayInfo.SortDirection = System.ComponentModel.ListSortDirection.Descending;

    dbbUsers.DataSource = inTrayInfo.GetAsDataSource();

    dbbUsers.DataBind();

    }


    I have no idea why that would fail, given that for a sitefinity account, my provider still calls all the telerik functionality.

    Any ideas, comments or suggestions you have are appreciated.
    Thanks,
    -T
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    06 Jul 2007
    Link to this post
    Hi Timothy,

    We don't see any problems with your custom Membership Provider implementation.

    As for the CheckDemand() failure, it could be caused by the fact that the user does not have appropriate permissions for the specified right. However, there is a known issue with checking the user permissions when the Role Provider for Cms users is not set as a default provider in the web.config. So please make sure that the role provider with name 'Sitefinity' is set as default. We will try to provide a workaround for this issue soon.

    Also please note, that by default the name of the Membership providers used for Cms users is 'Sitefinity'. This is defined in the Security section:

    <telerik>
        <security defaultProvider="DefaultSecurityProvider" cmsProvidersName="Sitefinity">

    So make sure that the name of your custom Membership provider is 'Sitefinity' in the web.config.

    Sincerely yours,

    Vlad
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  3. Timothy Masson
    Timothy Masson avatar
    7 posts
    Registered:
    17 Oct 2004
    06 Jul 2007
    Link to this post
    The naming of the membership provider in the web.config seems to have been the problem. I just renamed my membership provider to Sitefinity from FOOWebSecurity, and it works like a charm.

    Thanks,
    -T
  4. Timothy Masson
    Timothy Masson avatar
    7 posts
    Registered:
    17 Oct 2004
    06 Jul 2007
    Link to this post
    Just a clarifiying question:  when you write "However, there is a known issue with checking the user permissions when the Role Provider for Cms users is not set as a default provider in the web.config" does that mean that I can't roll my own roll provider?
    Since i'm going to be authenticating users from another datastore, I'll need to roll my own roll provider so that I can provide rolls from the other datastore, as well as the sitefinity datastore. Will this be a problem, given you statement above?
    Thanks again,
  5. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    09 Jul 2007
    Link to this post
    Hi Timothy,

    The known issue which I meant in my previous post is that Sitefinity does not handle multiple Role providers. This is because the ASP.NET doesn't support this functionality out of the box. 
    In other words, when a user is authenticated in the system, an authentication cookie is created for the user, but the cookie does not contain any information about the roles data store. So in the next request a RolePrincipal object is created from the cookie and assigned to the current user (HttpContext.Current.User) and the RolePrincipal is always created for the default RoleProvider.
    The workaround is to create a RolePrincipal manually after authentication specifying RoleProvider name in the constructor and assign it to HttpContext.Current.User. We will provide this implementation in the Login page soon.

    Regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
5 posts, 0 answered