chrisg

Getting at Roles via the API

 

So you want to get at the roles inside of blackpearl via the API. Well it is quite simple really and here is an example. Let's say you want to list out all the users that are members of a role.

 

 

/Get all the user names for the specified role

UserRoleManagerServer rClient = new UserRoleManagerServer();

string sRoleName = "HR Managers";

 

//Build a SC Connection String

SCConnectionStringBuilder cb = new SCConnectionStringBuilder();

cb.Host = "localhost";

cb.Port = 5555;

cb.Integrated = true;

cb.IsPrimaryLogin = true;

 

//Open the connection to K2

rClient.CreateConnection();

rClient.Connection.Open(cb.ToString());

 

//Obtain a collection of users for this role

IUserCollection roleUsers = rClient.ResolveQueue(sRoleName);

foreach (IUser user in roleUsers)

{

//Write each username to the console

Console.WriteLine(user.UserID);

}

 

//Close the Connection

rClient.Connection.Close();

 

 

 

Be aware the if these roles have within their membership any "groups", each group will be resolved internally, as a result the list returned will be the resolved users. In addition, if the role has any excluded users and/or groups these will also be removed from the list that the API returns.

 

Check it out, HAPPY CODING!

Published Tuesday, April 29, 2008 8:16 PM by chrisg

Comments

 

ProcHunter said:

How do you get a list of those k2 Roles?

June 14, 2008 6:24 PM
 

ProcHunter said:

HERE IS HOW YOU GET A LIST OF K2 Roles as defined in BlackPearl

//Build a SC Connection String

SCConnectionStringBuilder cb = new SCConnectionStringBuilder();

cb.Host = "localhost";

cb.Port = 5555;

cb.Integrated = true;

cb.IsPrimaryLogin = true;

SourceCode.Security.UserRoleManager.Management.UserRoleManager rClientG = new SourceCode.Security.UserRoleManager.Management.UserRoleManager();

rClientG.CreateConnection();

rClientG.Connection.Open(cb.ToString());

string[] sroles = rClientG.GetRoleNameList();

June 14, 2008 6:32 PM
Anonymous comments are disabled

About chrisg

I am responsible for community development for SourceCode. I have been in technology for over 14 years mainly in infrastructure and security. I absolutely love technology especially new stuff and gadgets.