【问题标题】:Using the Reporting Services Web Service, how do you get the permissions of a particular user?使用 Reporting Services Web 服务,您如何获得特定用户的权限?
【发布时间】:2009-06-02 15:46:18
【问题描述】:

使用SQL Server Reporting Services Web Service,如何确定特定域用户对特定报告的权限?有问题的用户不是访问 Web 服务的用户。

我正在使用在SSRS 中拥有完全权限的域服务帐户(比如说MYDOMAIN\SSRSAdmin)访问Web 服务。我想以编程方式查找特定报告的域用户(比如说MYDOMAIN\JimBob)的权限。

Web 服务上的GetPermissions() 方法将返回当前用户 拥有的权限列表(MYDOMAIN\SSRSAdmin),但这不是我想要的。如何获得MYDOMAIN\JimBob 的相同权限列表?我不会拥有用户的域密码,因此不能使用他们的凭据调用GetPermissions() 方法。但是,我是从具有完全权限的帐户访问此内容的,因此我认为理论上应该可以使用该信息。

【问题讨论】:

  • JimBob 是否对文件夹等拥有明确的权限?或通过组成员身份,例如 MyDomain\RSUsers
  • 我们几乎所有事情都使用活动目录组。我使用 GetPolicies() 方法找到了这些组。我想我可以然后查询大多数这些组的 AD 以了解他是否在其中。但这并不包括 BUILTIN\Administrators 之类的东西,而且我希望 SSRS 完全能够完成很多额外的代码。

标签: web-services reporting-services permissions


【解决方案1】:

SSRS 从用户的 NT 登录令牌中获取 NT 组。这就是为什么当您被添加到新组时,您需要注销并重新登录。这同样适用于大多数 Windows 检查(SQL Server、共享、NTFS 等)。

如果您知道 NT 组...

您可以直接查询 ReportServer 数据库。我几乎直接从我们用来检查文件夹安全性的一份报告中删除了这一点(C.Type = 1)。过滤 U.UserName。

SELECT
    R.RoleName,
    U.UserName,
    C.Path
FROM
    ReportServer.dbo.Catalog C WITH (NOLOCK)    --Parent
    JOIN
    ReportServer.dbo.Policies P WITH (NOLOCK) ON C.PolicyID = P.PolicyID
    JOIN
    ReportServer.dbo.PolicyUserRole PUR WITH (NOLOCK) ON P.PolicyID = PUR.PolicyID 
    JOIN
    ReportServer.dbo.Users U WITH (NOLOCK) ON PUR.UserID = U.UserID 
    JOIN
    ReportServer.dbo.Roles R WITH (NOLOCK) ON PUR.RoleID = R.RoleID
WHERE
    C.Type = 1 

【讨论】:

  • 感谢您的询问。这看起来给我的结果与 GetPolicies() Web 服务方法相同。它返回 Active Directory 组的名称,这意味着我必须查询 Active Directory 才能获取用户。我想我想做的事情不可能开箱即用,并且需要 GetPolicies() 和查询 AD 的组合。
  • GetPolicies() 方法可用于检索正确的权限。看到这个帖子bi-rootdata.com/2015/03/list-ssrs-items-permissions-using.html
【解决方案2】:

查看“GetPolicies 方法”,您可以在以下链接中看到。

http://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.getpolicies.aspx

【讨论】:

  • 请解释一下你的答案,发布链接是不够的
【解决方案3】:

希望这能让您入门。我在复制文件夹结构时使用它,当我想将我的 SSRS 项目从源服务器“迁移”到目标服务器时,我会使用它从旧服务器向新服务器报告。这是一种在我将项目从源服务器复制到目标服务器后,在一台服务器上获取项目的安全策略,然后在另一台服务器上为相同项目设置安全策略的方法。您必须设置自己的源和目标服务器名称。

using System;

using System.Collections.Generic;
using System.Diagnostics;
using System.Web.Services.Protocols;    //<=== required for SoapException

namespace SSRS_WebServices_Utility
{
internal static class TEST
{


    internal static void GetPoliciesForAnItem_from_Source_ThenSetThePolicyForTheItem_on_Destination(string itemPath)
    {

        string sSourceServer = "SOURCE-ServerName";
        Source_ReportService2010.ReportingService2010 sourceRS = new Source_ReportService2010.ReportingService2010();
        sourceRS.Credentials = System.Net.CredentialCache.DefaultCredentials;
        sourceRS.Url = @"http://" + sSourceServer + "/reportserver/reportservice2010.asmx";


        string sDestinationServer = "DESTINATION-ServerName";
        Destination_ReportService2010.ReportingService2010 DestinationRS = new Destination_ReportService2010.ReportingService2010();
        DestinationRS.Credentials = System.Net.CredentialCache.DefaultCredentials;
        DestinationRS.Url = @"http://" + sDestinationServer + "/reportserver/reportservice2010.asmx";



        Boolean val = true;
        Source_ReportService2010.Policy[] curPolicy = null;
        Destination_ReportService2010.Policy[] newPolicy = null;
        try
        {

            curPolicy = new Source_ReportService2010.Policy[1];
            curPolicy = sourceRS.GetPolicies(itemPath, out val);        //e.g. of itemPath:  "/B2W/001_OLD_PuertoRicoReport"



            //DestinationRS.SetPolicies(itemPath, newPolicy);
            int iCounter = 0;
            //int iMax = curPolicy.Length;

            newPolicy = new Destination_ReportService2010.Policy[curPolicy.Length];
            foreach (Source_ReportService2010.Policy p in curPolicy)
            {
                //create the Policy
                Destination_ReportService2010.Policy pNew = new Destination_ReportService2010.Policy();
                pNew.GroupUserName = p.GroupUserName;
                pNew.GroupUserName = p.GroupUserName;
                Destination_ReportService2010.Role rNew = new Destination_ReportService2010.Role();
                rNew.Description = p.Roles[0].Description;
                rNew.Name = p.Roles[0].Name;

                //create the Role, which is part of the Policy
                pNew.Roles = new Destination_ReportService2010.Role[1];
                pNew.Roles[0]=rNew;
                newPolicy[iCounter] = pNew;
                iCounter += 1;

            }

            DestinationRS.SetPolicies(itemPath, newPolicy);

            Debug.Print("whatever");

        }
        catch (SoapException ex)
        {

            Debug.Print("SoapException: " + ex.Message);


        }
        catch (Exception Ex)
        {
            Debug.Print("NON-SoapException: " + Ex.Message);

        }

        finally
        {
            if (sourceRS != null)
                sourceRS.Dispose();
            if (DestinationRS != null)
                DestinationRS.Dispose();                    

        }
    }

}

}

要调用它,请使用以下命令:

 TEST.GetPoliciesForAnItem_from_Source_ThenSetThePolicyForTheItem_on_Destination("/FolderName/ReportName");

您必须在哪里放置您自己的 SSRS 文件夹名称和报告名称,即项目的路径。

事实上,我使用了一种方法,它遍历 Destination 文件夹中的所有项目,然后像这样调用该方法:

        internal static void CopyTheSecurityPolicyFromSourceToDestinationForAllItems_2010()
    {
        string sDestinationServer = "DESTINATION-ServerName";

        Destination_ReportService2010.ReportingService2010 DestinationRS = new Destination_ReportService2010.ReportingService2010();
        DestinationRS.Credentials = System.Net.CredentialCache.DefaultCredentials;
        DestinationRS.Url = @"http://" + sDestinationServer + "/reportserver/reportservice2010.asmx";

        // Return a list of catalog items in the report server database
        Destination_ReportService2010.CatalogItem[] items = DestinationRS.ListChildren("/", true);

        // For each FOLDER, debug Print some properties
        foreach (Destination_ReportService2010.CatalogItem ci in items)
        {
            {
                Debug.Print("START----------------------------------------------------");
                Debug.Print("Object Name:         " + ci.Name);
                Debug.Print("Object Type:         " + ci.TypeName);
                Debug.Print("Object Path:         " + ci.Path);
                Debug.Print("Object Description:  " + ci.Description);
                Debug.Print("Object ID:           " + ci.ID);
                Debug.Print("END----------------------------------------------------");
                try
                {
                    GetPoliciesForAnItem_from_Source_ThenSetThePolicyForTheItem_on_Destination(ci.Path);
                }
                catch (SoapException e)
                {
                    Debug.Print("SoapException START----------------------------------------------------");
                    Debug.Print(e.Detail.InnerXml);
                    Debug.Print("SoapException END----------------------------------------------------");

                }
                catch (Exception ex)
                {
                    Debug.Print("ERROR START----------------------------------------------------");
                    Debug.Print(ex.GetType().FullName);
                    Debug.Print(ex.Message);
                    Debug.Print("ERROR END----------------------------------------------------");
                }
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 2013-05-10
    • 1970-01-01
    • 2014-11-13
    相关资源
    最近更新 更多