Reporting Services 2008 R2 Web 服务 api - 如何管理安全权限?
我正在编写一个 powershell 脚本,以使用 SSRS Web 服务将许多报告部署到 SQL Server Reporting Services 2008 R2。我对这种方法非常满意,创建新的部署文件夹并上传报告很容易。以下是显示文件夹创建的代码片段:
$reportServerUri = "http://{0}/ReportServer/ReportService2005.asmx" -f $reportServerName
$proxy = New-WebServiceProxy -Uri $reportServerUri -Namespace SSRS.ReportingService2005 -Credential $credential
#Dont currently set any properties so set empty array of properties
$propertyArray = @()
$warnings = $proxy.CreateFolder($folderName, $folderParent, $propertyArray)
但是我还希望能够设置该文件夹的权限,这就是我有点卡住的地方。我想要复制的是,从 Web UI 中选择文件夹的安全选项并针对角色添加用户\组。
我认为这可以通过 createFolder 调用上的 propertyArray 来完成,但我还无法在文档中找到任何信息(探测现有属性并且看不到任何相关内容),我一直在查看 http://msdn.microsoft.com/en-us/library/cc282788.aspx 获取指导。于是就到了死胡同。我认为可能有一种特定的方法来管理此级别的权限,但无法识别。
我正在使用 ReportingService2005 Web 服务,我知道也有 2010 Web 服务,但我也无法在那里找到我正在寻找的内容。
有谁知道如何使用 Web 服务 api 添加对文件夹的权限(对于其他对象(如报告和共享数据源)可能是一种一致的方法)?我认为这一定是可能的,因为 Web UI 允许你这样做。这不是一个 powershell 问题,而是关于用于管理权限的 api 的问题。
更新 - 下面是似乎可以完成这项工作的代码片段。我需要对此进行一些改进,因为看起来政策的更新必须包括原始列表,因此我需要获取当前的政策,将我的新政策添加到其中并使用完整列表进行更新。但我稍后会解决这个问题!
$Policies = $global:ssrsproxy.GetPolicies($ItemPath, [ref] $InheritsFromParent)
$PolicyAlreadyExists = $false
$Policies | Foreach-Object{ if ($_.GroupUserName -eq $GroupUserName)
{$PolicyAlreadyExists = $true} }
$Policies | Foreach-Object{ $_ | get-member }
if ($PolicyAlreadyExists){
"Policy already applied."
} else {
$Policy = New-Object SSRS.ReportingService2005.Policy
$Policy.GroupUserName = $GroupUserName
$Roles = @()
$Role = New-Object SSRS.ReportingService2005.Role
$Role.Name = $RoleName
$Roles += $Role
$Policy.Roles = $Roles
$global:ssrsproxy.SetPolicies($ItemPath, $Policy)
"Policy applied."
}
I'm writing a powershell script to deploy a number of reports to SQL Server Reporting Services 2008 R2 using the SSRS web services. I'm pretty happy with the approach, it was easy to create a new deployment folder and upload the reports. Following is a snippet of code showing creation of a folder :
$reportServerUri = "http://{0}/ReportServer/ReportService2005.asmx" -f $reportServerName
$proxy = New-WebServiceProxy -Uri $reportServerUri -Namespace SSRS.ReportingService2005 -Credential $credential
#Dont currently set any properties so set empty array of properties
$propertyArray = @()
$warnings = $proxy.CreateFolder($folderName, $folderParent, $propertyArray)
However I'd also like to be able to set permissions on the folder and this is where I am a bit stuck. What I want to replicate is where, from the web UI, I would select the security option of the folder and add a user\group against a role.
I thought this might be done through the propertyArray on the createFolder call but I haven't been able to find any information in the docs yet (probed existing properties and can't see anything relevant), I've been looking at http://msdn.microsoft.com/en-us/library/cc282788.aspx for guidance. So reached a dead end there. I thought there might be a specific method to manage permissions at this level but have not been able to identify one.
I am using the ReportingService2005 web services, I know there are also 2010 web services but I havent been able to find what I'm looking for there either.
Does anyone know how I add permissions to folders using the web services api (and presumably a consistent method for other objects like reports and shared data sources)? I assume it must be possible as the web UI allows you to do it. This is not a powershell question but instead about the api's to use to manage permissions.
Update - Below is the snippet of code that seems to do the job. I need to refine this a bit as it looks like the update to policies must include the original list so I need to get the current policies, add my new policy to this and update with the full list. But I'll fix that later!
$Policies = $global:ssrsproxy.GetPolicies($ItemPath, [ref] $InheritsFromParent)
$PolicyAlreadyExists = $false
$Policies | Foreach-Object{ if ($_.GroupUserName -eq $GroupUserName)
{$PolicyAlreadyExists = $true} }
$Policies | Foreach-Object{ $_ | get-member }
if ($PolicyAlreadyExists){
"Policy already applied."
} else {
$Policy = New-Object SSRS.ReportingService2005.Policy
$Policy.GroupUserName = $GroupUserName
$Roles = @()
$Role = New-Object SSRS.ReportingService2005.Role
$Role.Name = $RoleName
$Roles += $Role
$Policy.Roles = $Roles
$global:ssrsproxy.SetPolicies($ItemPath, $Policy)
"Policy applied."
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 SetPolicies 方法。首先定义包含组/用户的 策略 数组和所需的角色,然后将此数组与该项目一起传递给 SetPolicies。
Use the SetPolicies method. First define an array of Policy(s) containing group/user and required roles, then pass this array to SetPolicies along with the item.