Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How Do I Get the Current User's Repository Permissions (Groups) via Java-API?

I have an operation behavior that needs to know the repository permissions of the user who triggered it. I found this post here on Jazz.net that provided some instructions for how to do this with the "Plain-Java" (client-side) API:

https://jazz.net/forum/questions/157888/how-to-get-repository-permissions-of-user-in-rtc-using-plain-java-api

Unfortunately, I can't use this technique in a Server-Side operation behavior. I had thought that the technique might be similar so I've been using the intellisense and trial-and-error to try and figure out how I should do it.

I found a service and interface that looked promisiting under com.ibm.team.repository.service.userregistry.provider.*

I tried instantiating a class for the IUserRegistryProviderService and then getting the IUserRegistry using the getRegistry() function, but I got an error message saying that this action is only permitted on the JTS server. Since the operation fires on the CCM server, I assume I just can't use this technique.

Does anyone know how to do this?

1

0 votes

Comments

I think I may have found my answer.

I found a service that looked like it might be useful called: com.ibm.team.repository.service.IExternalUserRegistryInfoRestService

I instantiated the class and called my instance ieurirs (lazy naming scheme I patterned after some examples I've seen of iac for IAuditableCommon).

This class has a function called "getUsersInGroup". Following an example I found in the ExternalUserRegistryInfoRestServiceTests class, I created an argument for that function as follows:

ParmsGetUsersInGroup parms = new ParmsGetUsersInGroup();

parms.groupName = IPermissionService.JAZZ_ADMINS;

ResultSetDTO resultSet = ieurirs.getUsersInGroup(parms);

The resultSet then contained what looks like Contributor objects. I'll need to confirm. I printed the objects as strings and I can probably extract what I need from this even if I can't figure the correct data type to cast it to.

This technique works for getting the list of users who belong to a particular group. Since the group I am validating (JazzAdmins) is pretty small, this seems fine. However, it seems like I'd want to be able to do the reverse as well and get the groups that a particular user is a member of. I tried to do that using the ParmsGetUsers function, but it didn't work. The test class I found set the parms.userIdSearchTerm to "*". Presumably, this would cause it to fetch ALL users. That seemed more heavy-handed than what I wanted. I just wanted the current user. I tried searching using the current user's userId, but that didn't find any results. I suppose I might just be formulating the query wrong. I might tinker with that some more.

Disregard the above response. I had a mental lapse and didn't remember that my local sandbox that I use for development is not connected to the LDAP repository. The technique above works for a user registry defined only within the scope of CLM, but doesn't work when trying to fetch that user data when tied to LDAP.

The exception is "UnsupportedUserRegistryException". The error message is: "The configured user registry does not support the requested operation."

So I guess the quest to do this via LDAP continues... Any help is appreciated.



One answer

Permanent link

I found an answer to this but evidently forgot to come back and document it.

IAuditableCommon iac = getService(IAuditableCommon.class);

IContributor currentUser = (IContributor) iac.resolveAuditable(getAuthenticatedContributor(), ItemProfile.createFullProfile(IContributor.ITEM_TYPE), monitor);

IExternalUserRegistryService regService = getService(IExternalUserRegistryService.class);

boolean currentUserIsJazzAdmin = regService.isMember(currentUser.getUserId(), "JazzAdmins");

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937
× 411

Question asked: Oct 09 '15, 11:04 a.m.

Question was seen: 4,049 times

Last updated: Dec 04 '15, 3:48 p.m.

Confirmation Cancel Confirm