次の方法で共有


How to Add a Permission to a User Role

 

Applies To: System Center 2016 - Service Provider Foundation, System Center Technical Preview

In Service Provider Foundation, sometimes a user cannot accomplish a task because the user is missing a required permission. Permissions can be added to a user as long as the current user can manage permissions by using the UserRoles OData collection.

The way Service Provider Foundation works with user role permissions might be confusing at first. A UserRole entity does not have a property to change permissions directly. Instead, you set the UserRole.PermissionInput property to a collection of UserRolePermission objects. Each UserRolePermission object represents all permissions that the user has on a specific stamp. When the UserRole entity is updated, the UserRole.PermissionInput property is processed. Each UserRolePermission is read and replaces all existing permissions for the associated stamp that the user role has.

You likely want to preserve existing permissions by copying them to the UserRolePermission object, and then add or remove specific permissions.

To add a permission to a user role by using the .NET Framework

  1. Connect to the Service Provider FoundationVMM service.

  2. Obtain the SpfVMM.UserRole to which you want to add a permission.

  3. Create a new instance of the SpfVMM.UserRolePermission class.

  4. Copy the UserRole.Permission to a new list or array of strings.

  5. Add the new permissions to the list or array of permission strings.

  6. Set the UserRolePermission.Permission property to a new instance of the System.Collections.ObjectModel.ObservableCollection``1 class, which provides the array of permission strings.

  7. Set the UserRolePermission.StampId property to the stamp Id to which the user permissions applies.

  8. Add the UserRolePermission that you created to the UserRole.PermissionInput collection.

  9. Call the UpdateObject method on the VMM service object reference and pass in the changed UserRole object.

  10. Call the SaveChanges method on the VMM service object reference.

To add a permission to a user role by using HTTP

  1. Create a new HTTP PUT or MERGE operation.

    Important

    If you supply only the key and changed properties, use a MERGE operation. PUT is used when you want to replace all properties on the entity with new or default values. The MERGE operation updates the existing entity with the supplied properties. PUT updates the existing entity with the supplied properties, but resets all missing properties back to their default values.

  2. Set the URL to a specific user role identifier with the UserRoles collection: https://server:30005/subscription-id/services/systemcenter/vmm/UserRoles/user-role-id.

    Important

    The subscription-id that is used must have permissions to alter the permissions of a user role.

    Tip

    Provide the GUID of the user role on the URL. The previous example uses user-role-id as a placeholder.

  3. Add the HTTP headers.

    Specifically, add the x-ms-principal-id header, which can be set to any value.

  4. Create the HTTP payload that contains the user role entity with at least the ID and PermissionInput properties set.

  5. Submit the HTTP request.

Example

The following code example shows how to add the Checkpoint permission to an existing user role by using the .NET Framework. This code example also preserves all existing permissions that the user role already has. For more information, seeProgramming in Visual Studio with Service Provider Foundation Services.

SpfVMM.VMM vmmService = new SpfVMM.VMM(new Uri("https://wapserver:30005/97FD50F3-1DC0-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/"));  
vmmService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;  
  
// Get the existing user role  
var userRole = vmmService.UserRoles.Where(ur => ur.Name == "john@contoso.com_97fd50f3-1dc0-41b6-a7c0-2b4ff4c3f7e3").FirstOrDefault();  
  
if (userRole != null)  
{  
    // Create the replacement permission object  
    var permission = new SpfVMM.UserRolePermission();  
  
    // Preserve the existing permissions using System.Linq extensions  
    var perms = userRole.Permission.ToList();  
  
    // Add the new permission  
    perms.Add("Checkpoint");  
  
    // create the new permission object  
    permission.Permission = new System.Collections.ObjectModel.ObservableCollection(perms);  
    permission.StampId = new Guid("ba4146fa-fb41-4f59-a193-ad00c52a138c");  
  
    // Add the permissions to the user role  
    userRole.PermissionInput.Add(permission);  
  
    vmmService.UpdateObject(userRole);  
    vmmService.SaveChanges();  
}  
  

Example

The following code example shows an HTTP request that is sent to the server.

  
MERGE https://wapserver:30005/BA4146FA-FB41-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/UserRoles/97fd50f3-1dc0-41b6-a7c0-2b4ff4c3f7e3 HTTP/1.1  
DataServiceVersion: 3.0;NetFx  
MaxDataServiceVersion: 3.0;NetFx  
Accept: application/json;odata=minimalmetadata  
Accept-Charset: UTF-8  
DataServiceUrlConventions: KeyAsSegment  
User-Agent: Microsoft ADO.NET Data Services  
x-ms-principal-id: user@contoso.com  
Content-Type: application/json;odata=minimalmetadata  
Host: wapserver:30005  
Content-Length: 839  
Expect: 100-continue  
Authorization: Negotiate YIIGXgYGKwYBBQUCoIIGUjCCBk6gMDAuBgkqhkiC9xIBAgI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1dc0-41b6-a7c0-2b4ff4c3f7e3",  
    "PermissionInput": [{  
        "Permission": ["Create",  
                  "PauseAndResume",  
                  "Start",  
                  "Stop",  
                  "AllowLocalAdmin",  
                  "Remove",  
                  "Shutdown",  
                  "Checkpoint",  
                  "Author",  
                  "CanShare",  
                  "CanReceive",  
                  "CreateFromVHDOrTemplate",  
                  "CheckpointRestoreOnly",  
                  "AuthorVMNetwork",  
                  "Checkpoint"  
        ],  
        "Permission@odata.type": "Collection(Edm.String)",  
        "StampId": "ba4146fa-fb41-4f59-a193-ad00c52a138c"  
    }],  
    "PermissionInput@odata.type": "Collection(VMM.UserRolePermission)",  
    "odata.type": "VMM.UserRole"  
}  
  

Example

The following code example shows an HTTP response from the server.

HTTP/1.1 204 No Content  
Cache-Control: no-cache  
Server: Microsoft-IIS/8.5  
x-ms-request-id: 0b494a73-66e6-4b86-b1cf-90d3a7432622  
X-Content-Type-Options: nosniff  
request-id: eda9bde6-834a-0000-95d9-aced4a83ce01  
DataServiceVersion: 1.0;  
X-AspNet-Version: 4.0.30319  
Persistent-Auth: true  
X-Powered-By: ASP.NET  
Date: Mon, 19 Aug 2013 21:59:34 GMT