|
Lines 42-50
Link Here
|
| 42 |
})); |
42 |
})); |
| 43 |
dojo.mixin(umc.tools, { |
43 |
dojo.mixin(umc.tools, { |
| 44 |
|
44 |
|
| 45 |
// default value for the session timeout |
45 |
_sessionID: '', |
| 46 |
// it will be replaced by the ucr variable 'umc/http/session/timeout' onLogin |
46 |
_sessionDuration: 0, |
| 47 |
_sessionTimeout: 300, |
|
|
| 48 |
|
47 |
|
| 49 |
_status: { |
48 |
_status: { |
| 50 |
username: null, |
49 |
username: null, |
|
Lines 54-60
Link Here
|
| 54 |
displayUsername: true, |
53 |
displayUsername: true, |
| 55 |
width: null, |
54 |
width: null, |
| 56 |
setupGui: false, |
55 |
setupGui: false, |
| 57 |
loggingIn: false |
56 |
loggingIn: false, |
|
|
57 |
version: '' |
| 58 |
}, |
58 |
}, |
| 59 |
|
59 |
|
| 60 |
status: function(/*String?*/ key, /*Mixed?*/ value) { |
60 |
status: function(/*String?*/ key, /*Mixed?*/ value) { |
|
Lines 66-71
Link Here
|
| 66 |
// With two parameters, sets the value of the specified key. |
66 |
// With two parameters, sets the value of the specified key. |
| 67 |
// Also contains the properties given |
67 |
// Also contains the properties given |
| 68 |
// to `umc.app.start()`. The following properties exist: |
68 |
// to `umc.app.start()`. The following properties exist: |
|
|
69 |
// * version (String): The version of the UMC frontend package. |
| 69 |
// * username (String): The username of the authenticated user. |
70 |
// * username (String): The username of the authenticated user. |
| 70 |
// * hostname (String): The hostname on which the UMC is running. |
71 |
// * hostname (String): The hostname on which the UMC is running. |
| 71 |
// * domainname (String): The domainname on which the UMC is running. |
72 |
// * domainname (String): The domainname on which the UMC is running. |
|
Lines 90-130
Link Here
|
| 90 |
return undefined; |
91 |
return undefined; |
| 91 |
}, |
92 |
}, |
| 92 |
|
93 |
|
|
|
94 |
getSessionId: function() { |
| 95 |
return this._sessionID; |
| 96 |
}, |
| 97 |
|
| 98 |
setSession: function(/*String*/ sessionID, /*Integer*/ duration) { |
| 99 |
// summary: |
| 100 |
// sets the sessionid and sessiontimeout |
| 101 |
// sessionID: String |
| 102 |
// the session id |
| 103 |
// duration: Integer |
| 104 |
// the session timeout in milliseconds |
| 105 |
this._sessionID = sessionID; |
| 106 |
this._sessionDuration = duration; |
| 107 |
}, |
| 108 |
|
| 109 |
checkSessionActive: function() { |
| 110 |
return this._sessionID && this._sessionDuration > 0; |
| 111 |
}, |
| 112 |
|
| 93 |
closeSession: function() { |
113 |
closeSession: function() { |
| 94 |
// summary: |
114 |
// summary: |
| 95 |
// Reset the session cookie in order to close the session from the client side. |
115 |
// Reset the session in order to close the session from the client side. |
| 96 |
dojo.cookie('UMCSessionId', null, { |
116 |
this.setSession('', -1); |
| 97 |
expires: -1, |
|
|
| 98 |
path: '/' |
| 99 |
}); |
| 100 |
}, |
117 |
}, |
| 101 |
|
118 |
|
| 102 |
holdSession: function(/*String?*/ id) { |
119 |
holdSession: function(/*String*/ id) { |
| 103 |
// summary: |
120 |
// summary: |
| 104 |
// Set the expiration time of the current session cookie in to 24 hours. |
121 |
// Set the expiration time of the current session in to 24 hours. |
| 105 |
// id: String |
122 |
// id: String |
| 106 |
// If specified, the session ID will be set to this value, otherwise the |
123 |
// If specified, the session ID will be set to this value, otherwise the |
| 107 |
// ID will be read from the cookie automatically. |
124 |
// ID will not change. |
| 108 |
var date = new Date((new Date()).getTime() + 1000 * 60 * 60 * 24); |
125 |
this.setSession(id || this._sessionID, 1000 * 60 * 60 * 24); |
| 109 |
dojo.cookie('UMCSessionId', id || dojo.cookie('UMCSessionId'), { |
|
|
| 110 |
expires: date.toUTCString(), |
| 111 |
path: '/' |
| 112 |
}); |
| 113 |
}, |
126 |
}, |
| 114 |
|
127 |
|
| 115 |
_renewIESession : function() { |
|
|
| 116 |
// summary: |
| 117 |
// Reset the Internet Explorer Session. Internet Explorer can not handle max-age cookies. |
| 118 |
// This is required for automatically show the login dialogue when the session is expired. |
| 119 |
if(dojo.isIE !== undefined) { |
| 120 |
var date = new Date((new Date()).getTime() + 1000 * this._sessionTimeout); |
| 121 |
dojo.cookie('UMCSessionId', dojo.cookie('UMCSessionId'), { |
| 122 |
expires: date.toUTCString(), |
| 123 |
path: '/' |
| 124 |
}); |
| 125 |
} |
| 126 |
}, |
| 127 |
|
| 128 |
_checkSessionTimer: null, |
128 |
_checkSessionTimer: null, |
| 129 |
|
129 |
|
| 130 |
checkSession: function(enable) { |
130 |
checkSession: function(enable) { |
|
Lines 143-149
Link Here
|
| 143 |
// create a new timer instance |
143 |
// create a new timer instance |
| 144 |
this._checkSessionTimer = new dojox.timing.Timer(1000); |
144 |
this._checkSessionTimer = new dojox.timing.Timer(1000); |
| 145 |
this._checkSessionTimer.onTick = function() { |
145 |
this._checkSessionTimer.onTick = function() { |
| 146 |
if (!dojo.isString(dojo.cookie('UMCSessionId'))) { |
146 |
if (!umc.tools.checkSessionActive()) { |
| 147 |
umc.tools._checkSessionTimer.stop(); |
147 |
umc.tools._checkSessionTimer.stop(); |
| 148 |
if (umc.tools.status['loggingIn']) { |
148 |
if (umc.tools.status['loggingIn']) { |
| 149 |
// login dialog is already running |
149 |
// login dialog is already running |
|
Lines 156-161
Link Here
|
| 156 |
umc.tools._checkSessionTimer.start(); |
156 |
umc.tools._checkSessionTimer.start(); |
| 157 |
} |
157 |
} |
| 158 |
}); |
158 |
}); |
|
|
159 |
} else { |
| 160 |
umc.tools._sessionDuration -= 1000; |
| 159 |
} |
161 |
} |
| 160 |
}; |
162 |
}; |
| 161 |
} |
163 |
} |
|
Lines 170-176
Link Here
|
| 170 |
_PollingHandler: function(url, content, finishedDeferred, opts) { |
172 |
_PollingHandler: function(url, content, finishedDeferred, opts) { |
| 171 |
// save the current session ID locally, as the cookie might expire when |
173 |
// save the current session ID locally, as the cookie might expire when |
| 172 |
// the time and timezone settings are updated |
174 |
// the time and timezone settings are updated |
| 173 |
var _oldSessionID = dojo.cookie('UMCSessionId'); |
175 |
var _oldSessionID = umc.tools.getSessionId(); |
| 174 |
|
176 |
|
| 175 |
return { |
177 |
return { |
| 176 |
finishedDeferred: finishedDeferred, |
178 |
finishedDeferred: finishedDeferred, |
|
Lines 221-232
Link Here
|
| 221 |
|
223 |
|
| 222 |
sendRequest: function() { |
224 |
sendRequest: function() { |
| 223 |
// switch off the automatic check for session timeout... |
225 |
// switch off the automatic check for session timeout... |
| 224 |
// the proble here is as follows, we do not receive a response, |
226 |
// the problem here is as follows, we do not receive a response, |
| 225 |
// therefore the cookie is not updated (which is checked for the |
227 |
// therefore the cookie is not updated (which is checked for the |
| 226 |
// session timeout), however, the server will renew the session |
228 |
// session timeout), however, the server will renew the session |
| 227 |
// with each valid request that it receives |
229 |
// with each valid request that it receives |
| 228 |
var currentSessionID = dojo.cookie('UMCSessionId'); |
230 |
var currentSessionID = umc.tools.getSessionId(); |
| 229 |
if (!currentSessionID || 'undefined' == currentSessionID) { |
231 |
if (!currentSessionID) { |
| 230 |
// restore last valid session ID |
232 |
// restore last valid session ID |
| 231 |
currentSessionID = _oldSessionID; |
233 |
currentSessionID = _oldSessionID; |
| 232 |
} |
234 |
} |
|
Lines 235-252
Link Here
|
| 235 |
|
237 |
|
| 236 |
// send AJAX command |
238 |
// send AJAX command |
| 237 |
this._lastRequestTime = (new Date()).getTime(); |
239 |
this._lastRequestTime = (new Date()).getTime(); |
| 238 |
dojo.xhrPost({ |
240 |
var xhrRequest = dojo.xhrPost({ |
| 239 |
url: this.url, |
241 |
url: this.url, |
| 240 |
preventCache: true, |
242 |
preventCache: true, |
| 241 |
handleAs: 'json', |
243 |
handleAs: 'json', |
| 242 |
headers: { |
244 |
headers: { |
| 243 |
'Content-Type': 'application/json' |
245 |
'Content-Type': 'application/json', |
|
|
246 |
'X-UMC-Session-Id': umc.tools.getSessionId() |
| 244 |
}, |
247 |
}, |
| 245 |
postData: this.content, |
248 |
postData: this.content, |
| 246 |
timeout: 1000 * this.xhrTimeout |
249 |
timeout: 1000 * this.xhrTimeout |
| 247 |
}).then(dojo.hitch(this, function(data) { |
250 |
}); |
|
|
251 |
xhrRequest.then(dojo.hitch(this, function(data) { |
| 248 |
// request finished |
252 |
// request finished |
| 249 |
umc.tools._renewIESession(); |
253 |
if (xhrRequest.ioArgs.xhr.getResponseHeader('X-UMC-Session-Id')) { |
|
|
254 |
// reset the sessionId and sessionTimeout |
| 255 |
umc.tools.setSession(xhrRequest.ioArgs.xhr.getResponseHeader('X-UMC-Session-Id'), 1000 * parseInt(xhrRequest.ioArgs.xhr.getResponseHeader('X-UMC-Session-Timeout'))); |
| 256 |
} |
| 250 |
this._dialog.hide(); |
257 |
this._dialog.hide(); |
| 251 |
this._dialog.destroyRecursive(); |
258 |
this._dialog.destroyRecursive(); |
| 252 |
this.finishedDeferred.resolve(data); |
259 |
this.finishedDeferred.resolve(data); |
|
Lines 349-366
Link Here
|
| 349 |
} |
356 |
} |
| 350 |
else { |
357 |
else { |
| 351 |
// normal AJAX call |
358 |
// normal AJAX call |
| 352 |
var call = dojo.xhrPost({ |
359 |
var xcall = dojo.xhrPost({ |
| 353 |
url: url, |
360 |
url: url, |
| 354 |
preventCache: true, |
361 |
preventCache: true, |
| 355 |
handleAs: 'json', |
362 |
handleAs: 'json', |
| 356 |
headers: { |
363 |
headers: { |
| 357 |
'Content-Type': 'application/json' |
364 |
'Content-Type': 'application/json', |
|
|
365 |
'X-UMC-Session-Id': umc.tools.getSessionId() |
| 358 |
}, |
366 |
}, |
| 359 |
postData: body |
367 |
postData: body |
| 360 |
}); |
368 |
}); |
| 361 |
|
369 |
|
| 362 |
call = call.then(function(data) { |
370 |
var call = xcall.then(function(data) { |
| 363 |
umc.tools._renewIESession(); |
371 |
if (xcall.ioArgs.xhr.getResponseHeader('X-UMC-Session-Id')) { |
|
|
372 |
// reset the sessionId and sessionTimeout |
| 373 |
umc.tools.setSession(xcall.ioArgs.xhr.getResponseHeader('X-UMC-Session-Id'), 1000 * parseInt(xcall.ioArgs.xhr.getResponseHeader('X-UMC-Session-Timeout'))); |
| 374 |
} |
| 364 |
return data; |
375 |
return data; |
| 365 |
}); |
376 |
}); |
| 366 |
|
377 |
|