If user logoff or their session times out how to end coldfusion session?
I have system that I built and for this project I used Ajax with JQuery. On back end I use ColdFusion and session management to handle users session variables. There is two situations (actually three if we consider closing the browser) where users session will end. One situation is if they click Logoutthen I have function that will clear SESSION scope with all information in it but session is not ended. Also CFID and CFTOKEN are still the same. Here is example of Logout function:
<cffunction name="LogOut" access="remote" output="yes" returnformat="JSON" hint="Used in session timeout handling"> <cfset fnResults = structNew()> <cfset dt = createODBCDateTime(now())> <cfif structKeyExists(SESSION,"LoggedIn")> <cfset temp = structClear(SESSION)> <cfset fnResults.status = "200"> <cfelse> <cfset fnResults.status = "400"> <cfset fnResults.message = "Error!"> </cfif> <cfreturn fnResults> </cffunction>Second scenario is once user session timeout. Here is example of that fucntion:
<cffunction name="timeoutSession" access="remote" output="yes" verifyclient="no" securejson="false"> <cfset temp = structClear(SESSION)> </cffunction> Both of these functions will clear the session scope but not end the user session. I have used cfdump to check session scope once user logs out and CFID/CFTOKEN remains the same. I'm wondering how session cna be ended once they hit LogOut or timeoutSession function? Also should I rewrite the CFID and CFTOKEN every time user logs in the system? Here is example of my Application.cfc:
<cfcomponent output="false"> <cfset THIS.name = "MyApplication"> <cfset THIS.sessionManagement = true> <cfset THIS.applicationTimeout = CreateTimeSpan(0, 8, 0, 0)> <cfset THIS.sessionTimeout = CreateTimeSpan(0, 2, 0, 0)> <cfset THIS.requestTimeOut = "60"> <cffunction name="onApplicationStart" access="public" returntype="boolean" output="false"> <cfset APPLICATION.appStarted = now()> <cfset APPLICATION.title = "My Application"> <cfset APPLICATION.functions = CreateObject("component","udfs").init()> <cfset APPLICATION.sessionMinutes = 30> <cfreturn true> </cffunction> <!--- Runs when your session starts ---> <cffunction name="OnSessionStart" access="public" returntype="void" output="false"> <!--- Clear the session. ---> <cfset StructClear( SESSION ) /> <!--- Set loggedin flag to false. ---> <cfset SESSION.loggedin = false> <cfreturn /> </cffunction> <!--- Run before the request is processed. ---> <cffunction name="onRequestStart" returnType="boolean" output="false"> <cfargument name="thePage" type="string" required="true"> <cfset REQUEST.appCode = 'SPA'> <cfset REQUEST.appName = 'Single Page Application'> <cfset var page = listLast(arguments.thePage,"/")> <!---<cfset onApplicationStart()>---> <cfif !listFindNoCase("Login.cfm,Authentication.cfc",page)> <cfif !structKeyExists(SESSION, "loggedin") OR SESSION.loggedin EQ false> <cflocation url="Login.cfm" addToken="false"> </cfif> </cfif> <cfreturn true> </cffunction> </cfcomponent>I'm not sure if session can be ended in Application.cfc or I have to do that in my cffunctions. Same for CFID and CFTOKEN what is the best place to set new values if user logs in again? If aynone have experience with this please let me know. I'm trying to prevent user to use the same session and raise level of security in my SPA. There is one more thing that I found sessionInvalidate() method but they have mentioned that will not invalidate the underlying J2EE session. If I use this method in my LogOut and timeoutSession I can see cfid and cftoken are reset each time. I'm only worried if not ending J2EE session can cause some problems in my app. If anyone can help or provide some feed back on this topic please let me know.
