如何在SSRS报告中确定当前用户所在的AD安全组?

时间:2008-11-06 14:12:56

标签: reporting-services

我需要在SQL Server Reporting Services报告中确定用户所属的安全组。对报告的访问将由两个组中的一个成员驱动:'report_name_summary'和'report_name_detail'。一旦用户执行报告,我们希望能够在“report_name_detail”组中使用其成员资格(或缺少成员资格)来确定是否应允许“向下钻取”。

我不知道如何开箱即可访问当前用户的AD安全组成员资格,但我们愿意接受能够从报告中访问此信息的任何建议。

2 个答案:

答案 0 :(得分:5)

您可以向报告添加自定义代码。 This link有一些例子。

理论上,您应该能够编写这样的代码,然后使用返回值来显示/隐藏您想要的内容。但是,您可能会遇到此方法的权限问题。

Public Function ShouldReportBeHidden() As Boolean
Dim Principal As New System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())
If (Principal.IsInRole("MyADGroup")) Then
    Return False
Else
    Return True
End If
End Function

或者,您可以将详细报告添加为摘要报告的子报告。然后,您可以使用SSRS中内置的安全功能来限制对子报告的访问。

答案 1 :(得分:1)

在Reporting Services中,只需使用:

Public Function IsMemberOfGroup() As Boolean

If System.Threading.Thread.CurrentPrincipal.IsInRole("MyADGroup") Then
    Return True
Else
    Return False
End If

End Function

this posting

所示

注意:一旦将报告部署到服务器但不在IDE中,这种方法就可以使用。