简体   繁体   English

单点登录,有2个子域,一个Java,一个.NET

[英]Single Sign on with 2 subdomains, one Java, one .NET

I'm currently looking for a nice solution for the problem above. 我目前正在为上述问题寻找一个很好的解决方案。 We'll probably run form authentication on the .NET one. 我们可能会在.NET上运行表单身份验证。

I have an ASP.NET MVC app running on a.mydomain.com and a Java based app running on b.mydomain.com . 我有一个在a.mydomain.com运行的ASP.NET MVC应用程序和一个在b.mydomain.com运行的基于Java的应用程序。

What is the best approach so that I don't have to log in to each app. 什么是最好的方法,这样我就不必登录每个应用程序。 Say, when I log into the a.mydomain.com and then open the Java b.mydomain.com , and it will check and see that I'm already logged in? 比如说,当我登录a.mydomain.com然后打开Java b.mydomain.com ,它会检查并看到我已经登录了?

Would the WCF AuthenticationService class work for this? WCF AuthenticationService类是否适用于此? Could I do an AJAX request from the JavaScript of b.mydomain.com to check if I'm logged in already in the .NET app? 我可以从b.mydomain.com的JavaScript做一个AJAX请求来检查我是否已经在.NET应用程序中登录了吗?

As long as mydomain.com is not in the public suffix list ( http://publicsuffix.org/list/ ), a.mydomain.com can put a domain cookie for .mydomain.com 只要mydomain.com是不是在公共后缀列表( http://publicsuffix.org/list/ ), a.mydomain.com可以把一个域cookie为.mydomain.com

( note that you can only go down one level in putting cookie : abmydomain.com can not put a .mydomain.com cookie ) (请注意,在放置cookie时只能降低一级: abmydomain.com不能放置.mydomain.com cookie)

The cookie will be sent to b.mydomain.com (as well as *.mydomain.com and mydomain.com ) and can be used as a token to open a session. 该cookie将被发送到b.mydomain.com (以及*.mydomain.commydomain.com ),并可用作令牌来打开会话。 So be sure to control the whole *.myDomain.com subdomain and make it httpOnly and secured (https) 因此,请务必控制整个* .myDomain.com子域并使其成为httpOnly和安全(https)

Response.SetCookie(new HttpCookie("myCookieName", "myCookieValue") { HttpOnly = true, Domain = ".myDomain.com", Secure=true });

Some parts of the Atlassian Crowd solution http://www.atlassian.com/software/crowd/overview are based on this cookie mechanism Atlassian Crowd解决方案http://www.atlassian.com/software/crowd/overview的某些部分基于此cookie机制

So you might : 所以你可能会:

  1. Enable forms authentication on a.domain.com 在a.domain.com上启用表单身份验证
  2. upon successfull login build a myToken cookie which value contains userId and hashed userId with hashing key known by a.myDomain.com and b.myDomain.com 成功登录后,构建一个myToken cookie,其值包含userId,并使用has.keyDomain.com和b.myDomain.com已知的散列密钥散列userId
  3. set the cookie with domain .myDomain.com 使用域.myDomain.com设置cookie
  4. when user enters b.myDomain.com, check the cookie server side (in java) for matching between userId and hashed value 当用户进入b.myDomain.com时,检查cookie服务器端(在java中)是否匹配userId和散列值
  5. if the cookie is correct, open session for user userId 如果cookie正确,则打开用户userId的会话

Note that you won't be able to access the cookie client side (so no js cookie handling, except if it is server side js, for example nodejs) 请注意,您将无法访问cookie客户端(因此没有js cookie处理,除非它是服务器端js,例如nodejs)

Using a Java or .NET existing solution is not likely to function on the other platform. 使用Java或.NET现有解决方案不太可能在其他平台上运行。 You need several capabilities: 您需要几种功能:

  1. Tracking the client with an identifier for recognition (session, cookie). 使用识别标识符(会话,cookie)跟踪客户端。
  2. Have both the Java and .NET application be able to get the related information. 让Java和.NET应用程序都能够获取相关信息。

How can you do these? 你怎么能这样做?

  1. This is actually quite easy. 这其实很容易。 You're using the same domain so you can place a cookie on the browser for all domains, meaning that requests to a* and b* will both have the cookie sent to the server. 您正在使用相同的域,因此您可以在浏览器上为所有域放置cookie,这意味着对*和b *的请求都会将cookie发送到服务器。 Both Java and .NET have excellent facilities for cookie placement. Java和.NET都具有出色的cookie放置功能。
  2. This is dependent on your back-end. 这取决于您的后端。 What are the systems using for persistent storage? 用于持久存储的系统有哪些? If you have something like a MySQL database which both systems are connected to, you can make a table with login information for each stored identifier for authentication. 如果你有两个系统连接的MySQL数据库,你可以为每个存储的标识符创建一个包含登录信息的表进行身份验证。 If you take this route, have some sort of time-out as well to invalidate old authentications. 如果您采用这种方式,也会有一些超时以使旧的身份验证无效。

If you have both those pieces of information, you can do the authentication on each system. 如果您同时拥有这两条信息,则可以在每个系统上进行身份验证。

I recommend using one of enterprise sso protocols, Oauth2 or ws-federation. 我建议使用企业sso协议之一,Oauth2或ws-federation。 This gives you maximum flexibility in composing your services, you can not only federate these two but then, later, easily expand your application environment. 这为您提供了组合服务的最大灵活性,您不仅可以联合这两种服务,还可以在以后轻松扩展您的应用程序环境。 Both protocols do not need apps to be on the same domain. 两种协议都不需要应用程序位于同一个域中。

Although this could sound overcomplicated for your simple needs, you do it once and have the sso problem solved forever, no matter what happens in future to your applications. 虽然这对于您的简单需求来说听起来过于复杂,但是无论将来您的应用程序发生了什么,您都可以执行一次并彻底解决sso问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM