public ADSIProvider()
 {
     _portalSettings = PortalController.GetCurrentPortalSettings();
     _adsiConfig = ADSI.Configuration.GetConfig();
 }
        //'Obtain group objects from ADSI, to be used in custom module for importing role into DNN
        //Public Overloads Overrides Function GetGroups(ByVal Filter As String) As ArrayList
        //    Return SearchGroups("", Filter)
        //End Function

        //Public Overrides Sub AddRoleMembership(ByVal Role As DotNetNuke.Security.Roles.RoleInfo, ByVal UserDistinguishedName As String)
        //    Dim adsiConfig As Authentication.ADSI.Configuration = Authentication.ADSI.Configuration.GetConfig(_portalSettings.PortalId)
        //    Dim strDomain As String = Right(UserDistinguishedName, UserDistinguishedName.Length - UserDistinguishedName.IndexOf("DC="))
        //    Dim strUserName As String = UserDistinguishedName.Substring(3, UserDistinguishedName.IndexOf(",") - 3)
        //    Try
        //        Dim objCrossReference As ADSI.CrossReferenceCollection.CrossReference = _adsiConfig.RefCollection.Item(ConvertToCanonical(strDomain, False))
        //        If (Not objCrossReference.NetBIOSName Is Nothing) AndAlso (objCrossReference.NetBIOSName.Length > 0) Then
        //            strUserName = objCrossReference.NetBIOSName & "\" & strUserName
        //        End If

        //        ' Get DNN UserInfo from database
        //        Dim objUserController As New DotNetNuke.Entities.Users.UserController
        //        Dim objRoleController As New DotNetNuke.Security.Roles.RoleController
        //        Dim objUserInfo As DotNetNuke.Entities.Users.UserInfo = objUserController.GetUserByUsername(_portalSettings.PortalId, strUserName)
        //        ' Add user role
        //        If Not objUserInfo Is Nothing Then
        //            objRoleController.AddUserRole(_portalSettings.PortalId, objUserInfo.UserID, Role.RoleID, DateTime.MaxValue)
        //        End If
        //    Catch Exc As System.Runtime.InteropServices.COMException
        //        LogException(Exc)
        //    End Try

        //End Sub

        //Public Overrides Sub AddGroupMembership(ByVal Role As DotNetNuke.Security.Roles.RoleInfo, ByVal User As DotNetNuke.Entities.Users.UserInfo)
        //    Dim adsiConfig As Authentication.ADSI.Configuration = Authentication.ADSI.Configuration.GetConfig(_portalSettings.PortalId)
        //    Try
        //        Dim authGroup As Authentication.GroupInfo = GetGroup(Role.RoleName)
        //        Dim authUser As Authentication.UserInfo = GetUser(User.Username)

        //        If (Not authUser Is Nothing) Then
        //            ' Create new group, if not exists in AD
        //            If authGroup Is Nothing Then
        //                authGroup = CreateGroup(Role)
        //            End If

        //            If (Not authGroup Is Nothing) AndAlso (Not IsAuthenticationMember(authGroup, authUser)) Then
        //                'Get object in ADSI
        //                'Dim rootDomain As ADSI.Domain = _adsiConfig.RootDomain(ADSIPath.LDAP)
        //                Dim rootDomain As ADSI.Domain = _adsiConfig.RootDomain()
        //                Dim userEntry As DirectoryEntry = GetUserEntryByLoggedOnName(User.Username, rootDomain)
        //                Dim tempGroupEntry As DirectoryEntry '= GetGroupEntryByName(Role.RoleName, rootDomain)

        //                ' With a new group, it might not be available due to replication
        //                ' Return to avoid error or
        //                Do Until (Not tempGroupEntry Is Nothing)
        //                    tempGroupEntry = GetGroupEntryByName(Role.RoleName, rootDomain)
        //                Loop
        //                'If tempGroupEntry Is Nothing Then
        //                '    Return
        //                'End If
        //                Dim groupEntry As DirectoryEntry = GetLDAPEntry(tempGroupEntry, _adsiConfig)
        //                If (Not groupEntry Is Nothing) AndAlso (Not userEntry Is Nothing) Then
        //                    Dim strDisName As String = CheckNullString(userEntry.Properties(ADSI_DISTINGUISHEDNAME).Value)
        //                    groupEntry.Properties(ADSI_MEMBER).Add(strDisName)
        //                    groupEntry.CommitChanges()
        //                End If

        //            End If
        //        End If

        //    Catch Exc As System.Runtime.InteropServices.COMException
        //        LogException(Exc)
        //    End Try
        //End Sub

        //Public Overrides Sub RemoveGroupMembership(ByVal Role As DotNetNuke.Security.Roles.RoleInfo, ByVal User As DotNetNuke.Entities.Users.UserInfo)
        //    Dim adsiConfig As Authentication.ADSI.Configuration = Authentication.ADSI.Configuration.GetConfig(_portalSettings.PortalId)
        //    Try
        //        Dim authGroup As Authentication.GroupInfo = GetGroup(Role.RoleName)
        //        Dim authUser As Authentication.UserInfo = GetUser(User.Username)

        //        If (Not authGroup Is Nothing) AndAlso (Not authUser Is Nothing) Then
        //            If IsAuthenticationMember(authGroup, authUser) Then
        //                'Get object in ADSI
        //                'Dim rootDomain As ADSI.Domain = _adsiConfig.RootDomain(ADSIPath.LDAP)
        //                Dim rootDomain As ADSI.Domain = _adsiConfig.RootDomain()
        //                Dim userEntry As DirectoryEntry = GetUserEntryByLoggedOnName(User.Username, rootDomain)
        //                Dim tempGroupEntry As DirectoryEntry = GetGroupEntryByName(Role.RoleName, rootDomain)
        //                Dim groupEntry As DirectoryEntry = GetLDAPEntry(tempGroupEntry, _adsiConfig)

        //                If (Not groupEntry Is Nothing) AndAlso (Not userEntry Is Nothing) Then
        //                    Dim strDisName As String = CheckNullString(userEntry.Properties(ADSI_DISTINGUISHEDNAME).Value)
        //                    groupEntry.Properties(ADSI_MEMBER).Remove(strDisName)
        //                    groupEntry.CommitChanges()
        //                End If

        //            End If
        //        End If

        //    Catch Exc As System.Runtime.InteropServices.COMException
        //        LogException(Exc)
        //    End Try
        //End Sub

        public override string GetNetworkStatus()
        {
            StringBuilder sb = new StringBuilder();
            // Refresh settings cache first
            ADSI.Configuration.ResetConfig();
            _adsiConfig = ADSI.Configuration.GetConfig();

            sb.Append( "<b>[Global Catalog Status]</b>" + "<br>" );
            try
            {
                if( _adsiConfig.ADSINetwork )
                {
                    sb.Append( "OK<br>" );
                }
                else
                {
                    sb.Append( "FAIL<br>" );
                }
            }
            catch( COMException ex )
            {
                sb.Append( "FAIL<br>" );
                sb.Append( ex.Message + "<br>" );
            }

            sb.Append( "<b>[Root Domain Status]</b><br>" );
            try
            {
                if( Utilities.GetRootEntry() != null )
                {
                    sb.Append( "OK<br>" );
                }
                else
                {
                    sb.Append( "FAIL<br>" );
                }
            }
            catch( COMException ex )
            {
                sb.Append( "FAIL<br>" );
                sb.Append( ex.Message + "<br>" );
            }

            sb.Append( "<b>[LDAP Status]</b><br>" );
            try
            {
                if( _adsiConfig.LDAPAccesible )
                {
                    sb.Append( "OK<br>" );
                }
                else
                {
                    sb.Append( "FAIL<br>" );
                }
            }
            catch( COMException ex )
            {
                sb.Append( "FAIL<br>" );
                sb.Append( ex.Message + "<br>" );
            }

            sb.Append( "<b>[Network Domains Status]</b><br>" );
            try
            {
                if( _adsiConfig.RefCollection != null && _adsiConfig.RefCollection.Count > 0 )
                {
                    sb.Append( _adsiConfig.RefCollection.Count.ToString() );
                    sb.Append( " Domain(s):<br>" );
                    CrossReferenceCollection.CrossReference crossRef;
                    foreach( CrossReferenceCollection.CrossReference tempLoopVar_crossRef in _adsiConfig.RefCollection )
                    {
                        crossRef = tempLoopVar_crossRef;
                        sb.Append( crossRef.CanonicalName );
                        sb.Append( " (" );
                        sb.Append( crossRef.NetBIOSName );
                        sb.Append( ")<br>" );
                    }

                    if( _adsiConfig.RefCollection.ProcesssLog.Length > 0 )
                    {
                        sb.Append( _adsiConfig.RefCollection.ProcesssLog + "<br>" );
                    }
                }
                else
                {
                    sb.Append( "[LDAP Error Message]<br>" );
                }
            }
            catch( COMException ex )
            {
                sb.Append( "[LDAP Error Message]<br>" );
                sb.Append( ex.Message + "<br>" );
            }

            if( _adsiConfig.ProcessLog.Length > 0 )
            {
                sb.Append( _adsiConfig.ProcessLog + "<br>" );
            }

            return sb.ToString();
        }
Exemple #3
0
        //'Obtain group objects from ADSI, to be used in custom module for importing role into DNN
        //Public Overloads Overrides Function GetGroups(ByVal Filter As String) As ArrayList
        //    Return SearchGroups("", Filter)
        //End Function

        //Public Overrides Sub AddRoleMembership(ByVal Role As DotNetNuke.Security.Roles.RoleInfo, ByVal UserDistinguishedName As String)
        //    Dim adsiConfig As Authentication.ADSI.Configuration = Authentication.ADSI.Configuration.GetConfig(_portalSettings.PortalId)
        //    Dim strDomain As String = Right(UserDistinguishedName, UserDistinguishedName.Length - UserDistinguishedName.IndexOf("DC="))
        //    Dim strUserName As String = UserDistinguishedName.Substring(3, UserDistinguishedName.IndexOf(",") - 3)
        //    Try
        //        Dim objCrossReference As ADSI.CrossReferenceCollection.CrossReference = _adsiConfig.RefCollection.Item(ConvertToCanonical(strDomain, False))
        //        If (Not objCrossReference.NetBIOSName Is Nothing) AndAlso (objCrossReference.NetBIOSName.Length > 0) Then
        //            strUserName = objCrossReference.NetBIOSName & "\" & strUserName
        //        End If

        //        ' Get DNN UserInfo from database
        //        Dim objUserController As New DotNetNuke.Entities.Users.UserController
        //        Dim objRoleController As New DotNetNuke.Security.Roles.RoleController
        //        Dim objUserInfo As DotNetNuke.Entities.Users.UserInfo = objUserController.GetUserByUsername(_portalSettings.PortalId, strUserName)
        //        ' Add user role
        //        If Not objUserInfo Is Nothing Then
        //            objRoleController.AddUserRole(_portalSettings.PortalId, objUserInfo.UserID, Role.RoleID, DateTime.MaxValue)
        //        End If
        //    Catch Exc As System.Runtime.InteropServices.COMException
        //        LogException(Exc)
        //    End Try

        //End Sub

        //Public Overrides Sub AddGroupMembership(ByVal Role As DotNetNuke.Security.Roles.RoleInfo, ByVal User As DotNetNuke.Entities.Users.UserInfo)
        //    Dim adsiConfig As Authentication.ADSI.Configuration = Authentication.ADSI.Configuration.GetConfig(_portalSettings.PortalId)
        //    Try
        //        Dim authGroup As Authentication.GroupInfo = GetGroup(Role.RoleName)
        //        Dim authUser As Authentication.UserInfo = GetUser(User.Username)

        //        If (Not authUser Is Nothing) Then
        //            ' Create new group, if not exists in AD
        //            If authGroup Is Nothing Then
        //                authGroup = CreateGroup(Role)
        //            End If

        //            If (Not authGroup Is Nothing) AndAlso (Not IsAuthenticationMember(authGroup, authUser)) Then
        //                'Get object in ADSI
        //                'Dim rootDomain As ADSI.Domain = _adsiConfig.RootDomain(ADSIPath.LDAP)
        //                Dim rootDomain As ADSI.Domain = _adsiConfig.RootDomain()
        //                Dim userEntry As DirectoryEntry = GetUserEntryByLoggedOnName(User.Username, rootDomain)
        //                Dim tempGroupEntry As DirectoryEntry '= GetGroupEntryByName(Role.RoleName, rootDomain)

        //                ' With a new group, it might not be available due to replication
        //                ' Return to avoid error or
        //                Do Until (Not tempGroupEntry Is Nothing)
        //                    tempGroupEntry = GetGroupEntryByName(Role.RoleName, rootDomain)
        //                Loop
        //                'If tempGroupEntry Is Nothing Then
        //                '    Return
        //                'End If
        //                Dim groupEntry As DirectoryEntry = GetLDAPEntry(tempGroupEntry, _adsiConfig)
        //                If (Not groupEntry Is Nothing) AndAlso (Not userEntry Is Nothing) Then
        //                    Dim strDisName As String = CheckNullString(userEntry.Properties(ADSI_DISTINGUISHEDNAME).Value)
        //                    groupEntry.Properties(ADSI_MEMBER).Add(strDisName)
        //                    groupEntry.CommitChanges()
        //                End If

        //            End If
        //        End If

        //    Catch Exc As System.Runtime.InteropServices.COMException
        //        LogException(Exc)
        //    End Try
        //End Sub

        //Public Overrides Sub RemoveGroupMembership(ByVal Role As DotNetNuke.Security.Roles.RoleInfo, ByVal User As DotNetNuke.Entities.Users.UserInfo)
        //    Dim adsiConfig As Authentication.ADSI.Configuration = Authentication.ADSI.Configuration.GetConfig(_portalSettings.PortalId)
        //    Try
        //        Dim authGroup As Authentication.GroupInfo = GetGroup(Role.RoleName)
        //        Dim authUser As Authentication.UserInfo = GetUser(User.Username)

        //        If (Not authGroup Is Nothing) AndAlso (Not authUser Is Nothing) Then
        //            If IsAuthenticationMember(authGroup, authUser) Then
        //                'Get object in ADSI
        //                'Dim rootDomain As ADSI.Domain = _adsiConfig.RootDomain(ADSIPath.LDAP)
        //                Dim rootDomain As ADSI.Domain = _adsiConfig.RootDomain()
        //                Dim userEntry As DirectoryEntry = GetUserEntryByLoggedOnName(User.Username, rootDomain)
        //                Dim tempGroupEntry As DirectoryEntry = GetGroupEntryByName(Role.RoleName, rootDomain)
        //                Dim groupEntry As DirectoryEntry = GetLDAPEntry(tempGroupEntry, _adsiConfig)

        //                If (Not groupEntry Is Nothing) AndAlso (Not userEntry Is Nothing) Then
        //                    Dim strDisName As String = CheckNullString(userEntry.Properties(ADSI_DISTINGUISHEDNAME).Value)
        //                    groupEntry.Properties(ADSI_MEMBER).Remove(strDisName)
        //                    groupEntry.CommitChanges()
        //                End If

        //            End If
        //        End If

        //    Catch Exc As System.Runtime.InteropServices.COMException
        //        LogException(Exc)
        //    End Try
        //End Sub

        public override string GetNetworkStatus()
        {
            StringBuilder sb = new StringBuilder();

            // Refresh settings cache first
            ADSI.Configuration.ResetConfig();
            _adsiConfig = ADSI.Configuration.GetConfig();

            sb.Append("<b>[Global Catalog Status]</b>" + "<br>");
            try
            {
                if (_adsiConfig.ADSINetwork)
                {
                    sb.Append("OK<br>");
                }
                else
                {
                    sb.Append("FAIL<br>");
                }
            }
            catch (COMException ex)
            {
                sb.Append("FAIL<br>");
                sb.Append(ex.Message + "<br>");
            }

            sb.Append("<b>[Root Domain Status]</b><br>");
            try
            {
                if (Utilities.GetRootEntry() != null)
                {
                    sb.Append("OK<br>");
                }
                else
                {
                    sb.Append("FAIL<br>");
                }
            }
            catch (COMException ex)
            {
                sb.Append("FAIL<br>");
                sb.Append(ex.Message + "<br>");
            }

            sb.Append("<b>[LDAP Status]</b><br>");
            try
            {
                if (_adsiConfig.LDAPAccesible)
                {
                    sb.Append("OK<br>");
                }
                else
                {
                    sb.Append("FAIL<br>");
                }
            }
            catch (COMException ex)
            {
                sb.Append("FAIL<br>");
                sb.Append(ex.Message + "<br>");
            }

            sb.Append("<b>[Network Domains Status]</b><br>");
            try
            {
                if (_adsiConfig.RefCollection != null && _adsiConfig.RefCollection.Count > 0)
                {
                    sb.Append(_adsiConfig.RefCollection.Count.ToString());
                    sb.Append(" Domain(s):<br>");
                    CrossReferenceCollection.CrossReference crossRef;
                    foreach (CrossReferenceCollection.CrossReference tempLoopVar_crossRef in _adsiConfig.RefCollection)
                    {
                        crossRef = tempLoopVar_crossRef;
                        sb.Append(crossRef.CanonicalName);
                        sb.Append(" (");
                        sb.Append(crossRef.NetBIOSName);
                        sb.Append(")<br>");
                    }

                    if (_adsiConfig.RefCollection.ProcesssLog.Length > 0)
                    {
                        sb.Append(_adsiConfig.RefCollection.ProcesssLog + "<br>");
                    }
                }
                else
                {
                    sb.Append("[LDAP Error Message]<br>");
                }
            }
            catch (COMException ex)
            {
                sb.Append("[LDAP Error Message]<br>");
                sb.Append(ex.Message + "<br>");
            }

            if (_adsiConfig.ProcessLog.Length > 0)
            {
                sb.Append(_adsiConfig.ProcessLog + "<br>");
            }

            return(sb.ToString());
        }
Exemple #4
0
 public ADSIProvider()
 {
     _portalSettings = PortalController.GetCurrentPortalSettings();
     _adsiConfig     = ADSI.Configuration.GetConfig();
 }
        /// <summary>
        /// Obtain Authentication Configuration
        /// </summary>
        /// <remarks>
        /// Accessing Active Directory also cost lots of resource,
        /// so we only do it once then save into application cache for later use
        /// </remarks>
        /// <history>
        ///     [tamttt]	08/01/2004	Created
        /// </history>
        public static Configuration GetConfig()
        {
            PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
            string strKey = ADSI_CONFIG_CACHE_PREFIX + "." + _portalSettings.PortalId.ToString();

            Configuration config = (Configuration)DataCache.GetCache( strKey );
            if( config == null )
            {
                config = new Configuration();
                DataCache.SetCache( strKey, config );
            }

            return config;
        }