我正在使用VBScript使用LDAP脚本在我的应用程序与OID(Oracle身份目录)之间进行身份验证。我成功地进行了身份验证。下一步涉及获取用户所属的所有组,并使用我的应用程序中的组进行映射。由于某些原因,我无法从LDAP服务器获取组信息。我知道我应该查询的属性是“groupmembership”。但我无法从此属性中获取任何值。需要任何帮助。这是我所拥有的代码片段 -
'ldapauth.vbs
'Version: 1.0
'Use: c:\cscript ldapauth.vbs <userName> [<password>]
'Ex - Anonymous: c:\>cscript ldapauth.vbs svc_testconsona
'Ex - Authenticated: c:\>cscript ldapauth.vbs svc_testconsona wipro@123
Dim oUser 'LDAP object holding user info
Dim oDSP 'Directory Service Provider
Dim oArgs 'Command line arguments
Dim sCN 'search parameter - LDAP attribute: CN
Dim sPWD 'CN's password parameter
Dim sRoot 'Holds the root of the LDAP object
Dim sDN 'Distinguished Name of authenticating account
Dim sLDAPsrv 'LDAP server
Dim sLDAPsb 'LDAP search base
Dim bAuthQuery 'Query Type - True=Authenticated, False=Anonymous
CONST ADS_SECURE_AUTHENTICATION = &H0001
CONST ADS_USE_ENCRYPTION = &H0002
CONST ADS_USE_SSL = &H0002
CONST ADS_READONLY_SERVER = &H0004
CONST ADS_NO_AUTHENTICATION = &H0010
CONST ADS_FAST_BIND = &H0020
CONST ADS_USE_SIGNING = &H0040
CONST ADS_USE_SEALING = &H0080
CONST ADS_USE_DELEGATION = &H0100
CONST ADS_SERVER_BIND = &H0200
Const ADS_PROPERTY_NOT_FOUND = &h8000500D
sLDAPsrv = "myserver.domain.com:389"
sLDAPsb = "ou=Active,o=CMI"
'Get the command line args
set oArgs=WScript.Arguments
'Check command line args
On Error Resume Next
sCN = oArgs.item(0) 'username
If Err.Number <> 0 Then
Echo ""
Echo "**** ERROR: No username supplied."
Echo ""
Echo "Use: c:\>cscript ldapauth.vbs <userName> [<password>]"
Echo ""
Echo "Aborting..."
Echo ""
WScript.Quit
End If
sRoot = "LDAP://" & sLDAPsrv & "/cn=" & sCN & "," & sLDAPsb
sDN = "cn=" & sCN & "," & sLDAPsb
wscript.echo "the query is:"
wscript.echo sRoot
On Error Resume Next
sPWD = oArgs.item(1) 'password
If Err.Number <> 0 Then 'This will be a non-authenticated query
bAuthQuery = False
Echo ""
Echo "Performing anonymous LDAP query..."
Echo ""
Else 'This will be an authenticated query
bAuthQuery = True
Echo ""
Echo "Performing authenticated LDAP query..."
Echo ""
End If
'Done checking command line args
'Set directory service provider
Set oDSP = GetObject("LDAP:")
'Perform requested type of query - anonymous or authenticated
If bAuthQuery Then 'authenticated query requested
'Set the LDAP object query
On Error Resume Next
Set oUser = oDSP.OpenDSObject(sRoot,sDN,sPWD,ADS_SERVER_BIND)
If Err.Number <> 0 Then
If Err.Number = "-2147023570" Then
Echo "**** ERROR: Authentication failed. Check username, password and search base."
ElseIf Err.Number = "-2147016646" Then
Echo "**** ERROR: LDAP server not found."
Else
Echo "**** ERROR: Unable to bind to LDAP server. " & Err.Number
End If
Echo ""
Echo "Use: c:\>cscript ldapauth.vbs <username> <password>"
Echo ""
Echo "Aborting..."
Echo ""
WScript.Quit
End If
Else 'anonymous query requested
'Set the LDAP object query
On Error Resume Next
Set oUser = oDSP.OpenDSObject(sRoot,vbNullString,vbNullString,ADS_SERVER_BIND AND ADS_NO_AUTHENTICATION)
If Err.Number <> 0 Then
If Err.Number = "-2147016656" Then
Echo "**** ERROR: Username not found."
ElseIf Err.Number = "-2147016646" Then
Echo "**** ERROR: LDAP server not found."
Else
Echo "**** ERROR: Unable to bind to LDAP server. " & Err.Number
End If
Echo ""
Echo "Use: c:\>cscript ldapauth.vbs <username [<password>]"
Echo ""
Echo "Aborting..."
Echo ""
WScript.Quit
End If
End If
'Populate the user property cache
oUser.GetInfo
'Iterate through available user attributes
For count = 0 to (oUser.PropertyCount-1)
sAttribName = oUser.Item(CInt(count)).Name
-'This line fetches the attribute name poroperly. But values from groupmembership is not getting it.
if sAttribName = "groupmembership" then
sAttribVal = oUser.GetInfoEx(sAttribName)
else
sAttribVal = oUser.Get(sAttribName)
end if
If IsArray(sAttribVal) Then
For Each sMultiVal in oUser.GetEx(sAttribName)
sAttribList = sAttribList & sAttribName & Space(16-Len(sAttribName)) & ":: " & sMultiVal & vbCRLF
Next
Else
sAttribList = sAttribList & sAttribName & Space(16-Len(sAttribName)) & ": " & sAttribVal & vbCRLF
End If
sAttribName = ""
sAttribVal = ""
if err.number <> 0 then
err.Clear
end if
Next
Echo sAttribList
'Clean up
set oDSP=Nothing
set oUser=Nothing
wscript.Quit
Sub Echo(byref message)
WScript.Echo message
End Sub
答案 0 :(得分:2)
OID通常没有名为groupmembership
的用户的属性(除非您自己添加了一个属性)。
如果您要查找用户所属的组,则必须对组进行第二次ldap搜索。
OID中的组具有groupOfNames
或groupOfUniqueNames
作为其对象类。这些对象类中的每一个都具有用于存储组成员名称的多值属性。将用户分配到组时,会将其DN添加到相应的多值属性中。在groupOfNames
对象类中,此多值属性是成员,而在groupOfUniqueNames
对象类中,它是uniqueMember
。