Terminating user session through code once the allocated time expires.

Musab Rasheed
Kilo Patron

Hi,

I have a service catalog user which a user who doesn't have admin role can raise a request and once request is raised user will be provided with admin role automatically for certain duration. moreover once the duration expires then admin role will be automatically revoked but i want to end the session for the logged in user once the duration expires. can anyone provide me the sample code so that i can it in my workflow which will help me to revoke admin access as well to end user session.?

Thanks

1 ACCEPTED SOLUTION

Here is working code.



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


var it = sessions.iterator();  


while(it.hasNext()) {  


        var session = it.next();


  gs.log('musab1');


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


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


  gs.log('musab2');


                  var httpSession = session.getHS();  


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


        }  


}


View solution in original post

7 REPLIES 7

Here is working code.



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


var it = sessions.iterator();  


while(it.hasNext()) {  


        var session = it.next();


  gs.log('musab1');


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


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


  gs.log('musab2');


                  var httpSession = session.getHS();  


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


        }  


}


Thanks. That got me thinking in the right direction for a local logout page that didn't use logout.do.



<g:evaluate var="jvar_status">


                              var id = gs.getSessionID();


                              var gr = new GlideRecord('v_user_session');


                              if (gr.get('session_id',id)) {


                                                              gr.locked = true;


                                                              gr.update();


                              }


</g:evaluate>    


This doesn't work across nodes.