重新使用使用jQuery JSESSIONID对阿贾克斯xmlhtt prequest [英] Re-using jsessionId on ajax xmlhttprequest using jquery

查看:238
本文介绍了重新使用使用jQuery JSESSIONID对阿贾克斯xmlhtt prequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能codeA jQuery的阿贾克斯()调用(如xmlhtt prequest),以preserve会话ID(如已发JSESSIONID的cookie,在浏览器的cookie)

How can I code a jquery ajax() call (e.g. xmlhttprequest) to preserve the session ID (e.g. send the 'jsessionID' cookie already in the browser's cookies)

我们的背景:

  • 在两个基于Java Web应用程序
  • 在SSO机制登录的用户到这两个应用程序(即具有会话101与应用程序A和会话202与应用程序B)
  • 在应用程序A使用JavaScript(jQuery的),以REST调用的应用程序B
  • 在Java的球衣(FWIW)应用程序B实现的REST API
  • 在全部搞定的,老派的形式帖从应用程序A到B连接到同一个会话#202会话B
  • XmlHtt prequests(如jQuery的'阿贾克斯()调用)不重复使用会#202。每个XmlHtt prequest得到一个新的会话

为什么新的会话?

原因:XmlHtt prequest不传递任何cookies来申请B. Servlet容器设置JSESSIONID cookie中。服务器没有得到JSESSIONID

The reason: XmlHttpRequest do not pass any cookies to application B. Servlet container sets jsessionid in the cookie. Server does not get the jsessionid

在此相反,JSONP调用(其中动态生成<脚本SRC =HTTP://server/b/page.x>)的的传递饼干

In contrast, JSONP calls (which dynamically generate <script src="http://server/b/page.x">) do pass the cookies.

的问题

  • 什么是让阿贾克斯xmlhtt prequest最简单的方法调用来传递会话ID(饼干)到目标应用程序?
  • 在阿贾克斯,饼干,xmlhtt prequest,和REST任何有益的参考?
  • 谁能推荐阅读REST API的设计和验证?

Web会话,州和验证

我知道REST应该是无状态的,并重新使用Web会议似乎有些脆弱(即相对于使用OAuth和认证令牌一样,Netflix公司)

I know REST is supposed to be stateless, and re-using web sessions seems somewhat fragile (i.e. as opposed to using OAuth and authentication tokens, as does netflix)

这是第一次迭代,我们已接近把事情启动并运行。这工作正常使用JSONP,但XmlHtt prequest职位失败。

This is the first iteration and we were close to getting things "up and running". This worked fine with JSONP, but XmlHttpRequest posts failed.

在此先感谢

更新:

Update:

一个幼稚的问题确实如此。

A naive question indeed.

事实证明,通过xmlhtt prequest / AJAX的跨站点张贴有固有的安全问题和解决方法。 Firefox的,例如,将无法通过饼干XmlHtt prequest除非添加特殊的头。 Firefox会那么做一个pre-飞行检查(即一个HTTP OPTIONS调用)到服务器,看看这样行吗?。您的服务器需要回答的选项电话,说是的,它是确定之前,Firefox会与cookies邮报执行你。

It turns out that cross-site posting via xmlhttprequest/ajax has inherent security issues and workarounds. Firefox, for example, will not pass cookies with XmlHttpRequest unless you add special headers. Firefox will then do a 'pre-flight check' (i.e. an http OPTIONS call) to the server to see "is this ok?". Your server needs to answer the "OPTIONS" call saying "yes it's ok" before firefox will perform your "post with cookies".

IE和Firefox解决这些问题的不同(即有点像JavaScript大约1998)。我却不知道是什么IE浏览器,但到1998年已经活,我们并不想真正走这条道路,如果在所有可能的。

IE and Firefox solve these problem differently (i.e. a bit like javascript circa 1998). I don't konw what IE does, but having lived through 1998, we don't want to really go down that road if at all possible.

我们codeD一种解决方法。

We coded a workaround.

没有我们的团队知道这一点,当我们开始编码。 (即原型JSONP伟大的工作,一切也应该)

None of our team knew this when we started coding. (i.e. "jsonp worked great in the prototype; everything else should also")

参考: 如何Mozilla的解决了这个问题(HTTP报头和preflight检查) <一href="https://developer.mozilla.org/En/HTTP_access_control">https://developer.mozilla.org/En/HTTP_access_control

References: How Mozilla addresses this problem (http headers and preflight checks) https://developer.mozilla.org/En/HTTP_access_control

跨地资源共享: <一href="http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing">http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing

推荐答案

您也可以通过部署先进FUL代理解决了这个问题。他们会必须在这两个应用程序安装。然后,你会做通代理一个所有基于会话的呼叫和远程会话数据保存到本地代理的会话。

You could also solve this problem by deploying a state-ful proxy. They'd have to be installed on both apps. You'd then make a all your session-based calls thru the proxy and store the remote session data into your local proxy's session.

这篇关于重新使用使用jQuery JSESSIONID对阿贾克斯xmlhtt prequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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