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);
}
}
}