It's all about the answers!

Ask a question

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


0
1
Nate Decker (37814061) | asked Oct 09 '15, 11:04 a.m.

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?


Comments
Nate Decker commented Oct 09 '15, 11:39 a.m. | edited Oct 09 '15, 2:52 p.m.

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.


Nate Decker commented Oct 09 '15, 2:52 p.m.

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
Nate Decker (37814061) | answered Dec 04 '15, 3:48 p.m.

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");

Your answer


Register or to post your answer.