Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsAuthenticationAuthenticationDocumentation?Documentation?
Previous
 
Next
New Post
2/28/2008 8:26 PM
 

Hi All

I need to write a provider that authenticates users against another SQL DB. I assume after successful authentication you need to create the user in the DNN DB.

Is there any documentation on how to write a new authentication provider, eg what API or interfaces one must make available in the provider? I appreciate the availability of the live id source code, but I think that code is NOT a good documentation. What is needed is some overview of the architecture and guidelines on how to write your own.

Felix Burkhard

 

 

 
New Post
2/29/2008 10:44 AM
 

Hi Felix

There isn't a white-paper on writing a provider and it's something that does need to be done (I just don't know when I'll get to it). However you've got gist of it (authenticate then create/login the user in the DNN DB). Writing a provider isn't all that different than writing any module until it comes to the login/settings/logout pages where you're overriding the core procedures.

 
New Post
3/4/2008 3:35 PM
 

All I have is an example and this isn't exactly what you're asking for but I had to do something similar. What I did was left DDN as the source for users and roles and synchronized them with my other system. To do this just inherit the DNN providers and only override the methods you need. It works great if you put a checks in place like when adding a user to a role check the existence of both the user and the role in the other system first and create them if they don’t exist. Also, note that in the code below I was calling web services with no support for transactions. If your making database calls or something else that supports transactions you’d probably want to make your call to the other system first and commit or rollback based on whether the DDN call succeeds.

Membership Provider:

 
using System;
using System.Web;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Framework.Providers;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Security.Membership;

namespace BMT.Security.Membership
{
    public class BmtAspNetProvider : DotNetNuke.Security.Membership.AspNetMembershipProvider
    {


        public override Boolean ChangePassword(UserInfo user, String oldPassword, String newPassword)
        {

            DotNetNuke.Entities.Users.UserInfo curUserInfo;

            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();


            HttpContext Context = HttpContext.Current;

            Boolean retVal;

            //change password first in dnn to make sure it's valid
            retVal = base.ChangePassword(user, oldPassword, newPassword);

            if (retVal == true)
            {
                try
                {

                    //your code here

                }
                catch (Exception e)
                {

                    //your code here

                }
            }

            return retVal;

        }

        public override UserCreateStatus CreateUser(ref UserInfo user)
        {

            DotNetNuke.Entities.Users.UserInfo curUserInfo;
            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

            HttpContext Context = HttpContext.Current;

            UserCreateStatus uStatus = base.CreateUser(ref user);


            if (uStatus == UserCreateStatus.Success)
            {
                try
                {

                    //your code here

                }
                catch (Exception e)
                {

                    //your code here

                }

            }

            return uStatus;

        }

        public override void UpdateUser(UserInfo user)
        {

            DotNetNuke.Entities.Users.UserInfo curUserInfo;
            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

         
            HttpContext Context = HttpContext.Current;

            try
            {

                //your code here

            }
            catch (Exception e)
            {

                //your code here

            }

            base.UpdateUser(user);

        }

        public override string ResetPassword(UserInfo user, string passwordAnswer)
        {

            DotNetNuke.Entities.Users.UserInfo curUserInfo;
            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

            HttpContext Context = HttpContext.Current;

            String newPassword;
            newPassword = base.ResetPassword(user, passwordAnswer);

            try
            {

                //your code here

            }
            catch (Exception e)
            {

                //your code here

            }

            return newPassword;

        }
       
        public override bool DeleteUser(UserInfo user)
        {

            try
            {

                //your code here

            }
            catch (Exception e)
            {

                //your code here

            }

            return base.DeleteUser(user);
        }
       
    }
}

 

Role Provider:

using System;
using System.Web;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Framework.Providers;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Security.Membership;

namespace BMT.Security.Membership
{
    public class BMTRoleProvider : DotNetNuke.Security.Membership.DNNRoleProvider
    {

        public override bool CreateRole(int portalId, ref RoleInfo role)
        {

            DotNetNuke.Entities.Users.UserInfo curUserInfo;
            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

            HttpContext Context = HttpContext.Current;

            Boolean retVal = base.CreateRole(portalId, ref role);

            if (retVal == true)
            {
                try
                {

                    //your code here

                }
                catch (Exception e)
                {

                    //your code here

                }
            }

            return retVal;
        }

        public override void UpdateRole(RoleInfo role)
        {
            DotNetNuke.Entities.Users.UserInfo curUserInfo;
            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

            HttpContext Context = HttpContext.Current;

            //role.RoleName is null
            DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
            DotNetNuke.Security.Roles.RoleInfo newRoleInfo;
            newRoleInfo = rc.GetRole(role.RoleID, role.PortalID);

            try
            {

                //your code here

            }
            catch (Exception e)
            {

                //your code here
            }

            base.UpdateRole(role);
        }

        public override bool AddUserToRole(int portalId, UserInfo user, UserRoleInfo userRole)
        {

            DotNetNuke.Entities.Users.UserInfo curUserInfo;
            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

            //rolename in UserRoleInfo is null
            DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
            DotNetNuke.Security.Roles.RoleInfo newRoleInfo;
            newRoleInfo = rc.GetRole(userRole.RoleID, userRole.PortalID);


            HttpContext Context = HttpContext.Current;

            Boolean retVal = base.AddUserToRole(portalId, user, userRole);

            if (retVal == true)
            {
                try
                {

                    //your code here

                }
                catch (Exception e)
                {

                    //your code here
                }
            }

            return retVal;
        }

        public override void UpdateUserRole(UserRoleInfo userRole)
        {

            DotNetNuke.Entities.Users.UserInfo curUserInfo;
            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

            DotNetNuke.Entities.Users.UserInfo _UserInfo;
            _UserInfo = DotNetNuke.Entities.Users.UserController.GetUser(userRole.PortalID, userRole.UserID, false);

            HttpContext Context = HttpContext.Current;

            try
            {


                //your code here

            }
            catch (Exception e)
            {

                //your code here
            }

            base.UpdateUserRole(userRole);

        }

        public override void RemoveUserFromRole(int portalId, UserInfo user, UserRoleInfo userRole)
        {

            DotNetNuke.Entities.Users.UserInfo curUserInfo;
            curUserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

            HttpContext Context = HttpContext.Current;

            try
            {

                //your code here

            }
            catch (Exception e)
            {

                //your code here

            }

            base.RemoveUserFromRole(portalId, user, userRole);
        }

        public override void DeleteRole(int portalId, ref RoleInfo role)
        {
            try
            {

                //your code here

            }
            catch (Exception e)
            {

                //your code here

            }

            base.DeleteRole(portalId, ref role);
        }

    }

}

 

 
New Post
9/8/2008 5:27 PM
 

I'm trying to find out a list of Roles for the current User that's logged in.

I'm trying to use your code above, but it doesn't give me what I'm looking for.  Any ideas?

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsAuthenticationAuthenticationDocumentation?Documentation?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out