Copied to clipboard

Flag this post as spam?

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


  • Aleksander 45 posts 205 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 45 posts 205 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 45 posts 205 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 45 posts 205 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)

  • gll 1 post 71 karma points
    Nov 22, 2019 @ 20:52
    gll
    0

    I try do this on Umbraco 8.3. It doesn't work when i try to setup Public Access for pages. List of groups is empty. But there are groups in Members/Member Groups. What should i do?

  • Christian Bekker Andersen 16 posts 126 karma points c-trib
    Aug 20, 2020 @ 13:55
    Christian Bekker Andersen
    0

    I had the same issue, with it not showing under "Publiv access". Turned out that your MembershipProvider has to inherit from UmbracoMembershipProviderBase. Else it willl return an empty list.

    https://github.com/umbraco/Umbraco-CMS/blob/1eb0c93e053781cc48f801a878dee3609d92bc71/src/Umbraco.Web/Editors/MemberGroupController.cs#L121

  • limin 27 posts 149 karma points
    Sep 17, 2021 @ 16:19
    limin
    0

    Hi I have the exact same issue that it calls "Initialize" but doesn't call "GetAllRoles" in my custom role provider, I tried your solution "implementing IMemberGroupService", but I don't understand what is the relation between your "SpiderGroupService" and your "SpiderMembershipUmbracoRoleProvider", can you please share more code? Thanks

  • Chris Spanellis 45 posts 191 karma points
    Oct 21, 2020 @ 15:23
    Chris Spanellis
    0

    Hi,

    I am using Auth0 for authentication with UmbracoIdentity, and I want to use my own data store for users and roles (basically bypass Umbraco's built-in member logic all together).

    I have the authentication piece as well as the IMemberService and IMemberGroupService pieces working so everything seems to be coming from my custom classes. However, I also made a custom MembershipProbvider, which inherits from MembersMembershipProvider, in order to inject custom implementations of IMembershipMemberService and IMemberTypeService.

    I'm unsure if my own MembershipProvider is needed, or do I just need to register those custom implementations in my IUserComposer, and the standard IdentityEnabledMembersMembershipProvider will suffice?

  • jackjen 2 posts 71 karma points
    Feb 22, 2022 @ 15:35
    jackjen
    0

    When i pulled in the Umbraco. Web source code it was working again, during this i had only implemented our own RoleProvider, which shouldn't affect anything - so i guess it was just a brief bug

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies