-
Notifications
You must be signed in to change notification settings - Fork 411
/
mark-login-users.groovy
34 lines (32 loc) · 1.46 KB
/
mark-login-users.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
@Author kuisathaverat
list and mark all real users: those that have the LastGrantedAuthoritiesProperty because they've logged in at least once.
**/
import org.acegisecurity.*
import jenkins.security.*
import java.util.Date
User.getAll().each{ u ->
def prop = u.getProperty(LastGrantedAuthoritiesProperty)
def realUser = false
def creationDate = null
if (prop) {
realUser=true
creationDate = new Date(prop.timestamp).toString()
}
def lastLogin = new Date()
if(u.getDescription() != null && u.getDescription().startsWith('###') && realUser){
def timestamp = (u.getDescription() =~ /###(.+)###/)[ 0 ][ 1 ]
try{
lastLogin = new Date(java.lang.Long.valueOf(timestamp))
println u.getId() + ":" + u.getDisplayName() + ':' + realUser + ':' + u.getDescription() + ':creationDate=' + creationDate + ":lastLogin=" + lastLogin
} catch( Exception e){
println "ERROR:" + u.getId() + ":" + u.getDisplayName() + ':' + realUser + ':' + u.getDescription() + ':timestamp=' + timestamp + ":lastLogin=" + lastLogin
}
} else if (realUser){
u.setDescription('###' + lastLogin.getTime() + '###' + (u.getDescription() != null ? u.getDescription() : '' ) )
println u.getId() + ':' + u.getDisplayName() + ':' + realUser + ':' + u?.getDescription()
} else if (realUser==false){
u.setDescription('Is not a regular user')
println u.getId() + ':' + u.getDisplayName() + ':' + realUser + ':' + u?.getDescription()
}
}