在ColdFusion服务器之间共享登录凭证? [英] Sharing login credentials between ColdFusion severs?

查看:136
本文介绍了在ColdFusion服务器之间共享登录凭证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有多个CF8服务器,用户可以在一个服务器上登录,但是在所有服务器之间共享登录凭据(不需要重新登录)?

解决方案

也许问题是关于共享会话?您可以使用序列化的 J2EE会话或使用共享的客户端变量。 p>

例如,这可以通过以下方式完成。



在其中一个服务器上创建空数据库创建MySQL一)。在所有CF服务器上创建指向此数据库的数据源。使用此数据源作为服务器设置>客户端变量>客户端会话存储名称​​ SharedSessions (我们稍后将使用它)。



所有服务器上的Application.cfm中使用cflogin,它的代码可以看起来像这样(简化):

 < cfapplication 
name =shared_session_test
sessionManagement =true
clientmanagement =true
clientstorage =SharedSessions/&

< cflogin>

< cfif IsDefined(cflogin)和cflogin.name eqadmin和cflogin.password eqadmin>
< 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)>
<!---从共享客户端范围恢复登录参数 - >
< 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>
<!---认证失败 - 发回401 --->
< cfsetting enablecfoutputonly =yesshowdebugoutput =no>
< cfheader statuscode =401>
< cfheader name =WWW-Authenticatevalue =Basic realm =MySecurity>
< cfoutput>未授权< / 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#>

当然,这里有很多工作要做,以使过程更好,更安全,只是描述了一般的想法。



希望这有助。


If I have multiple CF8 servers, can a user login on one server, but share the login credential among all servers (no re-login required)?

解决方案

Maybe question is about sharing session? This can be done using serialized J2EE sessions or using shared client variables.

For example, this can be done in following way.

Create empty database on one of servers (I've created MySQL one). Create datasources pointing to this DB on all CF servers. Use this datasource as Server Settings > Client Variables > client sessions storage with name SharedSessions (we'll use it later).

If we're using cflogin in Application.cfm on all servers, it's code can look this (simplified) way:

<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>

Now these show the same on both servers:

<cfdump var="#getAuthUser()#">
<cfdump var="#CLIENT#">

Sure, there's much to do here to make process better and more secure, just described the general idea.

Hope this helps.

这篇关于在ColdFusion服务器之间共享登录凭证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆