Groovy script to check the User have application access or not

Hi all,

Anyone know how to use Jira api (groovy) to check the user have application access or not. In this case is Jira Software access. I find out below docs on JIRA REST API.

https://docs.atlassian.com/jira/7.1.7/com/atlassian/jira/application/ApplicationAuthorizationService.html#canUseApplication-com.atlassian.jira.user.ApplicationUser-com.atlassian.application.api.ApplicationKey-

https://developer.atlassian.com/static/javadoc/jira/latest/reference/com/atlassian/jira/application/ApplicationKeys.html

I use an interface called ApplicationAuthorizationService which defines canUseApplication method.

Here is my example script:

import com.atlassian.application.api.ApplicationKey
import com.atlassian.jira.application.ApplicationAuthorizationService

public canUseApplication(String username) {
      	def user = userManager.getUserByName(username)
        if (canUseApplication(user,SOFTWARE)){
          return "TRUE"
        }
        else {
          return "FALSE"
        }  
}
import com.atlassian.jira.application.ApplicationAuthorizationService
import com.atlassian.jira.application.ApplicationKeys
import com.atlassian.jira.component.ComponentAccessor

def applicationAuthorizationService = ComponentAccessor.getComponent(ApplicationAuthorizationService)
def userManager = ComponentAccessor.userManager

def user = userManager.getUserByName("admin")

applicationAuthorizationService.canUseApplication(user, ApplicationKeys.SOFTWARE)
2 Likes

Thanks Jamie.
Is there a way to get list of all those who have Jira Software access ?

Doesn’t seem to be… normally it’s licensed by group so you could find the groups and iterate those, otherwise just iterate every active user in the system calling the code above…