Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Rest or java API to get a user's security schemes or security levels

Dishant Sharma
Contributor
October 14, 2022

Is there any REST API or Java API through which I can get a user's security schemes or security levels? I want to know to what security level or security scheme the user is added. 

1 answer

1 vote
Charlie Misonne
Community Champion
October 14, 2022

Hi @Dishant Sharma

I'm afrtaid this is not available.

Users can be member of a security scheme via a user group, project role or by being added as individual users.

There is no API endpoint that will show you where a user has been added based on those 3 possibilities or even based on individual users only.

You will have to use several REST APIs yourself to build this logic via scripting. https://docs.atlassian.com/software/jira/docs/api/REST/9.3.0/#api/2/permissionscheme

Dishant Sharma
Contributor
October 14, 2022

@Charlie Misonne thanks for the reply. Is there any Java API that can achieve the same? Through this, I can make a custom Jira plugin and can create an endpoint, and use that one to pass some kind of query parameter and get the user's issue security level or scheme. 

Charlie Misonne
Community Champion
October 14, 2022

Yes, the javadoc is quite complete.

You will need the PermissionSchemeService and loop over all schemes with the getPermissionSchemes() method.

For each permission scheme you can do getPermission() and then get the PermissionGrant objects which has as getHolder() method containing the user, group or role

I haven't tested this but I'm quite sure you should be able to achieve your goal this way.

Security schemes are separate, you will find similar APIs for that via PermissionSchemeService.

Dishant Sharma
Contributor
October 14, 2022

@Charlie Misonne Thank you so much for the reply. Actually, I was looking through the java documentation of Jira and found a better way to achieve that by using the getAllSecurityLevelsForUser() method in the 'com.atlassian.jira.issue.security' package and accepts the user as the parameter for which one wants to keep a check of the accessible security levels. 

 

https://docs.atlassian.com/software/jira/docs/api/7.1.6/com/atlassian/jira/issue/security/IssueSecurityLevelManager.html#getAllSecurityLevelsForUser-com.atlassian.jira.user.ApplicationUser-

Charlie Misonne
Community Champion
October 14, 2022

Ok that's good to know!

But it won't work for the permission schemes.

Dishant Sharma
Contributor
October 14, 2022

@Charlie Misonne yeah, you're right! Actually, I changed my approach from issue security scheme to issue security level for the task that I'm doing. So, this will work in my case. 

But, I have one query. Is there any rest API or some java API to get the issue security scheme on a single issue? And, eventually, I can fetch the security levels inside that issue scheme.

Charlie Misonne
Community Champion
October 17, 2022

The Issue object has a getSecurityLevelId() method https://docs.atlassian.com/software/jira/docs/api/9.3.0/index.html?com/atlassian/jira/issue/Issue.html

You can't get the scheme directly from the issue. You will have to get the scheme from the project via the IssueSecuritySchemeService: https://docs.atlassian.com/software/jira/docs/api/9.3.0/index.html?com/atlassian/jira/issue/security/IssueSecuritySchemeService.html

Suggest an answer

Log in or Sign up to answer