如果我有多台CF8服务器,用户是否可以在一台服务器上登录,但在所有服务器之间共享登录凭证(不需要重新登录)?
答案 0 :(得分:7)
也许问题是关于分享会话?这可以使用序列化J2EE sessions或使用共享client variables来完成。
例如,这可以通过以下方式完成。
在其中一台服务器上创建空数据库(我创建了一个MySQL)。在所有CF服务器上创建指向此DB的数据源。将此数据源用作服务器设置>客户变量>名为 SharedSessions 的客户端会话存储(稍后我们将使用它)。
如果我们在所有服务器上的Application.cfm中使用cflogin,它的代码可以看起来像这样(简化):
<cfapplication
name="shared_session_test"
sessionManagement="true"
clientmanagement="true"
clientstorage="SharedSessions" />
<cflogin>
<cfif IsDefined( "cflogin" ) and cflogin.name eq "admin" and cflogin.password eq "admin">
<cfset user_roles = "administrators" />
<cfset user_name = cflogin.name />
<cfset user_password = cflogin.password />
</cfif>
<cfif IsDefined( "user_roles" )>
<!--- push login params into shared client scope --->
<cfset CLIENT.user_roles = user_roles />
<cfset CLIENT.user_name = user_name />
<cfset CLIENT.user_password = user_password />
<cfelseif IsDefined( "CLIENT.user_roles" )>
<!--- restore login params from shared client scope --->
<cfset user_roles = CLIENT.user_roles />
<cfset user_name = CLIENT.user_name />
<cfset user_password = CLIENT.user_password />
</cfif>
<cfif IsDefined( "user_roles" )>
<cfloginuser name="#user_name#" password="#user_password#" roles="#user_roles#">
<cfelse>
<!--- authentication failed - send back 401 --->
<cfsetting enablecfoutputonly="yes" showdebugoutput="no">
<cfheader statuscode="401">
<cfheader name="WWW-Authenticate" value="Basic realm=""MySecurity""">
<cfoutput>Not authorized</cfoutput>
<cfabort />
</cfif>
</cflogin>
<cfoutput><p><a href="http://other.server.com/index.cfm?#CLIENT.urltoken#">other.server.com</a></p></cfoutput>
现在这两个服务器上的显示相同:
<cfdump var="#getAuthUser()#">
<cfdump var="#CLIENT#">
当然,这里有许多工作要做,以使流程更好,更安全,只是描述了一般的想法。
希望这有帮助。