[英]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.