I am looking to setup an automated process to disable users who have not signed in for X days for Confluence similar to this JIRA script:
https://www.adaptavist.com/doco/display/SFJ/Automatically+deactivate+inactive+JIRA+users
I seem have a functioning script, however it does not provide any output like the JIRA version does. Has anyone successfully got an output that can be used for audit? It will only show "null" after it finishes running.
Right now I would have to view the log while running via the scriptrunner console.
As of now I am running 6.13.x Confluence Server.
Thanks in advance.
import com.atlassian.confluence.security.PermissionManager
import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.UserManager
import groovy.time.TimeCategory
import org.apache.log4j.Level
import org.apache.log4j.Logger
def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
def userManager = ComponentLocator.getComponent(UserManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)
def loginManager = ComponentLocator.getComponent(LoginManager)
def permissionManager = ComponentLocator.getComponent(PermissionManager)
def threeMonthsBack
use(TimeCategory) {
threeMonthsBack = 3.months.ago
}
def users = userManager.users
def page = users.currentPage
while (true) {
page.each { user ->
myLog.debug(user)
if (userAccessor.isDeactivated(user)) {
return
}
def userLoginInfo = loginManager.getLoginInfo(user)
def lastSuccessfulLoginDate = userLoginInfo?.lastSuccessfulLoginDate
def toDeactivate = ! lastSuccessfulLoginDate || lastSuccessfulLoginDate < threeMonthsBack
if (toDeactivate) {
log.warn "Found user: ${user.name} with last login date ${lastSuccessfulLoginDate}, will deactivate"
if (!permissionManager.isSystemAdministrator(user)) {
log.info "Deactivating user.."
userAccessor.deactivateUser(user)
}
}
}
if (users.onLastPage()) {
return
}
else {
users.nextPage()
}
}