简体   繁体   English

如何检查服务应用程序的权限?

[英]How to check the permissions of a Service Application?

I'm trying to check and see if a specific user has permissions on a specific Service Application, but I'm not having much luck. 我正在尝试检查特定用户是否对特定服务应用程序具有权限,但是运气不佳。 So far, I have managed to check if the current user has permissions with code similar to the following: 到目前为止,我已经设法检查当前用户是否具有类似于以下代码的权限:

SPCentralAdministrationSecurity security = serviceApp.GetAdministrationAccessControl();
var acl = security.ToAcl();
bool hasAccess = acl.DoesUserHavePermissions(SPCentralAdminRights.FullControl);

However, like I said, I need to check the permission of a specific user, not necessarily the current user. 但是,就像我说的,我需要检查特定用户的权限,而不必检查当前用户的权限。 Does anyone know of a way to accomplish this? 有人知道实现此目标的方法吗?

Edit: 编辑:

I somehow didn't realize that acl was actually a list. 我以某种方式没有意识到acl实际上是一个列表。 I looped through it to find the administrators for the service application, which is half the battle! 我遍历了它,找到了服务应用程序的管理员,这是成功的一半! But I still need to find the accounts listed under Permissions to see which accounts have access to invoke the service app. 但是我仍然需要找到“权限”下列出的帐户,以查看哪些帐户有权调用服务应用程序。 Any help is appreciated. 任何帮助表示赞赏。

After some more research, I've found an answer! 经过更多研究后,我找到了答案! Here's the detailed code: 这是详细的代码:

foreach (SPService service in SPFarm.Local.Services)
{
    if (service.Name.Equals("ServiceName"))
    {
        foreach (SPServiceApplication serviceApp in service.Applications)
        {
            //This gets the service app administrators
            SPCentralAdministrationSecurity serviceAppSecurity = serviceApp.GetAdministrationAccessControl();
            SPAcl<SPCentralAdministrationRights> adminAcl = serviceAppSecurity.ToAcl();

            foreach (SPAce<SPCentralAdministrationRights> rights in adminAcl)
            {
                //Handle users
            }

            //This gets the users that can invoke the service app
            SPIisWebServiceApplication webServiceApp = (SPIisWebServiceApplication) app;
            SPIisWebServiceApplicationSecurity webServiceAppSecurity = webServiceApp.GetAccessControl();
            SPAcl<SPIisWebServiceApplicationRights> invokerAcl = webServiceAppSecurity.ToAcl();

            foreach (SPAce<SPIisWebServiceApplicationRights> rights in invokerAcl)
            {
                //Handle users
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在SharePoint 2010中获取服务应用程序权限 - How to get Service Application Permissions in SharePoint 2010 如何在使用WMI进行权限检查期间阻止应用程序挂起 - How to prevent application hang during permissions check using WMI 如何检查上下文是 Windows 服务还是控制台应用程序 - How to check if the context is a Windows Service or a Console Application 如何调试服务应用程序并检查应用程序缺少哪个依赖项 - How to debug a service application and check which dependency is missing from application 使用C#更改/检查NETWORK SERVICE帐户的权限(读取,写入等) - Change / Check permissions (Read, Write,…) for the NETWORK SERVICE account with C# Web服务需要检查用户的NTFS文件权限 - Web service needs to check NTFS file permissions for user 如何设置正确的Windows服务权限 - How to set right Windows Service permissions 如何检查具有网站集的用户的权限? - How to check the permissions of a user with a site collection? 如何检查ASP.NET MVC用户是否从单独的WCF服务应用程序进行了身份验证和授权? - How to check an ASP.NET MVC user is authenticated and authorized from a separate WCF service application? Azure Web 应用程序 - 如何使用委托和应用程序权限 - Azure Web Application - how to use both delegated and Application permissions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM