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.
I have an ASP.NET MVC app running on a.mydomain.com
and a Java based app running on b.mydomain.com
.
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?
Would the WCF AuthenticationService class work for this? 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?
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
( note that you can only go down one level in putting cookie : abmydomain.com
can not put a .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. So be sure to control the whole *.myDomain.com subdomain and make it httpOnly and secured (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
So you might :
myToken
cookie which value contains userId and hashed userId with hashing key known by a.myDomain.com and b.myDomain.com 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)
Using a Java or .NET existing solution is not likely to function on the other platform. You need several capabilities:
How can you do these?
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. 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.
链接地址: http://www.djcxy.com/p/68906.html上一篇: Java高阶多态函数