Seeing Double, Detecting Duplicate Logins with Flex and ColdFusion...

I'm working with Kevin Kazmierczak on a Flex and ColdFusion project with Universal Mind and the need arose for us to be able to detect duplicate logins. Specifically, if a user logs in a second time without logging out of their initial session, we need to know. If the user does login twice, their ColdFusion session needs to be killed and they need to be logged out of the Flex application.

I'm going to detail the ColdFusion/Flex Data Services side of things and Kevin has written about the Flex portion on his blog.

The ColdFusion portion ended up being very simple, yet, very effective. We created an application variable called usersLoggedIn and made it a structure. This is done in the onApplicationStart method of Application.cfc.

<cfset application.usersLoggedIn = StructNew() />

Every time a user logs in, we store the user value object in the usersLoggedIn structure with their username as the structure key. We also added a unique session id to the user value object. We are using a UUID for this unique id.

<cflock scope="application" timeout="5" type="exclusive">
<cfset application.usersLoggedIn[ arguments.userName ] = userVO />
</cflock>

Now, we need to be able to tell the Flex application when we detect a duplicate login. This is where we leveraged Flex Data Services. We're using the Flex Message Gateway (NOTE: ColdFusion Enterprise is required to leverage the Flex Message Gateway) to send a message to Flex clients when we detect a duplicate login.

<cfif StructKeyExists(application.usersLoggedIn, arguments.userName)>
<cfset msg = StructNew() />
<cfset msg.body = "Double Login Detected" />
<cfset msg.headers = StructNew() />
<cfset msg.headers.SESSIONID = application.usersLoggedIn[ arguments.userName ].sessionId />
                     
<cfset msg.headers.COMMAND = "logout" />
<cfset msg.destination = "ColdFusionGateway" />
<cfset SendGatewayMessage("Flex2CF",msg)/>
</cfif>

When a user logs in, we are checking to see if they are already in the usersLoggedIn structure. If they are, we construct a message to send to the Flex clients with the users unique session id.

If you need help setting up the Flex Message Gateway, check out the Adobe docs. No need for me to reinvent the wheel.

That's all from the ColdFusion side of things, if you want to see what happens in the Flex application, head on over to Kevin's blog.

Comments
Russ's Gravatar Well I tried to read this post, since it is an issue I am dealing with, but I could get past the first line. For some reason I couldn't concentrate on the text.....
# Posted By Russ | 4/10/07 8:48 AM
Andychou's Gravatar Need 10 Adobe Flex engineers
# Posted By Andychou | 4/20/08 8:42 PM
Andychou's Gravatar Need 10 Adobe Flex engineers:
1. You should have this skill set: "Adobe Flex + C#/Java + SQL Database".
2. You have to be living in United States, United Kingdom, Australia or Canada.
3. Work part time (through the Internet) OR full time with us (on site at our client's office).
4. Please send us your resume, expected salary, full time or part time, etc.

Busycode Inc. is a top Adobe Flex outsourcing service provider who develops Flex/AIR applications for clients.
Visit http://www.busycode.com , you will see we are all about Flex engineer, Flex programmer, Flex coder, Flex speciallist and Flex expert. If you are Mr. Flex or Miss Flex, join us now!
# Posted By Andychou | 4/20/08 8:43 PM
flex developers's Gravatar hey

Really nice tips!

will try to keep it in my mind

thanks!
# Posted By flex developers | 10/15/08 5:11 AM
Questions or comments? Feel free to email me at kevin.schmidt[at]flexinabox.com