All users not login in within last 6 month should marked as inactive.

I have logged into JIRA with admin rights. I have written a code to deactivate the users who are not logged in from last 6 months. But i see that users who are part of Internal Directory are marked as in active but users from Active directory are not. So how can i make my code works for both the directory users.

Below is my code.

import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.user.util.UserUtil

int numOfDays = 8
Date dateLimit = (new Date())- numOfDays

StringBuffer st = new StringBuffer();
UserUtil userUtil = ComponentAccessor.userUtil
CrowdService crowdService = ComponentAccessor.crowdService
UserService userService = ComponentAccessor.getComponent(UserService)
ApplicationUser updateUser
UserService.UpdateUserValidationResult updateUserValidationResult

long count = 0
userUtil.getUsers().findAll{it.isActive()}.each {
UserWithAttributes user = crowdService.getUserWithAttributes(it.getName())
String lastLoginMillis = user.getValue('login.lastLoginMillis')

if (lastLoginMillis?.isNumber()) {
Date d = new Date(Long.parseLong(lastLoginMillis))
st.append("date is " +d);
if (d.before(dateLimit)) {

updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser())
updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
st.append("Final result of Updated Users are::: " "Deactivated ${}"
} else {
log.error "Update of ${} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}"

"${count} users deactivated.\n"


1 answer

1 accepted

0 votes
Accepted answer

Hi Prasanna,

In most setups, Active Directory users cannot be modified in JIRA. If you're using the Microsoft Active Directory user directory type, all users meeting a specific criteria in AD (usually filtered by OU or specific group membership) are synced into JIRA.

From the User Directories page, check and see what setup you have. If it's "Microsoft Active Directory (Read Only, with Local Groups)" for your AD, you can't modify the users in JIRA.

What you want to do requires you to be using the "Internal with LDAP Authentication" directory type. This directory can be more of a pain to manage than the standard AD directory type, but allows you to manage user properties (like active/inactive) within JIRA.

If you're unable to look into changing directory types to meet your requirements (it can be a big job to move them), I might suggest using an AD group as your filter criteria in your Microsoft Active Directory user directory type. When you remove users from what it's looking for to sync, they will become inactive in JIRA. You can use the script you've got going or some SQL to generate the inactive users list, then use a PowerShell script to remove them from whatever AD group you have / can set up to control JIRA access.


P.S. If you feel like this answer helped, please hit the checkmark to the left to mark it as answered. This helps us focus our efforts on unsolved questions. Thanks!

Hi Daniel Thank for the reply. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,782 views 18 21
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