New additional code give you an ability to create portals wtih diffrent AD_Provider configurations. Here is the changes...
Red – is changed or new strings.
\Providers\ADSIProvider\ADSIProvider.vb
Public Overloads Overrides Function GetUser(ByVal LoggedOnUserName As String) As UserInfo
Dim objAuthUser As UserInfo
Try
If _adsiConfig.LDAPAccesible Then
Dim entry As DirectoryEntry
entry = Utilities.GetUserEntryByName(LoggedOnUserName)
If Not entry Is Nothing Then
objAuthUser = New UserInfo
Dim location As String = Utilities.GetEntryLocation(entry)
If location.Length = 0 Then
location = _adsiConfig.ConfigDomainPath
End If
With objAuthUser
.PortalID = _portalSettings.PortalId
.GUID = entry.NativeGuid
.Location = location
.Username = LoggedOnUserName
.PrincipalName = Utilities.TrimUserDomainName(LoggedOnUserName) & "@" & location
.Username = LoggedOnUserName
.Membership.Password = Utilities.GetRandomPassword()
End With
FillUserInfo(entry, objAuthUser)
Else
'do not alow to login users from other domain even through these users
'have ACL access to resources in that domain in which web site hosts
'objAuthUser = GetSimplyUser(LoggedOnUserName)
objAuthUser = New UserInfo
Return objAuthUser
End If
Else ' could not find it in AD, so populate user object with minumum info
objAuthUser = GetSimplyUser(LoggedOnUserName)
End If
Return objAuthUser
Catch exc As System.Runtime.InteropServices.COMException
LogException(exc)
Return Nothing
End Try
End Function
\Providers\ADSIProvider\Configuration.vb
Sub New()
Dim authConfig As DotNetNuke.Authentication.ActiveDirectory.Configuration = DotNetNuke.Authentication.ActiveDirectory.Configuration.GetConfig()
mPortalId = authConfig.PortalId
Try
'Temporary fix this setting as TRUE for design, to be removed when release
mConfigDomainPath = authConfig.RootDomain
mDefaultEmailDomain = authConfig.EmailDomain
mUserName = authConfig.UserName
mPassword = authConfig.Password
mAuthenticationType = CType([Enum].Parse(GetType(AuthenticationTypes), authConfig.AuthenticationType), AuthenticationTypes)
' IMPORTANT: Remove ADSIPath, to be added later depends on accessing method
mRootDomainPath = ADSI.Utilities.ValidateDomainPath(mConfigDomainPath)
Catch exc As Exception
mProcessLog += exc.Message & "<br>"
End Try
' Also check if LDAP fully accessible
Try
Dim ldap As New DirectoryEntry(mRootDomainPath, mUserName, mPassword, mAuthenticationType)
'If ldap.Exists(mRootDomainPath) Then Try to find another way to check that domain exists
mLDAPAccesible = True
mRefCollection = New ADSI.CrossReferenceCollection(mUserName, mPassword, mAuthenticationType, mRootDomainPath)
'End If
Catch exc As System.Runtime.InteropServices.COMException
mLDAPAccesible = False
mProcessLog += exc.Message & "<br>"
LogException(exc)
End Try
' Also check if Authentication implemented in this Windows Network
Dim gc As New DirectoryEntry
Dim path As String = Utilities.GetRootDSEPath() ’Get correct path for domain other than current
Try
Dim rootGC As New DirectoryEntry
'If rootGC.Exists("GC://" + mRootDomainPath) Then Try to find another way to check that domain exists
If (mUserName.Length > 0) AndAlso (mPassword.Length > 0) Then
rootGC = New DirectoryEntry(path, mUserName, mPassword, mAuthenticationType)
Else
rootGC = New DirectoryEntry(path)
End If
mConfigurationPath = CType(rootGC.Properties(ADSI_CONFIGURATIONNAMIMGCONTEXT).Value, String)
mADSINetwork = True
'End If
Catch exc As System.Runtime.InteropServices.COMException
mADSINetwork = False
' mLDAPAccesible = False
mProcessLog += exc.Message & "<br>"
LogException(exc)
' Nothing to do if we could not access Global Catalog, so return
End Try
End Sub
\Providers\ADSIProvider\CrossReferenceCollection.vb
Imports DotNetNuke.Common
Public Sub New(ByVal UserName As String, ByVal Password As String, ByVal AuthType As AuthenticationTypes, Optional ByVal mRootDomain As String = "rootDSE")
MyBase.New()
Try
' Obtain NETBIOS only if LDAP accessible to prevent error
‘ Dim rootLDAP As New DirectoryEntry("LDAP://rootDSE", UserName, Password, AuthType)
‘ Dim crossRefPath As String = "LDAP://CN=Partitions," & rootLDAP.Properties("configurationNamingContext").Value.ToString
Dim rootLDAP As New DirectoryEntry
Dim configContext As String
Dim crossRefPath As String
mRootDomain = Utilities.GetRootDSEPath()
rootLDAP = New DirectoryEntry(mRootDomain, UserName, Password, AuthType)
Try
configContext = CType(rootLDAP.Properties("configurationNamingContext").Value, String)
crossRefPath = Utilities.GetGlobalCatalogPath() & "CN=Partitions," & configContext
Catch ex As System.Runtime.InteropServices.COMException
mProcessLog += ex.Message & "<br>"
End Try
Dim objCrossRefContainer As DirectoryEntry
If (UserName.Length > 0) AndAlso (Password.Length > 0) Then
objCrossRefContainer = New DirectoryEntry(crossRefPath, UserName, Password, AuthType)
Else
objCrossRefContainer = New DirectoryEntry(crossRefPath)
End If
Dim objCrossRef As DirectoryEntry
For Each objCrossRef In objCrossRefContainer.Children
If Not objCrossRef.Properties("nETBIOSName").Value Is Nothing Then
Dim netBIOSName As String = CType(objCrossRef.Properties("nETBIOSName").Value, String)
Dim canonicalName As String = CType(objCrossRef.Properties("dnsRoot").Value, String)
Dim domainPath As String = CType(objCrossRef.Properties("nCName").Value, String)
Dim crossRef As CrossReference = New CrossReference(domainPath, netBIOSName, canonicalName)
Me.Add(crossRef)
End If
Next
Catch ex As System.Runtime.InteropServices.COMException
mProcessLog += ex.Message & "<br>"
End Try
End Sub
\Providers\ADSIProvider\Utilities.vb
New Function GetGlobalCatalogPath()
Create global catalog root entry from root domain string for ADSI operations.
New syntax for root entry to get connected is LDAP://domain_controller_address/DC=sub_domain,DC=domain,DC=ru
Public Shared Function GetGlobalCatalogPath() As String
Dim adsiConfig As DotNetNuke.Authentication.ActiveDirectory.Configuration = DotNetNuke.Authentication.ActiveDirectory.Configuration.GetConfig()
Dim Path As String = adsiConfig.RootDomain
If Path.Length = 0 Then
Return Path
End If
Path = Right(Path, Path.Length - Path.IndexOf("DC="))
Path = Utilities.ConvertToCanonical(Path, False)
If Path.Length > 0 Then
Path = Path & "/"
End If
Path = "LDAP://" & Path
Return Path
End Function
New Function GetRootDSEPath()
Public Shared Function GetRootDSEPath() As String
Return GetGlobalCatalogPath() & "RootDSE"
End Function
Modified Function
Public Shared Function GetRootForestPath(Optional ByVal ADSIPath As ADSI.Path = ADSI.Path.GC) As String
Try
Dim authConfig As DotNetNuke.Authentication.ActiveDirectory.Configuration = DotNetNuke.Authentication.ActiveDirectory.Configuration.GetConfig()
Dim strADSIPath As String = ADSIPath.ToString & "://"
' convert ADSI string to "GC://global_catalog_for_domain_com/RootDSE" for access to trusted domains
Dim rootDomainName = ConvertToCanonical(authConfig.RootDomain, False)
Dim authType As AuthenticationTypes = CType([Enum].Parse(GetType(AuthenticationTypes), authConfig.AuthenticationType), AuthenticationTypes)
If rootDomainName.Length > 0 Then
rootDomainName = rootDomainName & "/"
End If
Dim ADsRoot As New DirectoryEntry(strADSIPath & rootDomainName & "rootDSE", authConfig.UserName, authConfig.Password, authType)
Dim strRootDomain As String = strADSIPath & rootDomainName & CType(ADsRoot.Properties(Configuration.ADSI_ROOTDOMAINNAMIMGCONTEXT).Value, String)
Return strRootDomain
Catch ex As System.Runtime.InteropServices.COMException
LogException(ex)
Return Nothing
End Try
End Function