GetUserRoleAssignment

Returns the role assignment for a specific role for this user.

Syntax

IRoleAssignment GetUserRoleAssignment(IRole role)

Parameter

Specify the following parameter when using this method:

Parameter Description
role The role for which you want the role assignment.

Return value

The role assignment that associates this user with the specified role. Returns null if none exists.

Exceptions

GetUserRoleAssignment throws an ArgumentNullException if you pass null for the role parameter.

Example

The following code sample illustrates using GetUserRoleAssignment in a script:

...  
// Create a CIMS object to interact with AD'
ICims cims = new Cims();  
// Note: There is no cims.connect function.' 
// By default, this application will use the connection to the domain controller

// and existing credentials from the computer already logged in. 
IHierarchicalZone objZone =  
cims.GetZoneByPath("cn=" + strZone + "," + strContainerDN) as IHierarchicalZone;

IUser objUser = cims.GetUserByPath(strUser);  
if (objUser == null)  
{  
    Console.WriteLine("User " + strUser + " does not exist.");  
    return;  
}  
IHierarchicalUser objUnixUser = objZone.GetUserUnixProfile(objUser) as
IHierarchicalUser;  
if (objUnixUser == null)  
{  
    objUnixUser = objZone.AddUserPartialProfile(strUser);  
}  
IRole objRole = objZone.GetRole(strRoleName);  
if (objRole == null)  
{  
    Console.WriteLine("Role " + strRoleName + " does not exist.");  
    return;  
}  
IRoleAssignment objAsg = objUnixUser.GetUserRoleAssignment(objRole);  
if (objAsg == null)  
{  
    Console.WriteLine("Role assginment does not exist.");  
    return;  
}  
else  
{  
    objAsg.Delete();  
    Console.WriteLine("Role " + strRoleName + " was successfully removed from user "
        \+ strUser);  
}  
...