GetRole

Returns the role with a specified name or GUID.

Syntax

IRole GetRole (string name)

IRole GetRole (Guid id)

Parameter

Specify the following parameter when using this method:

Parameter Description
name The name of the role.
id The GUID of the role.

Return value

The role with the specified name, or null if no match is found.

Exceptions

GetRole may throw one of the following exceptions:

  • ApplicationException if it can’t find authorization data for the zone or if it failed to get the role (see the message returned by the exception for the reason).

  • ArgumentException if the parameter is null or empty.

Example

The following code sample illustrates using the GetRole method in a script:

...  
// Get the zone object
IHierarchicalZone objZone =  
cims.GetZoneByPath("cn=" + strZone + "," + strContainerDN) as IHierarchicalZone;

if (objZone == null)  
{  
    Console.WriteLine("Zone " + strZone + " does not exist.");  
    return;  
}  
IRole role = objZone.GetRole(strRole);  
if (role == null)  
{  
    Console.WriteLine(strRole + " does not exist in zone.");  
}  
else if (objZone.GetAccessGroup(role, strGroup) != null)  
{  
    Console.WriteLine("Role assignment already exist.");  
}  
else  
{  
    // assign a role to the group
    IRoleAssignment zag = objZone.AddAccessGroup(strGroup);  
    zag.Role = role;  
    zag.Commit();  
}  
...