Search code examples
sessioncoldfusioncoldfusion-9

ColdFusion SessionTracker and forcing the session to end


I'm using the ColdFusion 9 coldfusion.runtime.SessionTracker to monitor currently logged in users using the following code.

app = application.getApplicationSettings().name;
sessiontracker = createObject("java","coldfusion.runtime.SessionTracker");
sessionCollection = sessionTracker.getSessionCollection(app);

Which returns a struct of jsessionid's and the session's variables for all the currently active sessions.

Is it possible to force a session to end given I have the jsessionid effectively forcing the user to be logged out?

Thanks,

Richard


Solution

  • So when a user logs in I'm setting a user structure in their session, so to remove their logged in state. Using sessionTracker I can get a specific user's session and just delete the user structure in their current session.

    app = application.getApplicationSettings().name;
    sessiontracker = createObject("java","coldfusion.runtime.SessionTracker");
    sessionCollection = sessionTracker.getSessionCollection(app);
    
    userSession = sessiontracker.getSession(app, sessionID));
    
    structDelete(userSession, "user");
    

    Not sure if this is the best way of doing it but it seems to work for me. Hope it helps people.