Role Management

Roles are used in K2 as a container for users and groups. A role can be defined across multiple user managers. Users can come from Active Directory, Database based, Custom providers and SmartObjects.

Role must contain at least one RoleItem. Using the UserRoleManager API you can create, delete and update roles. You can resolve a role to its members and get a list of role items.

using SourceCode.Hosting.Client.BaseAPI;
using SourceCode.Security.UserRoleManager.Client;UserRoleManagerServer umClient = new UserRoleManagerServer();
SCConnectionStringBuilder cb = new SCConnectionStringBuilder();
//Build a SC Connection String
cb.Host = “localhost”;
cb.Port = 5555;
cb.Integrated = true;
cb.IsPrimaryLogin = true;//Open the connection to K2

//Obtain a collection of users for this role
IUserCollection roleUsers = umClient.ResolveQueue(textBox1.Text);
foreach (IUser user in roleUsers)
//Write each username to the console
textBox2.Text = textBox2.Text + “\r\n” + user.UserID;
}//Close the Connection

A Role has include and exclude collections which allows you to exclude and include members for the role. When you add a RoleItem to a Role you actually add it to the Includes collection or the Excludes collection of the Role. UserItem and GroupItem objects are provided to represent users and groups of the UserManagers.

using SourceCode.Hosting.Server.Interfaces;
using SourceCode.Security.UserRoleManager.Management;UserRoleManager mgr = new UserRoleManager();

//How do I get a list of Roles already defined in K2?
string[] K2Roles = mgr.GetRoleNameList();

//add a new Role
Role role = new Role(rolename);
UserItem user = new UserItem(textBox1.Text);

A Role can be dynamic, meaning the resolution happens just-in-time. Roles can be refreshed automatically by setting a refresh interval as well.

Destination Rules in a workflow map has an advanced setting which allows Roles to be resolved to users when it is executed. This will explicitly assign tasks to relevant users instead of the Role. When a task is assigned to a Role, all included members will have access to the task.

[UPDATE]Here’s another article on this topic :

One response to “Role Management”

  1. […] look at the table structure of this DB it is straight forward. You have tables for Users, Groups and […]

%d bloggers like this: