From 5c4964bc555b3da6ed39b86024ecdaff468d1664 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 12 Aug 2010 17:34:32 +0000 Subject: [PATCH] Monotone-Parent: 4bda58ef38f5ccda5b874a0271bc6fd1168c8d2e Monotone-Revision: 4931dae72f1ad88e9b719cf79ec472271ce13836 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-08-12T17:34:32 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 16 ++++++++++++ UI/Common/UIxPageFrame.m | 9 +++++++ UI/MainUI/SOGoRootPage.m | 5 ++++ UI/MainUI/product.plist | 7 +++++- UI/Templates/UIxPageFrame.wox | 6 +++++ UI/WebServerResources/generic.js | 43 ++++++++++++++++++++++++-------- 6 files changed, 74 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index b5a43da44..736b27365 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2010-08-12 Wolfgang Sourdeau + * UI/WebServerResources/generic.js: (onAjaxRequestStateChange): + when using CAS authentication and when the return code is 0 and + when the request status is 4, chances are that the initial ajax + request failed due to the expiration of the CAS ticket entry in + memcached. In FF 3.5 and above, a bug prevents the initial cookie + from being given back to the reauthentication redirect from an + AJAX request. Therefore we open a window that will do this for us + and will close one the authentication has succeeded again. + + * UI/MainUI/SOGoRootPage.m (-revoverAction): new fake action that + perform the CAS redirection and then trigger the respawn of the + initial request. + + * UI/Common/UIxPageFrame.m (-usesCASAuthentication): new accessor + used for recovery of redirected requests. + * SoObjects/Contacts/SOGoFolder+CardDAV.m: (_appendObject:withBaseURL:toREPORTResponse:): moved method here from SOGOContact{GCS,Source}Folder since its implementation was diff --git a/UI/Common/UIxPageFrame.m b/UI/Common/UIxPageFrame.m index 9e33be5c9..ab9ac4947 100644 --- a/UI/Common/UIxPageFrame.m +++ b/UI/Common/UIxPageFrame.m @@ -406,6 +406,15 @@ && [user isSuperUser]); } +- (BOOL) usesCASAuthentication +{ + SOGoSystemDefaults *sd; + + sd = [SOGoSystemDefaults sharedSystemDefaults]; + + return [[sd authenticationType] isEqualToString: @"cas"]; +} + - (NSString *) userIdentification { /* The "identification" term is used in the human sense here. */ diff --git a/UI/MainUI/SOGoRootPage.m b/UI/MainUI/SOGoRootPage.m index 842da7402..18cba979e 100644 --- a/UI/MainUI/SOGoRootPage.m +++ b/UI/MainUI/SOGoRootPage.m @@ -435,4 +435,9 @@ return response; } +- (id) recoverAction +{ + return [self jsCloseWithRefreshMethod: @"recoverRequest();"]; +} + @end /* SOGoRootPage */ diff --git a/UI/MainUI/product.plist b/UI/MainUI/product.plist index 7bb31f229..0def5f8f3 100644 --- a/UI/MainUI/product.plist +++ b/UI/MainUI/product.plist @@ -106,10 +106,15 @@ }; }; methods = { - view = { + view = { protectedBy = ""; pageName = "SOGoRootPage"; }; + recover = { + protectedBy = "View"; + pageName = "SOGoRootPage"; + actionName = "recover"; + }; index = { protectedBy = ""; pageName = "SOGoRootPage"; diff --git a/UI/Templates/UIxPageFrame.wox b/UI/Templates/UIxPageFrame.wox index 40f01cb5e..9b6ea298c 100644 --- a/UI/Templates/UIxPageFrame.wox +++ b/UI/Templates/UIxPageFrame.wox @@ -133,6 +133,12 @@ var IsSuperUser = false; + var usesCASAuthentication = true; + + var usesCASAuthentication = false; + var UserFolderURL = ''; diff --git a/UI/WebServerResources/generic.js b/UI/WebServerResources/generic.js index 59307f451..28e622a52 100644 --- a/UI/WebServerResources/generic.js +++ b/UI/WebServerResources/generic.js @@ -23,6 +23,7 @@ var logConsole; var logWindow = null; var queryParameters; +var recoveryRequest = null; var menus = new Array(); var search = {}; @@ -245,15 +246,24 @@ function createHTTPClient() { function onAjaxRequestStateChange(http) { try { - if (http.readyState == 4 - && activeAjaxRequests > 0) { - if (!http.aborted) - http.callback(http); - activeAjaxRequests--; - checkAjaxRequestsState(); - http.onreadystatechange = Prototype.emptyFunction; - http.callback = Prototype.emptyFunction; - http.callbackData = null; + if (http.readyState == 4) { + if (http.status == 0 && usesCASAuthentication) { + recoveryRequest = http; + var urlstr = ApplicationBaseURL; + if (!urlstr.endsWith('/')) + urlstr += '/'; + urlstr += ("../../recover"); + window.open(urlstr, "_blank"); + } + else if (activeAjaxRequests > 0) { + if (!http.aborted) + http.callback(http); + activeAjaxRequests--; + checkAjaxRequestsState(); + http.onreadystatechange = Prototype.emptyFunction; + http.callback = Prototype.emptyFunction; + http.callbackData = null; + } } } catch(e) { @@ -275,6 +285,16 @@ function onAjaxRequestStateChange(http) { } } +function recoverRequest() { + if (recoveryRequest) { + triggerAjaxRequest(recoveryRequest.url, + recoveryRequest.callback, + recoveryRequest.callbackData, + recoveryRequest.paramHeaders); + recoveryRequest = null; + } +} + /* taken from Lightning */ function getContrastingTextColor(bgColor) { var calcColor = bgColor.substring(1); @@ -298,9 +318,10 @@ function triggerAjaxRequest(url, callback, userdata, content, headers) { http.open("POST", url, true); http.url = url; + http.paramHeaders = headers; http.callback = callback; http.callbackData = userdata; - http.onreadystatechange = function() { onAjaxRequestStateChange(http);}; + http.onreadystatechange = function() { onAjaxRequestStateChange(http); }; // = function() { // // log ("state changed (" + http.readyState + "): " + url); // }; @@ -1755,7 +1776,7 @@ function showAlertDialog(label) { _showAlertDialog(label); } } - + function _showAlertDialog(label) { var dialog = null; if (dialogs[label])