wjhguitarman
wjhguitarman

Reputation: 1073

How to get Service Application Permissions in SharePoint 2010

What is the best/easiest way to read Account permissions on a particular Service Application in SharePoint 2010? Currently I have been messing around with:

    var solution = SPFarm.Local.Solutions["Service App Name.wsp"];
    var solutionPermissions = solution. //trying different options here

I have been searching through the different options for what can follow "solution." But so far I am at a loss. Any ideas?

Upvotes: 3

Views: 1200

Answers (2)

athom
athom

Reputation: 1277

The answer from How to check the permissions of a Service Application? may be useful to you:

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
            }
        }
    }
}

Upvotes: 2

tnw
tnw

Reputation: 13877

You could try this via PowerShell. You could run a script from your code and try to interact with the permissions that way.

See this: http://blogs.technet.com/b/spweb/archive/2011/04/13/configure-service-application-permissions-in-sharepoint-2010-using-powershell.aspx

And how to run PowerShell from your code: http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C

Upvotes: 2

Related Questions