Skip to content

Commit f20322c

Browse files
auth for MDX2JSON
1 parent 16ea282 commit f20322c

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

example/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
dataSource: {
9090
MDX2JSONSource: "http://localhost:57772/SAMPLES", // MDX2JSON server address
9191
basicMDX: typeof req === "object" ? req.basicMDX : req
92+
//[ , namespace: "SAMPLES" ] // current namespace : default namespace
93+
//[ , username: "USER" ] // user name : default user
94+
//[ , password: "" ] // user password : default password
9295
}
9396
//, caption: "My table" // if set, table basic caption will be replaced by this text
9497
//, DrillDownExpression: "<spec>" // @deprecated drillDown expression split by "^"

source/js/DataSource.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Data source.
3-
*
3+
*
44
* Must implement methods.
55
*
66
* @param {Object} config
@@ -11,7 +11,9 @@ var DataSource = function (config, globalConfig) {
1111

1212
this.SOURCE_URL = config.MDX2JSONSource ||
1313
location.host + ":" + location.port + "/" + (location.pathname.split("/") || [])[1];
14-
14+
this.NAMESPACE = config["namespace"];
15+
this.USERNAME = config["username"];
16+
this.PASSWORD = config["password"];
1517
this.BASIC_MDX = config.basicMDX;
1618

1719
this.GLOBAL_CONFIG = globalConfig;
@@ -38,7 +40,6 @@ var DataSource = function (config, globalConfig) {
3840
* @private
3941
*/
4042
DataSource.prototype._post = function (url, data, callback) {
41-
4243
var xhr = new XMLHttpRequest();
4344
xhr.open("POST", url);
4445
xhr.onreadystatechange = function () {
@@ -54,12 +55,15 @@ DataSource.prototype._post = function (url, data, callback) {
5455
}
5556
})());
5657
} else if (xhr.readyState === 4 && xhr.status !== 200) {
57-
callback({ error: xhr.responseText
58-
|| "Error while trying to retrieve data from server." });
58+
callback({
59+
error: xhr.responseText || "Error while trying to retrieve data from server."
60+
});
5961
}
6062
};
63+
if (this.USERNAME && this.PASSWORD) {
64+
xhr.setRequestHeader("Authorization", "Basic " + btoa(this.USERNAME + ":" + this.PASSWORD));
65+
}
6166
xhr.send(JSON.stringify(data));
62-
6367
};
6468

6569
/**
@@ -217,7 +221,7 @@ DataSource.prototype.getCurrentData = function (callback) {
217221

218222
console.log("Requesting MDX: " + mdx);
219223

220-
_._post(_.SOURCE_URL + "/" + _.ACTION, {
224+
_._post(_.SOURCE_URL + "/" + _.ACTION + (_.NAMESPACE ? "?Namespace=" + _.NAMESPACE : ""), {
221225
MDX: mdx
222226
}, function (data) {
223227
ready.data = data;
@@ -227,7 +231,8 @@ DataSource.prototype.getCurrentData = function (callback) {
227231
};
228232

229233
if (this.DATA_SOURCE_PIVOT) {
230-
this._post(this.SOURCE_URL + "/DataSource", {
234+
this._post(this.SOURCE_URL + "/DataSource"
235+
+ (_.NAMESPACE ? "?Namespace=" + _.NAMESPACE : ""), {
231236
DataSource: this.DATA_SOURCE_PIVOT
232237
}, function (data) {
233238
ready.pivotData = data;

source/js/LightPivotTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ LightPivotTable.prototype.pushDataSource = function (config) {
8686
var newDataSource;
8787

8888
this.DRILL_LEVEL++;
89-
this._dataSourcesStack.push(newDataSource = new DataSource(config, this.CONFIG));
89+
this._dataSourcesStack.push(newDataSource = new DataSource(config || {}, this.CONFIG));
9090
this.dataSource = newDataSource;
9191

9292
return newDataSource;

0 commit comments

Comments
 (0)