944,129 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 2071
  • ASP RSS
Nov 4th, 2009
0

Active Directory- extracting groups

Expand Post »
Hello!

I am currently doing some authentication in Active Directory.
Our AD is running in Windows 2008 Server and I manage to log-in based in our AD. However I also want to get the group where the user belongs. but I don't know how. Can anyone help me?

here is the authentication in AD I copied...

ASP Syntax (Toggle Plain Text)
  1. <%@ Language="VBScript" %>
  2. <%
  3.  
  4. Option Explicit
  5. Response.Buffer = True
  6.  
  7. '// 1. Form Validation
  8. Dim Submit, UserName, Password, Domain, Result, Message
  9. Submit = "Authenticate"
  10.  
  11. 'Assume Failure
  12. Application("Error")= true
  13.  
  14. If Submit = "Authenticate" Then
  15. response.write("autenthication <br>")
  16. 'Get the input from your HTML form
  17. UserName = Request.Form("UserName")
  18. Password = Request.Form("Password")
  19. Domain = Application("Domain")
  20.  
  21. Session("usern") = UserName
  22. 'Call the AuthenticateUser() function to do the verification process
  23. Result = AuthenticateUser(UserName, Password, Domain)
  24.  
  25. If Result Then
  26. 'If user exist, then redirect to success page
  27. 'login success
  28. Application("Error")= false
  29. Response.Redirect ("success.asp")
  30. Else
  31. 'If user don't exist, redirect to error page
  32. 'login failed
  33. Application("Error")= true
  34. Response.Redirect ("../")
  35. End If
  36. End If
  37.  
  38. '// 2. Authenticate Function
  39. Function AuthenticateUser(UserName, Password, Domain)
  40. Dim strUser, strPassword, strQuery, oConn, cmd, oRS
  41.  
  42. 'Assume Failure
  43. AuthenticateUser = false
  44.  
  45. strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*'"
  46. Set oConn = server.CreateObject("ADODB.Connection")
  47. oConn.Provider = "ADsDSOOBJECT"
  48. oConn.Properties("User ID") = UserName
  49. oConn.Properties("Password") = Password
  50. oConn.Properties("Groups") = "SALES"
  51. oConn.Properties("Encrypt Password") = true
  52. oConn.open "ADProvider", strUser, strPassword
  53. Set cmd = server.CreateObject("ADODB.Command")
  54. Set cmd.ActiveConnection = oConn
  55. cmd.CommandText = strQuery
  56.  
  57. On Error Resume Next
  58. Set oRS = cmd.Execute
  59.  
  60. If oRS.bof OR oRS.eof Then
  61. AuthenticateUser = False
  62. Else
  63. AuthenticateUser = True
  64. End if
  65.  
  66. Set oRS = Nothing
  67. Set oConn = nothing
  68. End Function
  69. '############### CHECKER #########
  70.  
  71. response.write(myString)
  72.  
  73.  
  74. %>
Similar Threads
Reputation Points: 6
Solved Threads: 5
Light Poster
Cruize_Invades is offline Offline
40 posts
since May 2007
Nov 24th, 2009
0

ListADGroups.vbs

Here is some code that found in May:

ASP Syntax (Toggle Plain Text)
  1. '//////////////////////////////////////////////////////////////////////////
  2. '/// Name: ListADGroups.vbs
  3. '/// Version: 1.0
  4. '/// Date: 09/17/02
  5. '/// Purpose: listing information about Active Directory groups
  6. '/// OS: Windows 2000, XP
  7. '/// Reqs: Account with permissions to read Active Directory groups properties
  8. '/// Syntax: cscript /nologo ListADGroups.vbs
  9. '//////////////////////////////////////////////////////////////////////////
  10.  
  11. Option Explicit
  12. On Error Resume Next
  13.  
  14. '////////////////////////////////////////////////////
  15. '/// Variable Declarations
  16.  
  17. Dim oRootDSE, oCon, oCmd, oRecordSet
  18. Dim sDomainADsPath, sUser, sPassword, sGroup, sProperties
  19. Dim aDescription, aMember, iCount
  20.  
  21. '////////////////////////////////////////////////////
  22. '/// Extract domain name of the logged on user account
  23.  
  24. Set oRootDSE = GetObject("LDAP://RootDSE")
  25. sDomainADsPath = "LDAP://" & oRootDSE.Get("defaultNamingContext")
  26. Set oRootDSE = Nothing
  27.  
  28. '////////////////////////////////////////////////////
  29. '/// Create, configure, and open ADO Connection object
  30.  
  31. Set oCon = CreateObject("ADODB.Connection")
  32.  
  33. oCon.Provider = "ADsDSOObject"
  34.  
  35. sUser = "UserName"
  36. sPassword = "Password"
  37.  
  38. oCon.Open "ADProvider", sUser, sPassword
  39.  
  40. '////////////////////////////////////////////////////
  41. '/// Create and configure ADO Command object
  42.  
  43. Set oCmd = CreateObject("ADODB.Command")
  44. Set oCmd.ActiveConnection = oCon
  45.  
  46. sProperties = "name,ADsPath,description,member"
  47. sGroup = "*"
  48.  
  49. oCmd.CommandText = "<" & sDomainADsPath & ">;(&(objectCategory=group)(name=" & sGroup & "));" & sProperties & ";subtree"
  50. oCmd.Properties("Page Size") = 100
  51.  
  52. '////////////////////////////////////////////////////
  53. '/// Populate ADO RecordSet object with AD Group info
  54.  
  55. Set oRecordSet = oCmd.Execute
  56.  
  57. '////////////////////////////////////////////////////
  58. '/// Display results by listing all records in Recordset
  59.  
  60. WScript.Echo "Global Groups for the domain " & Replace(Mid(sDomainADsPath,11), ",DC=", ".")
  61.  
  62. While Not oRecordSet.EOF
  63. WScript.Echo "Name: " & vbTab & oRecordSet.Fields("name")
  64. WScript.Echo "ADsPath: " & vbTab & oRecordSet.Fields("ADsPath")
  65. aDescription = oRecordSet.Fields("description")
  66. If Not IsNull(aDescription) Then
  67. WScript.Echo "Description: " & vbTab & aDescription(0)
  68. End If
  69. aMember = oRecordSet.Fields("member")
  70. WScript.Echo "Members: "
  71. If Not IsNull(aMember) Then
  72. For icount = 0 to UBound(aMember)
  73. WScript.Echo vbTab & vbTab & aMember(iCount)
  74. Next
  75. End If
  76. oRecordSet.MoveNext
  77. Wend
  78.  
  79. '////////////////////////////////////////////////////
  80. '/// Close Recordset and Connection objects
  81.  
  82. oRecordSet.Close
  83. oCon.Close
  84.  
  85. '////////////////////////////////////////////////////
  86. '/// Clean up
  87.  
  88. Set oRecordSet = Nothing
  89. Set oCon = Nothing
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Stitch1920 is offline Offline
4 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: horizontal loop from database records
Next Thread in ASP Forum Timeline: asp upload image





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC