From fbb779a71d6fc1b97ccfb7ba5a68f02ab973f43a Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 6 May 2015 16:03:33 -0400 Subject: [PATCH] (fix) During login, we now extract the domain from the user to accelerate authentication requests on sources --- NEWS | 1 + SoObjects/SOGo/SOGoUserManager.m | 36 +++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 992a01184..672072ade 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ Enhancements - Missing contact fields are now saved and available when sharing it (Office, Profession, Manager's name, Assistant's name, Spouse/Partner, Anniversary) (Zentyal) - Appointment color and importance work now between Outlooks (Zentyal) - Synchronize events, contacts and tasks in reverse chronological order (Zentyal) + - During login, we now extract the domain from the user to accelerate authentication requests on sources Bug fixes - now keep the BodyPreference for future EAS use and default to MIME if none set (#3146) diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 125ca3fcc..ae4d8612d 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -479,17 +479,47 @@ static Class NSNullK; NSString *dictPassword, *username, *jsonUser; SOGoSystemDefaults *dd; BOOL checkOK; - + + dd = [SOGoSystemDefaults sharedSystemDefaults]; + // We check for cached passwords. If the entry is cached, we // check this immediately. If not, we'll go directly at the // authentication source and try to validate there, then cache it. if (*_domain != nil) username = [NSString stringWithFormat: @"%@@%@", _login, *_domain]; else - username = _login; + { + NSRange r; + + username = _login; + + // We try to extract the domain in use in order to avoid pounding all the authentication + // sources if SOGoLoginDomains isn't specified. This is also true if the user is + // using DAV or EAS. + r = [username rangeOfString: @"@"]; + + if (r.location != NSNotFound) + { + NSArray *allDomains; + int i; + + *_domain = [username substringFromIndex: r.location+1]; + + allDomains = [[dd dictionaryForKey: @"domains"] allValues]; + + for (i = 0; i < [allDomains count]; i++) + { + if ([*_domain isEqualToString: [[allDomains objectAtIndex: i] objectForKey: @"SOGoMailDomain"]]) + break; + } + + // We haven't found one + if (i == [allDomains count]) + *_domain = nil; + } + } failedCount = [[SOGoCache sharedCache] failedCountForLogin: username]; - dd = [SOGoSystemDefaults sharedSystemDefaults]; // // We check the fail count per user in memcache (per server). If the