Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Active Directory Group Membership
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Active Directory Group Membership

 Post Reply Post Reply Page  <123
Author
switchbak View Drop Down
Newbie
Newbie
Avatar

Joined: 23 August 2006
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote switchbak Quote  Post ReplyReply Direct Link To This Post Posted: 23 August 2006 at 11:33pm
I can't find the other thread, so I'm gonna post this here.
 
Here's what I've done to populate my forum groups based on my Active Directory groups:
 
in functions_windows_authentication.asp i changed the code that says:
 
  'We need to get the start user group ID from the database
  'Initalise the strSQL variable with an SQL statement to query the database
                'strSQL = "SELECT " & strDbTable & "Group.Group_ID " & _
                '"FROM " & strDbTable & "Group" & strDBNoLock & " " & _
                '"WHERE " & strDbTable & "Group.Starting_group = " & strDBTrue & ";"
 
 
to
 
 
 
  dim ADS_SCOPE_SUBTREE
  dim objConnection
  dim objCommand
  dim objRecordSet
  dim distName
  dim arrMemberOf
  dim theGroup
  dim objUser
  dim theGroupList
  dim intPrimaryGroupID
     
  ADS_SCOPE_SUBTREE = 2
  Set objConnection = CreateObject("ADODB.Connection")
  Set objCommand = CreateObject("ADODB.Command")
       
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
       
  Set objCommand.ActiveConnection = objConnection
  objCommand.CommandText = "Select distinguishedName, primaryGroupToken from 'LDAP://DC=my,DC=domain'  where sAMAccountName=' " & strUserName & "'"
  objCommand.Properties("Page Size") = 100
  objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
  Set objRecordSet = objCommand.Execute
  If objRecordSet.RecordCount > 0 Then
   objRecordSet.MoveFirst
       
   distName = vbNullString
   distName = objRecordSet.Fields("distinguishedName").Value           
  else
   'user not found in AD
  End If
  
  if distName <> vbnullstring then
   'lookup all groups but primary
   Set objUser = GetObject("LDAP://" & distname)  
   arrMemberOf = objUser.GetEx("memberOf")
   intPrimaryGroupID = objUser.Get("primaryGroupID")
   For Each theGroup in arrMemberOf
    theGroupList = theGroupList & lcase(theGroup) & ","
   Next
   'look up primary group
   objCommand.CommandText = "<;(objectCategory=Group);distinguishedName,primaryGroupToken;subtree">;(objectCategory=Group);distinguishedName,primaryGroupToken;subtree">LDAP://DC=my,DC=domain>;(objectCategory=Group);distinguishedName,primaryGroupToken;subtree"
   Set objRecordSet = objCommand.Execute
   objRecordSet.MoveFirst       
   Do Until objRecordset.EOF
    If objRecordset.Fields("primaryGroupToken") = intPrimaryGroupID Then
    theGroupList = theGroupList & lcase(objRecordSet.Fields("distinguishedName").Value) & ","
    End If
    objRecordset.MoveNext
   Loop
 
   'look for specific groups:
   'enterprise admins = db admins
   '_faculty = moderators
   'everyone else = newbies
   if instr(theGroupList,"enterprise admins,") <> 0 then
    'admin
    'We need to get the start user group ID from the database
    'Initalise the strSQL variable with an SQL statement to query the database
                  strSQL = "SELECT " & strDbTable & "Group.Group_ID " & _
                  "FROM " & strDbTable & "Group" & strDBNoLock & " " & _
                  "WHERE " & strDbTable & "Group.Name = 'Admin Group';" 
   elseif instr(theGroupList,"_faculty,") <> 0 then
    'moderators
    'We need to get the start user group ID from the database
    'Initalise the strSQL variable with an SQL statement to query the database
                  strSQL = "SELECT " & strDbTable & "Group.Group_ID " & _
                  "FROM " & strDbTable & "Group" & strDBNoLock & " " & _
                  "WHERE " & strDbTable & "Group.Name = 'Moderator Group';"
   else
    'newbies
    'We need to get the start user group ID from the database
    'Initalise the strSQL variable with an SQL statement to query the database
                  strSQL = "SELECT " & strDbTable & "Group.Group_ID " & _
                  "FROM " & strDbTable & "Group" & strDBNoLock & " " & _
                  "WHERE " & strDbTable & "Group.Starting_group = " & strDBTrue & ";"
   end if
  else
   'newbies
   'We need to get the start user group ID from the database
   'Initalise the strSQL variable with an SQL statement to query the database
                 strSQL = "SELECT " & strDbTable & "Group.Group_ID " & _
                 "FROM " & strDbTable & "Group" & strDBNoLock & " " & _
                 "WHERE " & strDbTable & "Group.Starting_group = " & strDBTrue & ";"
  end if


Edited by switchbak - 23 August 2006 at 11:35pm
Back to Top
 Post Reply Post Reply Page  <123

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.