Copied to clipboard

Flag this post as spam?

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


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

    Custom MemberGroupService only working under "Members" but not in "Public access"

    I've implemented my owm membership/role provider and also my own IMemberGroupService by registering it in a composer like so:

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class MembersComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.RegisterUnique<IMemberGroupService, DEMemberGroupService>();
        }
    }
    

    And a my test implementation of that service:

    public class DEMemberGroupService : IMemberGroupService
    {
        public IEnumerable<IMemberGroup> GetAll()
        {
            var memberGroups = new List<MemberGroup>();
            memberGroups.Add(new MemberGroup
            {
                Name = "DE Medlem",
                Id = 0
            });
    
            return memberGroups;
        }
    
        public IMemberGroup GetById(int id)
        {
            return GetAll().FirstOrDefault(x => x.Id == id);
        }
    
        public IEnumerable<IMemberGroup> GetByIds(IEnumerable<int> ids)
        {
            return ids.Select(GetById);
        }
    
        public IMemberGroup GetByName(string name)
        {
            return GetAll().FirstOrDefault(x => x.Name == name);
        }
    
        public void Save(IMemberGroup memberGroup, bool raiseEvents = true)
        {
            throw new NotImplementedException();
        }
    
        public void Delete(IMemberGroup memberGroup)
        {
            throw new NotImplementedException();
        }
    }
    

    Now when i go to "Members -> Member Groups" i see my "DE Medlem" group just fine.

    But when i go to set "Public access" on content and choose to set "Group based", i get:

    You need to create a member group before you can use group based authentication
    

    Also the response from /umbraco/backoffice/UmbracoApi/MemberGroup/GetAllGroups looks a bit funny, but might be unrelated.

    )]}',
    []
    

    Any ideas?

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

    After a bit of searching in source, i found that Umbraco does the following before returning groups: https://github.com/umbraco/Umbraco-CMS/blob/1eb0c93e053781cc48f801a878dee3609d92bc71/src/Umbraco.Web/Editors/MemberGroupController.cs#L121

    public IEnumerable<MemberGroupDisplay> GetAllGroups()
        {
            if (_provider.IsUmbracoMembershipProvider())
            {
                return Services.MemberGroupService.GetAll()
                    .Select(Mapper.Map<IMemberGroup, MemberGroupDisplay>);
            }
    
            return Enumerable.Empty<MemberGroupDisplay>();
        }
    

    Where IsUmbracoMembershipProvider checks wether your custom provider is "UmbracoMembershipProviderBase". And since my custom membership provider was just inheriting "MembershipProvider", it didn't work.

    So inheriting UmbracoMembershipProviderBase instead, made everything work as expected.

  • Ron P 9 posts 98 karma points
    Aug 11, 2022 @ 15:46
    Ron P
    0

    Hi Chris,

    I am upgrading from v7 to v8 and was stuck in custom role provider configuration. I came across this post while googling about the issue.

    Old way of just having a proper role provider in web.config no longer works?

    <roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
      <providers>
        <clear />
        <!--<add name="UmbracoRoleProvider" type="Umbraco.Web.Security.Providers.MembersRoleProvider" />-->
        <add name="UmbracoRoleProvider" type="RFSystem.Web.DAL.RFRoleProvider" description="RF custom role provider" />
      </providers>
    </roleManager>
    

    From your post I understand that I need to create a class that inherits IMemberGroupService and then create a composer to register the class. However, I already have a role provider defined in our class library. It inherits from System.Web.Security.RoleProvider. This is useless in v8+?

    Also can you explain what you meant by the line

    So inheriting UmbracoMembershipProviderBase instead, made everything work as expected.

    As we have a custom membership provider already defined and used by other non umbraco projects.

    Thank you.

  • Christian Bekker Andersen 16 posts 126 karma points c-trib
    Aug 11, 2022 @ 16:17
    Christian Bekker Andersen
    0

    Hi Rohan

    This is a very long time ago, so things might have changed and i can't really remember the exact issue.

    But from what i can read here, it looks like i basically found that custom membership providers needed to inherit from "UmbracoMembershipProviderBase" instead of just "MembershipProvider".

    How that might affect role providers im not sure.

  • Ron P 9 posts 98 karma points
    Aug 11, 2022 @ 17:49
    Ron P
    0

    Thanks for the response.

    What version of Umbraco are you using now? Any idea if the iisue persists in the newer version. If they dont have this issue in version 9 then I might upgrade to that version instead.

Please Sign in or register to post replies

Write your reply to:

Draft