How to get a user's login details with scriptrunner

Egor Braguntsov May 2, 2023

How to get a user's login details with scriptrunner

1 answer

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 2, 2023

Welcome to the Atlassian Community!

I am sorry that I do not quite understand the question, and need to ask for a bit more detail.

What "login details" are you looking for?  

When someone logs into Jira, Jira uses the configured identity provider system(s) to ask the user to uniquely identify themselves, so that it knows that the account logged into belongs to the person logging in.

In the basic case, all you really have available is "this account can log in", "unique ID for this account (with associated display name and email)" and "has logged in".

You can then go off and ask the IDP for more detail about the account in SR, but what you can extract from that depends entirely on the IDP and how it's been integrated.

So, could you clarify "login details" for us?

Egor Braguntsov May 2, 2023

Login details is what administrators can see when they hit "User management" -> "Users". Is there a way to get this information on the screenshot? with scriptrunner

Screenshot from 2023-05-02 18-30-02.png

Ken McClean
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 3, 2023

You can use the LoginManager class to accomplish this. Here's an example that returns the login count of the supplied user:


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager

def loginManager = ComponentAccessor.getComponent(LoginManager)
def loginDetails = loginManager.getLoginInfo("admin")

loginDetails.getLoginCount()

 


Worth noting is that if you're working with timestamps such as LastLoginDate, it'll be returned in the Unix Epoch format. So you'll need to do some conversion.
Like Egor Braguntsov likes this
Egor Braguntsov May 4, 2023

Thanks, that's what I needed

Suggest an answer

Log in or Sign up to answer