复杂的SQL以查看组中的角色?

复杂的SQL以查看组中的角色?,sql,ms-access,ldap,Sql,Ms Access,Ldap,第一个帖子。。。。 我正在尝试将角色映射到LDAP组成员身份,并希望我能得到一些关于如何分析此问题的帮助,请 一个角色由12个组中的1到12个组组成。 一个角色只能有一个特定组。 我认为一个用户可能有不止一个角色,他们可能不应该,但他们可能。例如: 角色|组 帮助热线|密码重置 安全性|密码重置,启用用户 接收|启用用户,禁用用户 我所拥有的数据是 用户组 史密萨|密码重置 SmithA|启用用户 BloggsJ|密码重置 鼠标|启用用户 MouseM |禁用用户 从中可以看到用户具有以下角色

第一个帖子。。。。 我正在尝试将角色映射到LDAP组成员身份,并希望我能得到一些关于如何分析此问题的帮助,请

一个角色由12个组中的1到12个组组成。
一个角色只能有一个特定组。
我认为一个用户可能有不止一个角色,他们可能不应该,但他们可能。例如:

角色|组
帮助热线|密码重置
安全性|密码重置,启用用户
接收|启用用户,禁用用户

我所拥有的数据是

用户组
史密萨|密码重置
SmithA|启用用户
BloggsJ|密码重置
鼠标|启用用户
MouseM |禁用用户

从中可以看到用户具有以下角色 用户角色
史密斯安全公司
BloggsJ|帮助热线
穆塞姆接待处

无论如何,我都可以修改第一个表,使其更有用,例如,将组拆分为多行,如下面的示例:

角色|组
帮助热线|密码重置
安全性|密码重置
安全性|启用用户
接收|启用用户
接收|禁用用户

我正在努力使用SQL来建立一个用户角色列表,我有一种可怕的感觉,我错过了显而易见的东西。 我正在使用MS Access,这不是家庭作业:)
谢谢

以下是我用来查看LDAP的内容。我从他那里得到了一些想法---

"

'仅供参考,获取GetObject调用中使用的域列表 “先运行这个,看看外面有什么

Dim objNameSpace
Dim Domain
Set objNameSpace = GetObject("WinNT:")
For Each Domain In objNameSpace
   Debug.Print Domain.Name
Next
Exit   ' comment out after first time.
每周例行公事

' initialize   needs reference   Excel 
Dim rc As Long, sFile As String, xls As Excel.Application
' your routine to get an output file name  as sFile
' your routine to create XLS app and open an empty workbook named sFile and make sheet name


' add column headings in row 1
Dim nRow As Long, nCol As Long
Dim sHeading As Variant, myHeadings() As Variant: myHeadings = Array("User", "Group", "yourField3", "yourField4", "Count")
nRow = 1
nCol = 0
For Each sHeading In myHeadings
    nCol = nCol + 1
    xls.ActiveSheet.cells(1, nCol) = myHeadings(nCol - 1)
Next sHeading

' needs reference   "Active DS Type Library"
Dim sGroup As Variant, myGroups() As Variant: myGroups = Array("yourGroup1", "yourGroup2")
' get each group
For Each sGroup In myGroups

    Dim IGroup1 As IADsGroup, IUser1 As IADsUser
    Set IGroup1 = GetObject("WinNT://" & "yourDomain" & "/" & sGroup & ",group")

    ' get each user in that group
    For Each IUser1 In IGroup1.Members

        If (Mid$(IUser1.Name, 1, 6) <> "userToBypass") Then

            Dim IGroup2 As IADsGroup, IUser2 As IADsUser
            Set IUser2 = GetObject("WinNT://" & "yourDomain" & "/" & IUser1.Name & ",user")

            ' get each group for that user
            For Each IGroup2 In IUser2.Groups

                If (Mid$(UCase(IGroup2.Name), 1, 13) <> "GroupToBypass") Then
                    nRow = nRow + 1
                    xls.ActiveSheet.cells(nRow, "A") = IUser2.Name
                    xls.ActiveSheet.cells(nRow, "B") = IGroup2.Name
                    xls.ActiveSheet.cells(nRow, "C") = "yourField3"
                    xls.ActiveSheet.cells(nRow, "D") = "yourField4" ' e.g. IUser2.Role ??
                    xls.ActiveSheet.cells(nRow, "E") = 1
                End If
            Next IGroup2

        End If
    Next IUser1
Next sGroup

' IADs cleanup
Set IGroup2 = Nothing
Set IUser2 = Nothing
Set IGroup1 = Nothing
Set IUser1 = Nothing
它回来了--


解决了…我觉得…淋浴时热水在你头上的作用太神奇了。a) 从角色表中计算每个角色类型的行数。b) 在角色和LDAP表之间执行组连接。c) 计算每个角色不同用户出现的次数。d) 如果该计数与每个角色的组计数相同,则为匹配


我稍后会编写代码,现在要铺屋顶了。

各种连接和联合,甚至都不远程工作。嗨,非常感谢你花时间回答,但我不确定你的回答与这个问题有什么关系。我已经拥有了LDAP中的所有组,现在我需要将它们与我们定义的角色(LDAP外部)关联起来,这是一个数据处理问题。谢谢角色组存储在哪里?这是系统外部的短列表吗?是否可以在上述程序中添加为“常量”列表?或者它们存储在系统中,在这种情况下可以对它们进行“连接”或“查找”?它们也可以存储在我们想要的任何地方。目前我在一个数据库中有两个表。LDAP数据列是用户组,第二个表是角色组角色。请使用上面的示例数据描述生成用户|角色的SQL。我已经修改了上面的答案,并在最后添加了SQL,带有is resultset。啊……我可以看到问题的一部分:)我太受现实世界流程的引导了。用户请求一个角色,比如说“安全性”。为了允许将它们添加到两个组中,“密码重置”和“启用用户”。我试图编写只返回“安全性”而不返回“帮助台”的SQL(请注意,帮助台有“密码重置”组),但这太愚蠢了,事实上,我想强调的是,即使没有请求,他们也在扮演其他角色。
SELECT UserGroup.User, UserGroup.Group, RoleGroup.Role
FROM UserGroup LEFT JOIN RoleGroup ON UserGroup.Group = RoleGroup.Group
ORDER BY UserGroup.User, RoleGroup.Role;
User    Group           Role
BloggsJ Password Reset  Helpdesk
BloggsJ Password Reset  Security
MouseM  Disable User    Reception
MouseM  Enable User     Reception
MouseM  Enable User     Security
SmithA  Password Reset  Helpdesk
SmithA  Enable User     Reception
SmithA  Enable User     Security
SmithA  Password Reset  Security