View | Details | Raw Unified | Return to bug 27936
Collapse All | Expand All

(-)umc/app.js (-25 / +1 lines)
 Lines 91-116    Link Here 
91
			umc.tools.status('overview', umc.tools.isTrue(props.overview));
91
			umc.tools.status('overview', umc.tools.isTrue(props.overview));
92
		}
92
		}
93
93
94
		if (props.username && props.password && dojo.isString(props.username) && dojo.isString(props.password)) {
94
		umc.dialog.login().then(dojo.hitch(this, 'onLogin'));
95
			// username and password are given, try to login directly
96
			umc.dialog.login().then(dojo.hitch(this, 'onLogin'));
97
			return;
98
		}
99
100
		// check whether we still have a possibly valid cookie
101
		var sessionCookie = dojo.cookie('UMCSessionId');
102
		var usernameCookie = dojo.cookie('UMCUsername');
103
		if (undefined !== sessionCookie && usernameCookie !== undefined
104
			&& (!umc.tools.status('username') || umc.tools.status('username') == usernameCookie)) {
105
			// the following conditions need to be given for an automatic login
106
			// * session and username need to be set via cookie
107
			// * if a username is given via the query string, it needs to match the
108
			//   username saved in the cookie
109
			this.onLogin(dojo.cookie('UMCUsername'));
110
		}
111
		else {
112
			umc.dialog.login().then(dojo.hitch(this, 'onLogin'));
113
		}
114
	},
95
	},
115
96
116
	onLogin: function(username) {
97
	onLogin: function(username) {
 Lines 118-128    Link Here 
118
		dojo.cookie('UMCUsername', username, { expires: 100, path: '/' });
99
		dojo.cookie('UMCUsername', username, { expires: 100, path: '/' });
119
		umc.tools.status('username', username);
100
		umc.tools.status('username', username);
120
101
121
		// set the UCR session timeout value
122
		umc.tools.ucr('umc/http/session/timeout').then( function(res) {
123
			umc.tools._sessionTimeout = parseInt( res['umc/http/session/timeout'] , 10 );
124
		} );
125
126
		// start the timer for session checking
102
		// start the timer for session checking
127
		umc.tools.checkSession(true);
103
		umc.tools.checkSession(true);
128
104
(-)umc/widgets/Uploader.js (-2 / +3 lines)
 Lines 175-183    Link Here 
175
							dojo.mixin(params, this.dynamicOptions);
175
							dojo.mixin(params, this.dynamicOptions);
176
						}
176
						}
177
					}
177
					}
178
					// mixin the iframe information
178
					// mixin the iframe information and sessionID
179
					dojo.mixin(params, {
179
					dojo.mixin(params, {
180
						iframe: (this._uploader.uploadType === 'iframe') ? true : false
180
						iframe: (this._uploader.uploadType === 'iframe'),
181
						'X-UMC-Session-Id': umc.tools.getSessionId()
181
					});
182
					});
182
					this._uploader.upload(params);
183
					this._uploader.upload(params);
183
					this.onUploadStarted(data[0]);
184
					this.onUploadStarted(data[0]);
(-)umc/widgets/LoginDialog.js (-1 / +3 lines)
 Lines 232-238    Link Here 
232
		this.standby(true);
232
		this.standby(true);
233
		umc.tools.umcpCommand('auth', {
233
		umc.tools.umcpCommand('auth', {
234
			username: username,
234
			username: username,
235
			password: password
235
			password: password,
236
			// send also the version of the UMC frontend package
237
			version: umc.tools.status('version')
236
		}).then(dojo.hitch(this, function(data) {
238
		}).then(dojo.hitch(this, function(data) {
237
			// disable standby in any case
239
			// disable standby in any case
238
			this.standby(false);
240
			this.standby(false);
(-)umc/dialog.js (-1 / +2 lines)
 Lines 68-74    Link Here 
68
			// try to authenticate via long polling... i.e., in case of an error try again until it works
68
			// try to authenticate via long polling... i.e., in case of an error try again until it works
69
			this._loginDeferred = umc.tools.umcpCommand('auth', {
69
			this._loginDeferred = umc.tools.umcpCommand('auth', {
70
				username: username,
70
				username: username,
71
				password: password
71
				password: password,
72
				version: umc.tools.status('version')
72
			}, false, undefined, {
73
			}, false, undefined, {
73
				message: this._('So far the authentification failed. Continuing nevertheless.'),
74
				message: this._('So far the authentification failed. Continuing nevertheless.'),
74
				noLogin: true
75
				noLogin: true
(-)umc/tools.js (-43 / +54 lines)
 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

Return to bug 27936