Copied to clipboard

Flag this post as spam?

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


  • Neil Marshall 10 posts 63 karma points
    Feb 03, 2010 @ 15:01
    Neil Marshall
    0

    using Umbraco membership provider from SharePoint

    Hi There,

    I understand this post may not be 100% correct in this forum however I'm going to ask the question anyway as it does involve using Umbraco and a possible bug.

    We are developing an Umbraco site for a client. They also have a Sharepoint site that some members will need to log on to. Instead of providing those users with seperate logons for both systems we want SharePoint to use the Umbraco membership provider. I was under the impression that the umbraco provider had to conform to the standard .net membership provider as umbraco can also be used with other membership providers such as the standard .net one (aspnetdb).

    I've been though all the SharePoint configuration (web config and authentication provider config within central site admin in SharePoint). Looking at the logs it appears it is trying to use the umbraco membership provider but is getting a "Object reference not set to an instance of an object" exception.

    This is the reason I'm posting the topic in this forum as I believe it is a possible problem in the umbraco.providers or umbraco.cms.businesslogic.member code. I may be completely wrong also but have tried to diagnose this and am currently downloading the source to try and fix it myself however I just thought I'd ask if anyone had any ideas!

    The SharePoint error log shows this:

    Error in searching user 'neil marshall' : System.NullReferenceException: Object reference not set to an instance of an object.     at umbraco.cms.businesslogic.member.Member.IsMember(String loginName)     at umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(String loginName)     at umbraco.providers.members.Helper.GetMemberByUsernameOrGuid(String userNameOrGuid)     at umbraco.providers.members.UmbracoMembershipProvider.GetUser(String username, Boolean userIsOnline)     at Microsoft.SharePoint.Utilities.SPMembershipProviderPrincipalResolver.ResolvePrincipal(String input, Boolean inputIsEmailOnly, SPPrincipalType scopes, SPPrincipalSource sources, SPUserCollection usersContainer)     at Microsoft.SharePoint.Utilities.SPMembershipProviderPrincipalResolver.SearchPrincipals(String... 
    02/03/2010 13:32:10.72* w3wp.exe (0x0848)                        0x1F74 Windows SharePoint Services    General                        72e7 Medium   ... input, SPPrincipalType scopes, SPPrincipalSource sources, SPUserCollection usersContainer, Int32 maxCount, Boolean& bReachMaxCount)     at Microsoft.SharePoint.Utilities.SPUtility.SearchPrincipalFromResolvers(List`1 resolvers, String input, SPPrincipalType scopes, SPPrincipalSource sources, SPUserCollection usersContainer, Int32 maxCount, Boolean& reachMaxCount, Dictionary`2 usersDict). 

    I've been through each of the method mentioned in the error entry in reverse order (as the first one mentioned is presumably where the problem lies and wanted to see the path to it) and pulled out each of them to see if I can see any problem in any of them:

            public override MembershipUser GetUser(string username, bool userIsOnline)
            {
                Member m = Helper.GetMemberByUsernameOrGuid(username);

                if (m == null)
                {
                    return null;
                }
                else
                {
                    return ConvertToMembershipUser(m);
                }
            }

    public static Member GetMemberByUsernameOrGuid(string userNameOrGuid)
            {
                Member m = null;

                // test if username is a GUID (then it comes from member core login)
                if (GuidPseudoTryParse(userNameOrGuid))
                {
                    m = new Member(new Guid(userNameOrGuid));
                }
                else
                {
                    m = Member.GetMemberFromLoginName(userNameOrGuid);
                }

                return m;
            }

    public static Member GetMemberFromLoginName(string loginName)
            {
                if (IsMember(loginName))
                {
                    object o = SqlHelper.ExecuteScalar<object>(
                        "select nodeID from cmsMember where LoginName = @loginName",
                        SqlHelper.CreateParameter("@loginName", loginName));

                    if (o == null)
                        return null;

                    int tmpId;
                    if (!int.TryParse(o.ToString(), out tmpId))
                        return null;

                    return new Member(tmpId);
                }
                else
                    HttpContext.Current.Trace.Warn("No member with loginname: " + loginName + " Exists");

                return null;
            }

            public static bool IsMember(string loginName)
            {
                Debug.Assert(loginName != null, "loginName cannot be null");
                object o = SqlHelper.ExecuteScalar<object>(
                    "select count(nodeID) as tmp from cmsMember where LoginName = @loginName",
                    SqlHelper.CreateParameter("@loginName", loginName));
                if (o == null)
                    return false;
                int count;
                if (!int.TryParse(o.ToString(), out count))
                    return false;
                return count > 0;
            }

    Thanks for any help you can provide!

  • Neil Marshall 10 posts 63 karma points
    Feb 15, 2010 @ 17:40
    Neil Marshall
    2

    Ended up solving this myself.

    Although in the web.config you are asked to provide a connection string for the umbraco Membership and Role Providers the Umbraco Membership provider seems to need the standard umbracoDbDSN and some of the other Umbraco app config settings to be added to the SharePoint web.config file.

    Once this was done it all works great. I was only able to find this out by downloading the latest umbaco source and setting breakpoints within the code when the particular methods were called from SharePoint.

    I can now create users and Groups in Umbraco and the permissions within SharePoint automatically take effect so you don't need to manage users in two places! This was the preferred option as Umbraco makes it so easy to provide users with browser editable profiles.

    Umbraco just gets sweeter and sweeter!

    Neil

     

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Feb 15, 2010 @ 17:45
    Nik Wahlberg
    0

    Cool, would you mind sharing this as code samples? Perhaps a couple of Wiki entries would be a good spot for this. We appreciate it!

    -- Nik

Please Sign in or register to post replies

Write your reply to:

Draft