+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Custom Authentication, Role and Profile Providers Example

Custom Authentication, Role and Profile Providers Example

17 posts, 1 answered
  1. Daniel
    Daniel avatar
    35 posts
    Registered:
    15 Jun 2010
    13 Oct 2010
    Link to this post
    Greetings,

    Is there a working example available of how to implement custom Authentication, Role and Profile Providers? We need to use Sitefinity's one to authenticate users who have access to Sitefinity's backend and we need to use our own custom providers to allow users to register and use several private parts of the website. We also need to be able to grant permissions to the roles provided by this custom provider to the pages we create on the Sitefinity's backend. 

    I've been trying to achieve this functionality but been unable to do so so far and as such a working example of how to create these providers and associate them in sitefinity would be quite appreciated. I also would like to keep using Sitefinity's Managers with these providers and as such I can't really inherit the normal ASP.NET Providers but the inherit the Sitefinity's ones instead, correct?

    Thanks in advance,
    Daniel
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    13 Oct 2010
    Link to this post
    Hi Daniel,

    Thank you for using our services.

    You can take a look at the following webinar which explains how to create custom membership and role providers. The CMS uses ASP.NET Membership and Role providers and may also find these tutorials useful:
    Implementing a Membership Provider
    Implementing a Role Provider

    When you develop the custom providers and add them to your websites you should set the Login control's ProviderName property to be the one of your custom provider.


    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Daniel
    Daniel avatar
    35 posts
    Registered:
    15 Jun 2010
    14 Oct 2010
    Link to this post
    Hello Radoslav,

    I've successfully created my custom Role Provider by extending Sitefinity's SitefinityRoleProvider and overrided the needed methods. I've added this custom provider to the Role Provider list in Sitefinity's Administration section (Administration -> Settings -> Security -> Role Providers).

    I am, however, unable to see my provider's roles when I go to the Roles section under the Administration, the page isn't even calling the GetAllRoles method on my custom provider. On the Roles page I can only create Roles on the "Default" provider as weel it seems, since the Provider combo box only shows that option.

    Is there anything I'm missing?

    Thanks in advance,
    Daniel
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Oct 2010
    Link to this post
    Hi Daniel,

    1. Make sure that your provider is correctly registered.

    2. Application has been restarted.

    3. You have implemented

    • GetUserLinks
    • GetRoles()
    methods

    4. Your class is public

    sample

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Sitefinity.Security.Data;
     
    namespace TestProvider
    {
        public class Class3 : RoleDataProvider
        {
     
            public override Telerik.Sitefinity.Security.Model.Role CreateRole(string roleName)
            {
                throw new NotImplementedException();
            }
     
            public override Telerik.Sitefinity.Security.Model.Role CreateRole(Guid id, string roleName)
            {
                throw new NotImplementedException();
            }
     
            public override Telerik.Sitefinity.Security.Model.Role GetRole(Guid id)
            {
                throw new NotImplementedException();
            }
     
            public override IQueryable<Telerik.Sitefinity.Security.Model.Role> GetRoles()
            {
                return (new List<Telerik.Sitefinity.Security.Model.Role>()).AsQueryable();
            }
     
            public override void Delete(Telerik.Sitefinity.Security.Model.Role item)
            {
                throw new NotImplementedException();
            }
     
            public override Telerik.Sitefinity.Security.Model.UserLink CreateUserLink()
            {
                throw new NotImplementedException();
            }
     
            public override Telerik.Sitefinity.Security.Model.UserLink CreateUserLink(Guid id)
            {
                throw new NotImplementedException();
            }
     
            public override Telerik.Sitefinity.Security.Model.UserLink GetUserLink(Guid id)
            {
                throw new NotImplementedException();
            }
     
            public override IQueryable<Telerik.Sitefinity.Security.Model.UserLink> GetUserLinks()
            {
              return (new List<Telerik.Sitefinity.Security.Model.UserLink>()).AsQueryable();
            }
     
            public override void Delete(Telerik.Sitefinity.Security.Model.UserLink item)
            {
                throw new NotImplementedException();
            }
        }
    }


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Daniel
    Daniel avatar
    35 posts
    Registered:
    15 Jun 2010
    14 Oct 2010
    Link to this post
    Hello Ivan,

    I've just added the example code which you gave me into my project (changed the namespace to match my project and DLL namespace, Website.Core, and changed the class name to MyRoleDataProvider). 

    Then I recompiled the website and fully restarted my ISS server and logged into Sitefinity's Administration, gone to Administration -> Settings -> Security -> Role Providers and added my provider with the following details:

    Name: MyRoles
    Description: My Roles
    ProviderType: Website.Core.MyRoleDataProvider, Website.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

    Headed to the Administration -> Roles and I was expecting to see a new role there which I added to the GetAllRoles method but only the roles from the Default provider appear, when clicking the Add Role option it also doesn't show the MyRoles provider in the combo box. 

    I'm trusting this is the correct procedure or am I missing something important? 

    I've tried so far by extending RoleDataProvider, RoleProvider and SitefinityRoleProvider and after registering them on the Sitefinity's administration section they still won't activate.

    Thanks in advance,
    Daniel

    PS: It's now working it seems, can't figure out what I've changed though.

    Thank you very much!

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Oct 2010
    Link to this post
    Hello Daniel,

    Ok let  me know if there are any further issues.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Daniel
    Daniel avatar
    35 posts
    Registered:
    15 Jun 2010
    15 Oct 2010
    Link to this post
    Greetings,

    If I'm on the roles provider tab and I select my custom provider so that it lists only the roles on that provider I can delete a role perfectly, however if I'm under the "All" tab and I delete a role from my custom provider a success message is shown but the method Delete(Role item) isn't called at all, it's only called if I first select my provider on the providers tab.

    Is this a bug or something I'm lacking?

    Thanks in advance,
    Daniel
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Oct 2010
    Link to this post
    Hello Daniel,

    This is a bug.

    When you try to delete a role and click "delete" button we call RoleManager class and its GetRole method that gets the role with the specified identity. When you are on "All Roles" tab we use the OpenAccessRoleProvider and clicking "delete" does not do anything, because you pass a role that  does not exist in the OpenAccessRoleProvider. The role is removed from your custom provider when you are on the custom role tab, because the provider in this case is correct.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Paolo
    Paolo avatar
    147 posts
    Registered:
    11 Jun 2009
    05 Apr 2011
    Link to this post
    Hello Ivan,
    but when I'm implementing the custom membership provider should I implement

    public override IQueryable<Telerik.Sitefinity.Security.Model.Role> GetRoles()
            {
                return (new List<Telerik.Sitefinity.Security.Model.Role>()).AsQueryable();
            }

    so or if in my custom table I got roles I've to return the custom roles? same thing for the userlink?

    Thanks
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Apr 2011
    Link to this post
    Hello Paolo,

    You should return IQueryable of Role objects. I sent a reply to you in the other thread you ask similar question.

    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/simple-example-with-custom-membership-provider.aspx

    Best wishes,
    Ivan Dimitrov
    the Telerik team

  11. Leng Xiong
    Leng Xiong avatar
    9 posts
    Registered:
    13 Jun 2012
    09 Jun 2011
    Link to this post
    Hey Ivan,

    I am working on trying to get a Custom Role Provider to work as well and I am confused by the different information floating around the Telerik support site. I have created my Custom Role Provider by extending the base ASP.NET Standard Role Provider, but should I be using the Telerik Role Data Provider class instead as the example shows? Is this example an old one because the Role Provider Wrapper class was not written at the time that this was originally posted? As it is my understanding, the wrapper classes should now provide proper use of a Custom Role Provider based on the ASP.NET one?

    Thanks,

    Leng
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Jun 2011
    Link to this post
    Hi ,

    Membership and Role wrapper are now implemented, so if you have a provider based on the ASP.NET SqlMembership provider you should be able to use it with Sitefinity.Check this blog post for samples and more information.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  13. Leng Xiong
    Leng Xiong avatar
    9 posts
    Registered:
    13 Jun 2012
    14 Jun 2011
    Link to this post
    Hey Ivan,

    Thanks for providing that information.

    Leng
  14. Smilyan
    Smilyan avatar
    4 posts
    Registered:
    20 Sep 2012
    20 Sep 2012
    Link to this post
    It was possible to use a custom role provider on Sitefinity 3.x that was inheriting from System.Web.Security.RoleProvider. The provider was available when added to web.config in

    <roleManager defaultProvider="CP" enabled="true" >
       <providers>
          <clear/>
          <add name="CP" connectionStringName="" applicationName="/" type="CP.Providers.CustomRoleProvider, CP.Providers"/>
       </providers>
    </roleManager>

    Is this still possible in Sitefinity 5.x in order to reuse my old custom role provider (also keeping the Id of type Int not Guid for User and Role entities) or I can only use a custom role provider inheriting from Telerik.Sitefinity.Security.Data.RoleDataProvider?  

    Note: My attempt to reuse the old custom role provider from Sitefinity 3.x didn't lead to any success. I could only reuse the custom membership provider after passing guid to the  MembershipUser.ProviderUserKey.

  15. Smilyan
    Smilyan avatar
    4 posts
    Registered:
    20 Sep 2012
    20 Sep 2012
    Link to this post
    *
  16. Aakash
    Aakash avatar
    2 posts
    Registered:
    19 Jan 2015
    11 Feb 2015
    Link to this post
    Is there any way where we can add Profile providers in web.config?
  17. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    13 Feb 2015
    Link to this post
    Hello Aakash,

    The Profile providers could be added under:
    Administration > Settings > Advanced > UserProfiles > Create new

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
17 posts, 1 answered