Skip to content

Commit

Permalink
Bug fix #56 and enhancement #54
Browse files Browse the repository at this point in the history
Added more debugging logs and added ability to use long upn names.
  • Loading branch information
westechms committed Feb 6, 2019
1 parent bfea2b3 commit 7c714c1
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 77 deletions.
4 changes: 2 additions & 2 deletions ActiveDirectory.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DNN_ActiveDirectoryAuthentication" type="Auth_System" version="06.01.02">
<package name="DNN_ActiveDirectoryAuthentication" type="Auth_System" version="07.00.00">
<friendlyName>DNN_ActiveDirectoryAuthentication</friendlyName>
<description>The DotNetNuke Active Directory Authentication Project is an Authentication provider for DotNetNuke that uses the Windows
Active Directory authentication protocol to authenticate users.
Expand Down Expand Up @@ -33,7 +33,7 @@
<assembly>
<path>bin\Providers</path>
<name>DotNetNuke.Authentication.ActiveDirectory.dll</name>
<version>06.01.02</version>
<version>07.00.00</version>
</assembly>
<assembly>
<path>bin</path>
Expand Down
8 changes: 4 additions & 4 deletions AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyConfiguration("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("")>
<Assembly: AssemblyCopyright("2018 DotNetNuke Corporation")>
<Assembly: AssemblyCopyright("2019 DotNetNuke Corporation")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(False)>
Expand All @@ -29,7 +29,7 @@ Imports System.Runtime.InteropServices
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("06.01.02.19")>
' <Assembly: AssemblyVersion("07.00.00.13")>

<Assembly: AssemblyVersion("06.01.02.19")>
<Assembly: AssemblyFileVersion("06.01.02.19")>
<Assembly: AssemblyVersion("07.00.00.13")>
<Assembly: AssemblyFileVersion("07.00.00.13")>
59 changes: 54 additions & 5 deletions Components/AuthenticationController.vb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Namespace DotNetNuke.Authentication.ActiveDirectory

Private ReadOnly _mProviderTypeName As String = ""
Private ReadOnly _portalSettings As PortalSettings
Private _config As Configuration = Configuration.GetConfig()

''' -------------------------------------------------------------------
''' <summary>
Expand All @@ -47,9 +48,9 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
''' </history>
''' -------------------------------------------------------------------
Sub New()
Dim config As Configuration = Configuration.GetConfig()

_portalSettings = PortalController.Instance.GetCurrentPortalSettings
_mProviderTypeName = config.ProviderTypeName
_mProviderTypeName = _config.ProviderTypeName
End Sub

''' -------------------------------------------------------------------
Expand Down Expand Up @@ -136,7 +137,14 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
End If
End If
End If
'debug logging issue #54 steven west 2/6/2019
If _config.EnableDebugMode Then
Utilities.objEventLog.AddLog("Description", "@AUTHENTICATIONLOGON:Dumping redirect url: URL:" & strUrl, _portalSettings, -1, Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT)
End If
HttpContext.Current.Response.Redirect(strUrl, True)
Else
'added error issue #54 steven west 2/6/2019
LogException(New Exception("There was an error trying to create user account: " & loggedOnUserName))
End If
Else
' Not Windows Authentication
Expand Down Expand Up @@ -180,6 +188,41 @@ Namespace DotNetNuke.Authentication.ActiveDirectory

End Function

''' -------------------------------------------------------------------
''' <summary>
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [sawest] 02/06/2019 Created for issue #56 long upn names
'''
''' </history>
''' -------------------------------------------------------------------
Public Function UPNManualLogon(ByVal userName As String, ByVal strPassword As String,
ByRef loginStatus As UserLoginStatus, ByVal ipAddress As String) As UserInfo
Dim objAuthUser As ADUserInfo = ProcessFormAuthentication(userName, strPassword)
Dim _config As Configuration = Configuration.GetConfig()
Dim objUser As UserInfo = Nothing
Dim objReturnUser As UserInfo = Nothing

If (userName.Length > 0) And (objAuthUser IsNot Nothing) Then
If _config.StripDomainName Then
userName = Utilities.TrimUserDomainName(userName)
End If
objAuthUser.Username = userName
objUser = DNNUserController.GetUserByName(_portalSettings.PortalId, userName)

objReturnUser = AuthenticateUser(objUser, objAuthUser, loginStatus, ipAddress)
If Not (objReturnUser Is Nothing) Then
objAuthUser.LastIPAddress = ipAddress
UpdateDNNUser(objReturnUser, objAuthUser)
End If
End If

Return objReturnUser

End Function

''' -------------------------------------------------------------------
''' <summary>
''' Process the authentication of the user whether they've logged in
Expand Down Expand Up @@ -383,6 +426,12 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
OnUserCreateCompleted(args)

'Item 7703

'debug logging issue #54 steven west 2/6/2019
If _config.EnableDebugMode Then
Utilities.AddEventLog(_portalSettings, "@CREATEUSER:Dumping create status: CreateStatus: " & createStatus.ToString)
End If

If createStatus = UserCreateStatus.Success Or createStatus = UserCreateStatus.UserAlreadyRegistered Then
loginStatus = UserLoginStatus.LOGIN_SUCCESS
Else
Expand Down Expand Up @@ -525,9 +574,9 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
If config.WindowsAuthentication Then
Dim userName As String = loggedOnUserName

If config.StripDomainName Then
userName = Utilities.TrimUserDomainName(userName)
End If
'If config.StripDomainName Then
' userName = Utilities.TrimUserDomainName(userName)
'End If

Dim objAuthUser As ADUserInfo = objAuthUserController.GetUser(userName, loggedOnPassword)
Return objAuthUser
Expand Down
24 changes: 23 additions & 1 deletion Components/Config/Configuration.vb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
Public Const AD_SEARCHBOTS As String = "AD_SearchBots"
Public Const AD_SYNCPHOTO As String = "AD_SyncPhoto"
Public Const AD_ENABLEAUTOLOGIN As String = "AD_ENABLEAUTOLOGIN"
Public Const AD_ENABLEDEBUGMODE As String = "AD_ENABLEDEBUGMODE"


Private mPortalId As Integer
Expand All @@ -75,6 +76,7 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
Private mBots As String = ""
Private mPhoto As Boolean = False
Private mEnableAutoLogin As Boolean = False
Private mEnableDebugMode As Boolean = False

''' -------------------------------------------------------------------
''' <summary>
Expand All @@ -92,6 +94,7 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
''' [sawest] 12/16/2016 Added if contain statements. If a key was missing, an error was thrown in the try block and the rest of the settings did not load.
''' [sawest] 12/16/2016 Switched to using constants for setting names
''' [sawest] 01/02/2017 Added photo setting and constant
''' [sawest] 02/06/2019 Added debug mode setting and constant
''' </history>
''' -------------------------------------------------------------------
Sub New()
Expand Down Expand Up @@ -160,6 +163,9 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
If CambrianSettings.ContainsKey(AD_ENABLEAUTOLOGIN) Then
mEnableAutoLogin = CType(Null.GetNull(CambrianSettings(AD_ENABLEAUTOLOGIN), mEnableAutoLogin), Boolean)
End If
If CambrianSettings.ContainsKey(AD_ENABLEDEBUGMODE) Then
mEnableDebugMode = CType(Null.GetNull(CambrianSettings(AD_ENABLEDEBUGMODE), mEnableDebugMode), Boolean)
End If
End If
Catch ex As Exception
'Log the exception
Expand Down Expand Up @@ -251,7 +257,8 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
ByVal AutoCreateUsers As Boolean,
ByVal Bots As String,
ByVal Photo As Boolean,
ByVal EnableAutoLogin As Boolean)
ByVal EnableAutoLogin As Boolean,
ByVal EnableDebugMode As Boolean)

Dim objSecurity As New PortalSecurity
'Item 8512
Expand All @@ -274,6 +281,7 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
PortalController.UpdatePortalSetting(PortalID, AD_SEARCHBOTS, If(String.IsNullOrEmpty(Bots), "", Bots))
PortalController.UpdatePortalSetting(PortalID, AD_SYNCPHOTO, Photo.ToString)
PortalController.UpdatePortalSetting(PortalID, AD_ENABLEAUTOLOGIN, EnableAutoLogin.ToString)
PortalController.UpdatePortalSetting(PortalID, AD_ENABLEDEBUGMODE, EnableDebugMode.ToString)
'Only update password if it has been changed
If AuthenticationPassword.Length > 0 Then
PortalController.UpdatePortalSetting(PortalID, AD_AUTHENTICATIONPASSWORD, Convert.ToString(objSecurity.Encrypt(AUTHENTICATION_KEY, AuthenticationPassword)))
Expand Down Expand Up @@ -635,6 +643,20 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
Return mEnableAutoLogin
End Get
End Property
''' -------------------------------------------------------------------
''' <summary>
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [sawest] 02/06/2019 Created
''' </history>
''' -------------------------------------------------------------------
Public ReadOnly Property EnableDebugMode() As String
Get
Return mEnableDebugMode
End Get
End Property



Expand Down
6 changes: 3 additions & 3 deletions DotNetNuke.Authentication.ActiveDirectory.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<OptionInfer>On</OptionInfer>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<UseIISExpress>false</UseIISExpress>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -58,9 +58,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetNuke, Version=8.0.4.226, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="DotNetNuke, Version=7.2.0.607, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\Sites\dnndev7\bin\DotNetNuke.dll</HintPath>
<HintPath>..\..\..\..\Sites\dnndev80\bin\DotNetNuke.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down
111 changes: 57 additions & 54 deletions Login.ascx.vb
Original file line number Diff line number Diff line change
Expand Up @@ -110,61 +110,64 @@ Namespace DotNetNuke.Authentication.ActiveDirectory

Dim theUser As String = String.Empty
Dim strDomain As String = String.Empty
Dim userinfo As String()
'Dim userinfo As String()
If Not String.IsNullOrEmpty(txtUsername.Text) Then

'If UPN username provided, strip domain, translate to netBiOS
If txtUsername.Text.Contains("@") Then

'***Changed Steven A West 1-11-2018 Bug fix #12 & #24
theUser = ADSI.Utilities.UPNToLogonName0(txtUsername.Text.ToLower)

'***Commented Out Steven A West 1-11-2018 Bug fix #12 & #24**************
' userinfo = Split(txtUsername.Text, "@")
' theUser = userinfo(0)
'theUser = Left(txtUsername.Text, txtUsername.Text.IndexOf("@")) ***Changed Steven A West 2-25-2017 Bug fix #12
' strDomain = UCase(userinfo(1))

'***Changed Steven A West 2-25-2017 Bug fix #12
'strDomain = Right(txtUsername.Text, Len(txtUsername.Text) - (Len(theUser) + 1)).ToUpper
'***Changed Steven A West 8-29-2017 Bug fix #12
'If strDomain.Contains(sDefaultDomain) Then
' theUser = Trim(sDefaultDomain).Replace("\", "") & "\" & theUser
'Else
' theUser = strDomain & "\" & theUser
'End If
'If Not String.IsNullOrEmpty(sDefaultDomain) Then
' If strDomain.Contains(sDefaultDomain) Then
' theUser = Trim(sDefaultDomain).Replace("\", "") & "\" & theUser
' Else
' theUser = strDomain & "\" & theUser
' End If
'End If

'****************************************************************************
'Changing code for long UPN ability issue #56 sawest 2-6-2019
'needs to be cleaned up and removed in later version

''If UPN username provided, strip domain, translate to netBiOS
'If txtUsername.Text.Contains("@") Then

' '***Changed Steven A West 1-11-2018 Bug fix #12 & #24
' theUser = ADSI.Utilities.UPNToLogonName0(txtUsername.Text.ToLower)

' '***Commented Out Steven A West 1-11-2018 Bug fix #12 & #24**************
' ' userinfo = Split(txtUsername.Text, "@")
' ' theUser = userinfo(0)
' 'theUser = Left(txtUsername.Text, txtUsername.Text.IndexOf("@")) ***Changed Steven A West 2-25-2017 Bug fix #12
' ' strDomain = UCase(userinfo(1))

' '***Changed Steven A West 2-25-2017 Bug fix #12
' 'strDomain = Right(txtUsername.Text, Len(txtUsername.Text) - (Len(theUser) + 1)).ToUpper
' '***Changed Steven A West 8-29-2017 Bug fix #12
' 'If strDomain.Contains(sDefaultDomain) Then
' ' theUser = Trim(sDefaultDomain).Replace("\", "") & "\" & theUser
' 'Else
' ' theUser = strDomain & "\" & theUser
' 'End If
' 'If Not String.IsNullOrEmpty(sDefaultDomain) Then
' ' If strDomain.Contains(sDefaultDomain) Then
' ' theUser = Trim(sDefaultDomain).Replace("\", "") & "\" & theUser
' ' Else
' ' theUser = strDomain & "\" & theUser
' ' End If
' 'End If

' '****************************************************************************
'Else

'If username doesn't contain the DOMAIN\ already and config uses Default Domain
'Then prepend default domain as prefix
If (Not txtUsername.Text.Contains("\")) And (sDefaultDomain <> "" And Not txtUsername.Text.Contains("@")) Then
theUser = Trim(sDefaultDomain).Replace("\", "") & "\" & txtUsername.Text
Else
'If username doesn't contain the DOMAIN\ already and config uses Default Domain
'Then append default domain as prefix
If (Not txtUsername.Text.Contains("\")) And (sDefaultDomain <> "") Then
theUser = Trim(sDefaultDomain).Replace("\", "") & "\" & txtUsername.Text
Else
'if username contains domain\ then check if domain provided is canonical and translate
If txtUsername.Text.Contains("\") Then

'***Changed Steven A West 1-11-2018 Bug fix #12 & #24
strDomain = UCase(Split(txtUsername.Text, "\")(0))
theUser = UCase(Split(txtUsername.Text, "\")(1))
If strDomain.Contains(".") Then 'canonical domain provided, translate
strDomain = ADSI.Utilities.CanonicalToNetBIOS(strDomain.ToLower)
End If
If Not String.IsNullOrEmpty(strDomain) Then
theUser = strDomain & "\" & theUser
End If
'********
Else
'no domain provided and no default domain set
theUser = txtUsername.Text
'if username contains domain\ then check if domain provided is canonical and translate
If txtUsername.Text.Contains("\") And Not txtUsername.Text.Contains("@") Then

'***Changed Steven A West 1-11-2018 Bug fix #12 & #24
strDomain = UCase(Split(txtUsername.Text, "\")(0))
theUser = UCase(Split(txtUsername.Text, "\")(1))
If strDomain.Contains(".") Then 'canonical domain provided, translate
strDomain = ADSI.Utilities.CanonicalToNetBIOS(strDomain.ToLower)
End If
If Not String.IsNullOrEmpty(strDomain) Then
theUser = strDomain & "\" & theUser
End If
'********
Else
'no domain provided and no default domain set or UPN given
theUser = txtUsername.Text
End If
End If
End If
Expand Down Expand Up @@ -277,9 +280,9 @@ Namespace DotNetNuke.Authentication.ActiveDirectory
Dim loginStatus As UserLoginStatus = UserLoginStatus.LOGIN_FAILURE
Dim objAuthentication As New AuthenticationController
Dim objUser As DNNUserInfo = Nothing
If UserName.Contains("\") Then
objUser = objAuthentication.ManualLogon(UserName, txtPassword.Text, loginStatus, IPAddress)
End If
' If UserName.Contains("\") Then
objUser = objAuthentication.ManualLogon(UserName, txtPassword.Text, loginStatus, IPAddress)
'End If
Dim authenticated As Boolean = Null.NullBoolean
Dim message As String = Null.NullString
authenticated = (loginStatus <> UserLoginStatus.LOGIN_FAILURE)
Expand Down
Loading

0 comments on commit 7c714c1

Please sign in to comment.