|
107 | 107 | // Use this for checking the session, to bypass login screen |
108 | 108 | bypassLoginCheck: function(args) { //determine to show or bypass login screen |
109 | 109 | if (g_loginResponse == null) { //show login screen |
110 | | - /* |
111 | | - * Since we no longer store sessionKey in cookie, opening the |
112 | | - * 2nd browser window (of the same domain) will show login screen (i.e. user has to |
113 | | - * enter credentials again) and will cause the 1st browser window session timeout. |
114 | | - */ |
115 | 110 | var unBoxCookieValue = function (cookieName) { |
116 | | - var cookieValue = $.cookie(cookieName); |
117 | | - if (cookieValue && cookieValue.length > 2 && cookieValue[0] === '"' && cookieValue[cookieValue.length-1] === '"') { |
118 | | - cookieValue = cookieValue.slice(1, cookieValue.length-1); |
119 | | - $.cookie(cookieName, cookieValue, { expires: 1 }); |
120 | | - } |
121 | | - return decodeURIComponent(cookieValue); |
| 111 | + return decodeURIComponent($.cookie(cookieName)).replace(/"([^"]+(?="))"/g, '$1'); |
122 | 112 | }; |
123 | | - unBoxCookieValue('sessionkey'); |
124 | | - // if sessionkey cookie exists use this to set g_sessionKey |
125 | | - // and destroy sessionkey cookie |
126 | | - if ($.cookie('sessionkey')) { |
127 | | - g_sessionKey = $.cookie('sessionkey'); |
128 | | - $.cookie('sessionkey', null); |
129 | | - } else { |
130 | | - g_sessionKey = unBoxCookieValue('JSESSIONID'); |
131 | | - } |
| 113 | + // sessionkey is a HttpOnly cookie now, no need to pass as API param |
| 114 | + g_sessionKey = null; |
132 | 115 | g_role = unBoxCookieValue('role'); |
133 | 116 | g_userid = unBoxCookieValue('userid'); |
134 | 117 | g_domainid = unBoxCookieValue('domainid'); |
135 | 118 | g_account = unBoxCookieValue('account'); |
136 | 119 | g_username = unBoxCookieValue('username'); |
137 | 120 | g_userfullname = unBoxCookieValue('userfullname'); |
138 | 121 | g_timezone = unBoxCookieValue('timezone'); |
139 | | - } else { //single-sign-on (bypass login screen) |
| 122 | + } else { //single-sign-on (bypass login screen) |
140 | 123 | g_sessionKey = encodeURIComponent(g_loginResponse.sessionkey); |
141 | 124 | g_role = g_loginResponse.type; |
142 | 125 | g_username = g_loginResponse.username; |
143 | 126 | g_userid = g_loginResponse.userid; |
144 | 127 | g_account = g_loginResponse.account; |
145 | 128 | g_domainid = g_loginResponse.domainid; |
146 | 129 | g_userfullname = g_loginResponse.firstname + ' ' + g_loginResponse.lastname; |
147 | | - g_timezone = g_loginResponse.timezone; |
| 130 | + g_timezone = g_loginResponse.timezone; |
148 | 131 | } |
149 | 132 |
|
150 | 133 | var userValid = false; |
|
180 | 163 | return true; |
181 | 164 | } |
182 | 165 | }); |
183 | | - |
| 166 | + |
| 167 | + // Populate IDP list |
| 168 | + $.ajax({ |
| 169 | + type: 'GET', |
| 170 | + url: createURL('listIdps'), |
| 171 | + dataType: 'json', |
| 172 | + async: false, |
| 173 | + success: function(data, textStatus, xhr) { |
| 174 | + if (data && data.listidpsresponse && data.listidpsresponse.idp) { |
| 175 | + var idpList = data.listidpsresponse.idp.sort(function (a, b) { |
| 176 | + return a.orgName.localeCompare(b.orgName); |
| 177 | + }); |
| 178 | + g_idpList = idpList; |
| 179 | + } |
| 180 | + }, |
| 181 | + error: function(xhr) { |
| 182 | + }, |
| 183 | + }); |
| 184 | + |
184 | 185 | return userValid ? { |
185 | 186 | user: { |
186 | 187 | userid: g_userid, |
|
227 | 228 | async: false, |
228 | 229 | success: function(json) { |
229 | 230 | var loginresponse = json.loginresponse; |
230 | | - |
231 | | - g_sessionKey = encodeURIComponent(loginresponse.sessionkey); |
| 231 | + // sessionkey is recevied as a HttpOnly cookie |
| 232 | + // therefore reset any g_sessionKey value, an explicit |
| 233 | + // param in the API call is no longer needed |
| 234 | + g_sessionKey = null; |
232 | 235 | g_role = loginresponse.type; |
233 | 236 | g_username = loginresponse.username; |
234 | 237 | g_userid = loginresponse.userid; |
235 | 238 | g_account = loginresponse.account; |
236 | 239 | g_domainid = loginresponse.domainid; |
237 | | - g_timezone = loginresponse.timezone; |
| 240 | + g_timezone = loginresponse.timezone; |
238 | 241 | g_userfullname = loginresponse.firstname + ' ' + loginresponse.lastname; |
239 | 242 |
|
240 | 243 | $.cookie('username', g_username, { |
|
320 | 323 | $.ajax({ |
321 | 324 | url: createURL('logout'), |
322 | 325 | async: false, |
323 | | - success: function() { |
| 326 | + success: function() { |
324 | 327 | g_sessionKey = null; |
325 | 328 | g_username = null; |
326 | 329 | g_account = null; |
|
331 | 334 | g_kvmsnapshotenabled = null; |
332 | 335 | g_regionsecondaryenabled = null; |
333 | 336 | g_loginCmdText = null; |
334 | | - |
335 | | - $.cookie('JSESSIONID', null); |
336 | | - $.cookie('sessionkey', null); |
337 | | - $.cookie('username', null); |
338 | | - $.cookie('account', null); |
339 | | - $.cookie('domainid', null); |
340 | | - $.cookie('role', null); |
341 | | - $.cookie('timezone', null); |
342 | | - |
| 337 | + |
| 338 | + // Remove any cookies |
| 339 | + var cookies = document.cookie.split(";"); |
| 340 | + for (var i = 0; i < cookies.length; i++) { |
| 341 | + var cookieName = $.trim(cookies[i].split("=")[0]); |
| 342 | + if (['login-option', 'lang'].indexOf(cookieName) < 0) { |
| 343 | + $.cookie(cookieName, null); |
| 344 | + } |
| 345 | + } |
| 346 | + |
343 | 347 | if (onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen. |
344 | 348 | document.location.reload(); //when onLogoutCallback() returns true, reload the current document. |
345 | 349 | } |
|
367 | 371 | g_regionsecondaryenabled = null; |
368 | 372 | g_loginCmdText = null; |
369 | 373 |
|
370 | | - $.cookie('JSESSIONID', null); |
371 | | - $.cookie('sessionkey', null); |
372 | | - $.cookie('username', null); |
373 | | - $.cookie('account', null); |
374 | | - $.cookie('domainid', null); |
375 | | - $.cookie('role', null); |
376 | | - $.cookie('timezone', null); |
| 374 | + // Remove any cookies |
| 375 | + var cookies = document.cookie.split(";"); |
| 376 | + for (var i = 0; i < cookies.length; i++) { |
| 377 | + var cookieName = $.trim(cookies[i].split("=")[0]); |
| 378 | + if (['login-option', 'lang'].indexOf(cookieName) < 0) { |
| 379 | + $.cookie(cookieName, null); |
| 380 | + } |
| 381 | + } |
| 382 | + |
377 | 383 | var url = 'samlSso'; |
378 | 384 | if (args.data.idpid) { |
379 | 385 | url = url + '&idpid=' + args.data.idpid; |
|
0 commit comments