Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/webapp/assets/js/model/server-extended-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ define(["backbone", "brooklyn", "view/viewutils"], function (Backbone, Brooklyn,
callbacks: [],
loaded: false,
url: "/v1/server/up/extended",
sync: function(method, collection, options){
options = options || {};
options.beforeSend = function (xhr) {
xhr.setRequestHeader('X-Csrf-Token-Required-For-Requests', 'write');
};
return Backbone.Model.prototype.sync.apply(this, arguments);
},
onError: function(thiz,xhr,modelish) {
log("ServerExtendedStatus: error contacting Brooklyn server");
log(xhr);
Expand Down
13 changes: 12 additions & 1 deletion src/main/webapp/assets/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ define([
});

/*
* Prepend a base URL to REST API calls
* Prepend a base URL to REST API calls, and add the CSRF token if present.
*/
$.ajaxSetup({
beforeSend: function(jqXHR, settings) {
Expand All @@ -264,6 +264,17 @@ define([
if (baseURL && settings.url.startsWith("/v1")) {
settings.url = (baseURL + settings.url).replace("//", "/");
}

// add CSRF token as header
var ca = document.cookie.split(';');
for (var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.toLowerCase().indexOf('csrf-token') != -1) {
var parts = c.split('=');
jqXHR.setRequestHeader('X-'+parts[0], parts[1]);
}
}
}
});

Expand Down