Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,512
Community Members
 
Community Events
165
Community Groups

Groovy script that lists currently authenticated (logged in right now) users.

Hi,

I'm looking for a groovy script that will give me a list of users that are currently logged in to Jira.  In the Scriptrunner console, I can get a list of all users or users that have never logged in but I don't see a way to get just users that are logged in right now ("right now" = when I run the script in the console).

Thanks in advance for any help.

- B

1 answer

1 accepted

1 vote
Answer accepted

Hi,

you can retrieve all application users.

And getting the last login time of user compares it with a delay (like 1 hour ago).

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.security.login.LoginManager
import groovy.time.TimeCategory

def twoHoursAg
use(TimeCategory) {
twoHoursAgo = 1.hours.ago
}

UserManager userManager = ComponentAccessor.getUserManager()
LoginManager loginManager = ComponentAccessor.getComponent(LoginManager)
userManager.users.findAll{loginManager.getLoginInfo(it.username)?.lastLoginTime!=null && new Date(loginManager.getLoginInfo(it.username)?.lastLoginTime) >= twoHoursAgo}

Great! This will work well enough for my purpose.  Thank you!

Like Djiga Sene likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you