Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Aleksander 43 posts 202 karma points
    May 27, 2019 @ 14:35
    Aleksander
    0

    Custom Roleprovider in Umbraco 8 - Broken ?

    Hi.

    In my umbraco 8 solution, im trying to add my own roleprovider, as i've done many times before in Umbraco 7.

    Using this as inspiration: https://24days.in/umbraco-cms/2015/extending-membership/

    My Membership is hooked up just fine. But the Roleprovider seems to be broken in umbraco 8.

    When i try to add role based access to a node, or simply inspect the Member Groups in the Members tab - no groups show up.

    I've verified that the Roles.Provider is indeed set to my custom one during startup. The Constructor is also called. But GetAllRoles are never called when i inspec member groups nor when i try to assign groupbased access..

    Did any of you guys play with the RoleProvder in Umbraco 8 ?

    Here's my code if anyone's intrested:

    public class SpiderMembershipUmbracoRoleProvider : RoleProvider 
    {
    
            public override string ApplicationName { get => "spider"; set => throw new NotImplementedException(); }
    
            public SpiderMembershipUmbracoRoleProvider()
            {
                Console.WriteLine("TEST");
            }
    
            public override string[] GetAllRoles() { return new string[] { "SpiderUsers" }; }
            public override bool IsUserInRole(string username, string roleName)
            {
                if (roleName.ToLower() == "spiderusers")
                    return true;
                else
                    return false;
            }
    
            public override string[] GetRolesForUser(string username)
            {
                return new[] { "SpiderUsers" };
            }
    
            public override void CreateRole(string roleName)
            {
                throw new NotImplementedException();
            }
    
            public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
            {
                throw new NotImplementedException();
            }
    
            public override bool RoleExists(string roleName)
            {
                throw new NotImplementedException();
            }
    
            public override void AddUsersToRoles(string[] usernames, string[] roleNames)
            {
                throw new NotImplementedException();
            }
    
            public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
            {
                throw new NotImplementedException();
            }
    
            public override string[] GetUsersInRole(string roleName)
            {
                throw new NotImplementedException();
            }
    
            public override string[] FindUsersInRole(string roleName, string usernameToMatch)
            {
                throw new NotImplementedException();
            }
    }
    

    And my web config:

        <membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
            <providers>
                <clear />
                <add name="UmbracoMembershipProvider" type="Company.Core.Members.SpiderMembershipProvider, Company.Core" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="10" useLegacyEncoding="false" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Member" passwordFormat="Hashed" allowManuallyChangingPassword="false" />
                <add name="UsersMembershipProvider" type="Umbraco.Web.Security.Providers.UsersMembershipProvider, Umbraco.Web" />
            </providers>
        </membership>
        <!-- Role Provider -->
        <roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
            <providers>
                <clear />
                <add name="UmbracoRoleProvider" type="Company.Core.Members.SpiderMembershipUmbracoRoleProvider, Company.Core" />
            </providers>
        </roleManager>
    

    Empty Member groups

  • Aleksander 43 posts 202 karma points
    May 28, 2019 @ 09:17
    Aleksander
    0

    This morning i decided to add the source code for Umbraco.Web to my project.

    I modified the default implementation of MemberRoleProvider - adding a "test" role to the GetAllRoles default implementation.

    This change wasn't noticable in the backoffice either, so it seems like it doesn't even use the MemberRoleProvider anylonger.

    Anyone has a clue which API is being called when umbraco gets the Member roles ?

  • Aleksander 43 posts 202 karma points
    May 28, 2019 @ 14:36
    Aleksander
    0

    Okay so i found the correct way to do it in Umbraco 8.

    I needed to Implement my own IMemberGroupService.

    Then During Compose in a IUserComposer i could call:

            composition.RegisterUnique<IMemberGroupService, SpiderGroupService>();
    

    now my custom usergroups shows up.

  • Matthew 2 posts 22 karma points
    Sep 17, 2019 @ 19:55
    Matthew
    0

    Can you point me at a working solution please?

    Umbraco is generally superb, but I do hate custom membership providers

  • Aleksander 43 posts 202 karma points
    Sep 18, 2019 @ 06:41
    Aleksander
    0

    the solution actually is right there in the comment.

    Create a class implementing IMemberGroupService and then create a class implementing IUserComposer and in that class's compose method make the above method call.

    just note that this is a soltion i made work on umbraco 8.0.1 i think, which is actually a hack - it was not intended to work this way, so hopefully it will be, or has been fixed (Didnt check up on it since may)

Please Sign in or register to post replies

Write your reply to:

Draft