Retrieving users, current user, groups, group members and group managers from the client

Posted: 3 May 2009 in CSSDK, Groups, Java, Security, Teamsite, Users

The security context of the TeamSite server can be accessed through the client. With the client, we can call getUser(), getCurrentUser() and getGroup() methods to retrieve the security details we’re after.

CSUser currentUser = client.getCurrentUser();
CSUSer someUser = client.getUser("johndoe", true);
CSGroup someGroup = client.getGroup("marketing",true);
CSIterator someGroupMembersIterator = someGroup.getUsers(false);
CSIterator someGroupManagersIterator = someGroup.getAdministrators();

The boolean parameter to the getUser() and getGroup() methods indicate that the server validates the user or the group before returning it. Otherwise, the user is validated upon the first method invoked on the returned object. I would recommend to always validate the user or group and know straight-away about possible exceptions rather than be surprised by them later on in the program. Hence, I always pass true as a value to those 2 functions.

Retrieving all the groups and all the users within Teamsite is easy too from the client.

CSIterator groupsIterator = client.getPrincipalManager().getAllTSGroups();
 while (groupsIterator.hasNext()) {
 CSGroup someGroup = (CSGroup);
 CSIterator usersIterator = client.getPrincipalManager().getAllTSUsers();
 while (usersIterator.hasNext()) {
 CSUser someUser = (CSUser);

Also, the getUser() and getGroup() methods may return null if the user or group is not found. Thus, the returned object must be evaluated before being used.

CSUser someUser = client.getUser("johndoe", true);
if (someUser!=null){
    System.out.println(someUser.getName() + ":" + someUser.getFullName());
CSGroup someGroup = client.getGroup("marketing",true);
if (someGroup!=null){
    System.out.println(someGroup.getName() + ":" + someGroup.getDescription());

The CSIterator class extends Iterator so that we can loop on each one of them and display their names, for example.

while (someGroupMembersIterator.hasNext()){
    CSUser groupMember=(CSUser);
    System.out.println(groupMember.getName() + " belongs to group " + someGroup.getName());
while (someGroupManagersIterator.hasNext()){
    CSUser groupManager=(CSUser);
    System.out.println(groupManager.getName() + " manages group " + someGroup.getName());

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s