Change made in 3 files (plus web config).
web.config
-- Add key to appSettings
<add key="AuthenticationStripDomain" value="true" />
DotNetNuke.Library/Shared
Globals.vb
-- Add in from ADSI Componant due to need for this function in other places
Public Function TrimUserDomainName(ByVal UserName As String) As String
Dim strReturn As String
If UserName.IndexOf("\") > -1 Then
strReturn = Right(UserName, UserName.Length - (UserName.IndexOf("\") + 1))
ElseIf UserName.IndexOf("@") > -1 Then
strReturn = Left(UserName, UserName.IndexOf("@"))
Else
strReturn = UserName
End If
Return strReturn
End Function
DotNetNuke.Library/Components/Authentication
AuthenticationController.vb
-- Modify AuthenticationLogon() to check for appsetting and remove domain from login name
Public Sub AuthenticationLogon()
Dim _config As Authentication.Configuration = Authentication.Configuration.GetConfig()
Dim objAuthUserController As New Authentication.UserController
Dim authCookies As String = AUTHENTICATION_KEY & "_" & _portalSettings.PortalId.ToString
Dim LoggedOnUserName As String = HttpContext.Current.Request.ServerVariables(LOGON_USER_VARIABLE)
If LoggedOnUserName.Length > 0 Then
Dim UserName As String = LoggedOnUserName
If Not Config.GetSetting("AuthenticationStripDomain") Is Nothing Then
If Config.GetSetting("AuthenticationStripDomain") = "true" Then
UserName = DotNetNuke.Common.Globals.TrimUserDomainName(UserName)
End If
End If
Dim objDNNUser As DotNetNuke.Entities.Users.UserInfo
Dim objAuthUser As Authentication.UserInfo
Dim intUserId As Integer
objDNNUser = DotNetNuke.Entities.Users.UserController.GetUserByName(_portalSettings.PortalId, UserName, False)
If Not objDNNUser Is Nothing Then
intUserId = objDNNUser.UserID
' Synchronize role membership if it's required in settings
If _config.SynchronizeRole Then
objAuthUser = objAuthUserController.GetUser(UserName)
' user object might be in simple version in none active directory network
If Not objAuthUser.GUID.Length = 0 Then
objAuthUser.UserID = intUserId
UserController.AddUserRoles(_portalSettings.PortalId, objAuthUser)
End If
End If
Else
' User not exists in DNN database, obtain user info from provider to add new
objAuthUser = objAuthUserController.GetUser(LoggedOnUserName)
objDNNUser = CType(objAuthUser, DotNetNuke.Entities.Users.UserInfo)
UserName = objDNNUser.Username
If Not Config.GetSetting("AuthenticationStripDomain") Is Nothing Then
If Config.GetSetting("AuthenticationStripDomain") = "true" Then
UserName = DotNetNuke.Common.Globals.TrimUserDomainName(UserName)
End If
End If
objDNNUser.Username = UserName
If Not objAuthUser Is Nothing Then
Dim createStatus As UserCreateStatus = objAuthUserController.AddDNNUser(objAuthUser)
intUserId = objAuthUser.UserID
SetStatus(_portalSettings.PortalId, AuthenticationStatus.WinLogon)
End If
End If
If intUserId > 0 Then
FormsAuthentication.SetAuthCookie(Convert.ToString(UserName), True)
'check if user has supplied custom value for expiration
.......
' Get ipAddress for eventLog
......
Dim objEventLog As New Services.Log.EventLog.EventLogController
Dim objEventLogInfo As New Services.Log.EventLog.LogInfo
objEventLogInfo.AddProperty("IP", ipAddress)
objEventLogInfo.LogPortalID = _portalSettings.PortalId
objEventLogInfo.LogPortalName = _portalSettings.PortalName
objEventLogInfo.LogUserID = intUserId
objEventLogInfo.LogUserName = UserName
objEventLogInfo.AddProperty("WindowsAuthentication", "True")
objEventLogInfo.LogTypeKey = "LOGIN_SUCCESS"
......
.......
End Sub
HttpModule.DNNMembership
DNNMembershipModule.vb
-- Modify OnAuthenticateRequest() to check for appsetting and remove domain from Context.User.Identity.Name
Public Sub OnAuthenticateRequest(ByVal s As Object, ByVal e As EventArgs)
Dim Context As HttpContext = CType(s, HttpApplication).Context
Dim Request As HttpRequest = Context.Request
Dim Response As HttpResponse = Context.Response
'First check if we are upgrading/installing
If Request.Url.LocalPath.EndsWith("Install.aspx") Then
Exit Sub
End If
'exit if a request for a .net mapping that isn't a content page is made i.e. axd
If Request.Url.LocalPath.ToLower.EndsWith(".aspx") = False _
AndAlso Request.Url.LocalPath.ToLower.EndsWith(".asmx") = False Then
Exit Sub
End If
' Obtain PortalSettings from Current Context
Dim _portalSettings As PortalSettings = PortalController.GetCurrentPortalSettings
If Request.IsAuthenticated = True And Not _portalSettings Is Nothing Then
Dim arrPortalRoles() As String
Dim objRoleController As New RoleController
Dim UserName As String = Context.User.Identity.Name
If Not Config.GetSetting("AuthenticationStripDomain") Is Nothing Then
If Config.GetSetting("AuthenticationStripDomain") = "true" Then
UserName = DotNetNuke.Common.Globals.TrimUserDomainName(UserName)
End If
End If
Dim objUser As UserInfo = UserController.GetCachedUser(_portalSettings.PortalId, UserName)
......