Skip to content

Commit

Permalink
Updated to support Firefox's Cross-site HTTP requests policy.
Browse files Browse the repository at this point in the history
* Access-Control-Allow-Origin to specific host (wild card does not work with FF)
* Access-Control-Allow-Credentials true
* Set XMLHttpRequest.withCredentials = true
  • Loading branch information
rwinch authored and mraible committed Mar 24, 2011
1 parent 9fd5a62 commit 1975e47
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Expand Up @@ -15,10 +15,11 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;

response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Origin", "http://"+req.getServerName());
response.setHeader("Access-Control-Allow-Methods", "GET,POST");
response.setHeader("Access-Control-Max-Age", "360");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
response.setHeader("Access-Control-Allow-Credentials", "true");

chain.doFilter(req, res);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/index.jsp
Expand Up @@ -92,6 +92,9 @@
$('#status').click(function() {
$.ajax({url: getHost() + '${ctx}/api/login.json',
type: 'GET',
beforeSend: function(xhr){
xhr.withCredentials = true;
},
success: function(data, status) {
$(".status").remove();
$("#status").after("<span class='status'> Logged In: " + data.loggedIn + "</span>");
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/login.jsp
Expand Up @@ -45,6 +45,9 @@
e.preventDefault();
$.ajax({url: getHost() + "${ctx}/api/login.json",
type: "POST",
beforeSend: function(xhr){
xhr.withCredentials = true;
},
data: $("#loginForm").serialize(),
success: function(data, status) {
if (data.loggedIn) {
Expand Down

0 comments on commit 1975e47

Please sign in to comment.