Invalidate/Timeout User Session

bbarnard
Kilo Contributor

I'm looking for a way to invalidate a user session on our ServiceNow instance to force them to relogin without locking their account.

I have not been able to determine a way to do this either in script or via the user or logged in users form.

Does anyone know if this is possible?

1 ACCEPTED SOLUTION

Slava Savitsky
Giga Sage

When you lock out a user, it triggers a business rule called "Lock Out User" that terminates the user's session. You can use the script from that business rule to do the same without locking out the user's account.



// Get all sessions


var sessions = GlideSessions.get().getLoggedInSessionList();


var it = sessions.iterator();


while(it.hasNext()) {


        var session = it.next();


        // If session is current users session, invalidate the session


        if (session.getUser() == current.user_name) {


                  var httpSession = session.getHS();


                  httpSession.setAttribute("locked_out", "true");


        }


}


View solution in original post

5 REPLIES 5

Slava Savitsky
Giga Sage

When you lock out a user, it triggers a business rule called "Lock Out User" that terminates the user's session. You can use the script from that business rule to do the same without locking out the user's account.



// Get all sessions


var sessions = GlideSessions.get().getLoggedInSessionList();


var it = sessions.iterator();


while(it.hasNext()) {


        var session = it.next();


        // If session is current users session, invalidate the session


        if (session.getUser() == current.user_name) {


                  var httpSession = session.getHS();


                  httpSession.setAttribute("locked_out", "true");


        }


}


bbarnard
Kilo Contributor

Thanks Slava,



I'll give that a try.




Bryan


sanjayg
Kilo Contributor

Hey Bryan,



Were you able to achieve this ??



I have a similar requirement and i dont see a possibility of getting all the sessions of all the nodes.



Thanks,


Sanjay


Robert Chrystie
ServiceNow Employee
ServiceNow Employee

I would check out this Wiki page.  



Modifying Session Timeout - ServiceNow Wiki



You didn't state when you wanted to trigger this action, which happens by default after 30 minutes.   If you want to simply adjust the timing of this you can set the system property described in this article, but this is not an on demand solution.



Thanks,


-Robert