How to find last login date of users in Confluence


Is there a way I can tell the last login date of all users in one screen? I know I can see it by clicking on the user name. However I need to look at over 1500 users and see who has not logged in for a while to be able to deactive these users. We are using Confluence 3.5.17

I have tried some of the earlier posted user macros but the result is either empyt field for last login daye, NEVER or the userlist is showing only ~20 users of the 1500.

Would also need to get the date when the account was created and a tab showing if the user is active or deactivated.

Thanks, Kjell

5 answers

I created a user macro with the help of some answers here that creates a table with the Name, Create Date, Last Login and number of days since last login (roughly because of the time being in milliseconds).

## @param group:title=Gruppe|type=string|required=true|desc=Group to show

#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)

#set($loginManager = $containerContext.getComponent('loginManager'))
#set($crowdService = $containerContext.getComponent('crowdService'))

#set($group = $userAccessor.getGroup($paramgroup))

    #set($usernames = $userAccessor.getMemberNames($group))

<table class="confluenceTable" width="660px">
        <th class="confluenceTh " width="220px">Name</th>
        <th class="confluenceTh"  width="110px">Create date</th>
        <th class="confluenceTh" width="110px">Last Login</th>
        <th class="confluenceTh" width="110px" style="text-align:center;">Activated</th>
        <th class="confluenceTh" width="110px" style="text-align:center;">Days</th>
    #foreach($username in $usernames)
        #set($user = $userAccessor.getUser($username))
        #set($crowdUser = $crowdService.getUser($
           <td class="confluenceTd">#usernameLink($</td>
           <td class="confluenceTd" style="text-align:center;">$action.dateFormatter.formatGivenString('dd.MM.yyyy', $crowdUser.createdDate)</td>
           <td class="confluenceTd" style="text-align:center;">$action.dateFormatter.formatGivenString('dd.MM.yyyy',$loginManager.getLoginInfo($user).lastSuccessfulLoginDate)</td>
          <td class="confluenceTd" style="text-align:center;">
                    <ac:macro ac:name="status">
                    <ac:parameter ac:name="colour">Red</ac:parameter>
                   <ac:parameter ac:name="title">Nein</ac:parameter>
                   <ac:macro ac:name="status">
                   <ac:parameter ac:name="colour">Green</ac:parameter>
                   <ac:parameter ac:name="title">Ja</ac:parameter>
                  #set($totalactiveusers = $totalactiveusers + 1)

                #set($t3= $content.currentDate.time -  $loginManager.getLoginInfo($user).lastSuccessfulLoginDate.time)
           <td class="confluenceTd" style="text-align:center;">
           #if($t3 < 7) 
                 <ac:macro ac:name="status">
                 <ac:parameter ac:name="colour">Green</ac:parameter>
                 <ac:parameter ac:name="title">$t3</ac:parameter>
           #elseif($t3 < 14) 
                 <ac:macro ac:name="status">
                 <ac:parameter ac:name="colour">Yellow</ac:parameter>
                 <ac:parameter ac:name="title">$t3</ac:parameter>
           #elseif($t3 < 9999) 
                 <ac:macro ac:name="status">
                 <ac:parameter ac:name="colour">Red</ac:parameter>
                 <ac:parameter ac:name="title">$t3</ac:parameter>
                 <ac:macro ac:name="status">
                 <ac:parameter ac:name="colour">Magenta</ac:parameter>
                 <ac:parameter ac:name="title">$t3</ac:parameter>


You can give the group-name as parameter or you use confluence-users to show all users. Hope this helps.


what if one wants to know the user creation date. I know these:


But, is there a place where I can see the full list of parameters?

Thanks, Bruce. This macro made my day. :)

Many thanks, Bruce. The macro is great, it helps us to get information from different angles.

You can get them from the databse with this query:

select cu.user_name, cua.attribute_value from cwd_user_attribute cua left join cwd_user cu on where attribute_name='lastAuthenticated';

The time is in unix format. Yoy may want to write a script to change that to a more human readable format.

This appears to only work for users in Confluence's local user directory, but not any users who authenticate through an external LDAP server (delegated LDAP auth).

Does Confluence no longer save the last login time for these users? (It used to work in 3.4.x -- the login date was stored in the OS_PROPERTYENTRY table under entity key "")

The following works for me on Confluence 5.5 using Postgres. They perhaps changed the structure of the database. There are other examples in the Confluence docs:

SELECT cwd_user.user_name, to_timestamp(CAST(cwd_user_attribute.attribute_value as bigint)/1000)
FROM cwd_user, cwd_user_attribute
WHERE cwd_user_attribute.user_id =
AND cwd_user_attribute.attribute_name = 'lastAuthenticated'
ORDER BY to_timestamp;

This keys in on active users, you can take that AND clause out if you want to include inactive users. We use a mix of LDAP and a few local users and everyone seems to be in there.

I run a free SQL embedding plugin (check the store for Pocket Queries) and throw this list into a velocity template that was mostly stolen from Bruce. If you have a lot of users the SQL query runs faster than the full macro.

For good measure, this is a query for Jira 6.2.2 with a Postgres backend:

SELECT cwd_user.user_name, to_timestamp(CAST(cwd_user_attributes.attribute_value as bigint)/1000)
FROM cwd_user, cwd_user_attributes
WHERE cwd_user_attributes.user_id =
AND cwd_user_attributes.attribute_name = 'lastAuthenticated'
AND = '1'
ORDER BY to_timestamp;

It's weird, the macro is using $crowdUser.createdDate, but doesn't contain the createdDate method. Anyone know where is that createdDate method from? I am trying to find the API equivalent. Thanks.

I know this is an old thread, but I'm pretty sure someone will find it handy to have a SQL that works with recursive (LDAP) groups. It requires a database with Common Table Expressions, e.g. MS SQLServer

-- CTE (Common Table Expression)
WITH recursive_groups ( group_id, name, directory_id)
	-- Anchor, i.e. the login groups
	SELECT, group_name, directory_id
		cwd_group g
		JOIN cwd_directory d ON (g.directory_id =
	WHERE = 'T' -- only enabled directories
		AND g.group_name in ('confluence-users-ldap','confluence-administrators','confluence-administrators-system') -- put your login groups here
	-- Recursive sub groups
	SELECT, g.group_name, g.directory_id
		cwd_membership m
		JOIN recursive_groups to_the_root ON (to_the_root.group_id = m.parent_id)
		JOIN cwd_group g ON (m.child_group_id =
		JOIN cwd_directory d ON (g.directory_id =
	WHERE = 'T' -- only enabled directories
	distinct AS [UserId], u.lower_user_name AS [User], u.display_name AS FullName, l.SUCCESSDATE AS [LastLogin], du.directory_name AS DirectoryName
	recursive_groups g
	JOIN cwd_membership m ON (m.parent_id = g.group_id)
	JOIN cwd_user u ON ( = m.child_user_id)
	JOIN cwd_directory du ON (u.directory_id =
	LEFT JOIN user_mapping map ON (map.username = u.user_name)
	LEFT JOIN logininfo l ON (l.USERNAME = map.user_key)
WHERE = 'T' -- only enabled users

You might be interested in this improvement request on Atlassian's Confluence project:

You can both watch and vote on the issue as important to you as well as review the SQL statement provided in the comments as a temporary work-around to your need.

Using Bruce's work, I have updated the version that I use and put it on GitHub:

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

279 views 2 10
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you