From 8d6d4ece42d53ba8aa152717f8934a8fef181719 Mon Sep 17 00:00:00 2001 From: nasli Date: Thu, 14 Dec 2017 12:18:12 +0100 Subject: [PATCH 1/3] Fix duplicate accounts --- OCCommunicationLib | 2 +- Owncloud iOs Client/AppDelegate.m | 19 +++++++++++-------- .../DataBase/Queries/ManageFilesDB.m | 2 +- .../Login/Keychain/OCKeychain.m | 2 +- .../Tabs/FileTab/FilesViewController.m | 2 +- .../Tabs/SettingTab/SettingsViewController.m | 3 --- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/OCCommunicationLib b/OCCommunicationLib index 5391f4b657..5a1929b347 160000 --- a/OCCommunicationLib +++ b/OCCommunicationLib @@ -1 +1 @@ -Subproject commit 5391f4b6579d799bd387fd70a80a327844e976d8 +Subproject commit 5a1929b3473cb44cb330308064519fad4fd6b529 diff --git a/Owncloud iOs Client/AppDelegate.m b/Owncloud iOs Client/AppDelegate.m index d0c2eb4334..f57c4b8985 100644 --- a/Owncloud iOs Client/AppDelegate.m +++ b/Owncloud iOs Client/AppDelegate.m @@ -2791,6 +2791,7 @@ -(void)badCertificateNotAcceptedByUser { - (void) switchActiveUserTo:(UserDto *)user isNewAccount:(BOOL)isNewAccount { + self.userSessionCurrentToken = nil; // should be here or right after checking the user really changed? for the moment, here @@ -2802,28 +2803,30 @@ - (void) switchActiveUserTo:(UserDto *)user isNewAccount:(BOOL)isNewAccount { // Cancel downloads of the previous user [self portedCancelAllDownloads]; + + [UtilsCookies saveActiveUserCookiesAndRestoreCookiesOfUser:user]; // update active state of users in DB [ManageUsersDB setAllUsersNoActive]; [ManageUsersDB setActiveAccountByUserId:user.userId]; user.activeaccount = YES; - - [UtilsCookies saveActiveUserCookiesAndRestoreCookiesOfUser:user]; - + //Change the active user in appDelegate global variable self.activeUser = user; - + + //We check the connection here because we need to accept the certificate on the self signed server before go to the files tab + [[CheckAccessToServer sharedManager] isConnectionToTheServerByUrl:[UtilsUrls getFullRemoteServerPath:user]]; + [CheckFeaturesSupported updateServerFeaturesAndCapabilitiesOfActiveUser]; - - [UtilsCookies eraseURLCache]; - - //we create the user folder to haver multiuser + + //we create the user folder to have multiuser [UtilsFileSystem createFolderForUser:user]; self.isNewUser = YES; ManageAccounts *manageAccounts = [ManageAccounts new]; [manageAccounts updateDisplayNameOfUserWithUser:user]; + } } diff --git a/Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m b/Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m index dda47474d8..ffbc0fb1f2 100644 --- a/Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m +++ b/Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m @@ -49,7 +49,7 @@ + (NSMutableArray *) getFilesByFileIdForActiveUser:(NSInteger) fileId { #endif __block NSMutableArray *output = [NSMutableArray new]; - DLog(@"getFilesByFileId: %ld for active user",(long)fileId); + DLog(@"getFilesByFileId: %ld for active user %ld, %@",(long)fileId, mUser.userId, mUser.username); FMDatabaseQueue *queue = Managers.sharedDatabase; diff --git a/Owncloud iOs Client/Login/Keychain/OCKeychain.m b/Owncloud iOs Client/Login/Keychain/OCKeychain.m index a7b0eff6f5..8f74823744 100644 --- a/Owncloud iOs Client/Login/Keychain/OCKeychain.m +++ b/Owncloud iOs Client/Login/Keychain/OCKeychain.m @@ -103,7 +103,7 @@ +(NSDictionary *)getKeychainDictionaryOfUserId:(NSString *)userId { OSStatus stsExist = SecItemCopyMatching((__bridge CFDictionaryRef)keychainItem, (CFTypeRef *)&result); - DLog(@"(getCredentials)Error Code %d (0 = success)", (int)stsExist); + DLog(@"(getCredentials of userId %@)Error Code %d (0 = success)", userId, (int)stsExist); if (stsExist != errSecSuccess) { NSLog(@"Unable to get the item with userId=%@ ",userId); diff --git a/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m b/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m index 26cb751b4f..fbea1efbbb 100644 --- a/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m +++ b/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m @@ -1855,7 +1855,7 @@ - (void) updateCurrentFileToShowIfNeeded { FileDto *rootFileDtoOfActiveUser = [ManageFilesDB getRootFileDtoByUser:app.activeUser]; if (self.fileIdToShowFiles.userId != rootFileDtoOfActiveUser.userId) { _fileIdToShowFiles = rootFileDtoOfActiveUser; - DLog(@"Changing between accounts, update _fileIdToShowFiles with root file of active user"); + DLog(@"Changing between accounts, update _fileIdToShowFiles with root file of active user %ld, %@", (long)app.activeUser.userId, app.activeUser.username); } } } diff --git a/Owncloud iOs Client/Tabs/SettingTab/SettingsViewController.m b/Owncloud iOs Client/Tabs/SettingTab/SettingsViewController.m index 1ff4f3eea8..ba90bca612 100644 --- a/Owncloud iOs Client/Tabs/SettingTab/SettingsViewController.m +++ b/Owncloud iOs Client/Tabs/SettingTab/SettingsViewController.m @@ -1100,9 +1100,6 @@ - (void) didPressOnAccountIndexPath:(NSIndexPath*)indexPath { AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; UserDto *selectedUser = (UserDto *)[self.listUsers objectAtIndex:indexPath.row]; - //We check the connection here because we need to accept the certificate on the self signed server before go to the files tab - [[CheckAccessToServer sharedManager] isConnectionToTheServerByUrl:[UtilsUrls getFullRemoteServerPath:selectedUser]]; - //Method to change the account [[OCLoadingSpinner sharedOCLoadingSpinner] initLoadingForViewController: self]; [app switchActiveUserTo:selectedUser isNewAccount:NO]; From ce26e30c58d68808de4f5241755e7f3bc6f3d492 Mon Sep 17 00:00:00 2001 From: nasli Date: Thu, 14 Dec 2017 15:21:55 +0100 Subject: [PATCH 2/3] Update library commit --- OCCommunicationLib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OCCommunicationLib b/OCCommunicationLib index 5a1929b347..c0cbbddc76 160000 --- a/OCCommunicationLib +++ b/OCCommunicationLib @@ -1 +1 @@ -Subproject commit 5a1929b3473cb44cb330308064519fad4fd6b529 +Subproject commit c0cbbddc7628b6c96476b3eb67806e8ee11a1831 From ff4b3f9abcaf56f8768837ee56626e11788dd2ed Mon Sep 17 00:00:00 2001 From: nasli Date: Fri, 15 Dec 2017 11:41:32 +0100 Subject: [PATCH 3/3] Fix use correct cookies after a renew of credentials in SAML --- .../Login/UniversalLoginViewController.swift | 1 + .../Network/UserData/DetectUserData.m | 1 + Owncloud iOs Client/Utils/UtilsCookies.h | 2 ++ Owncloud iOs Client/Utils/UtilsCookies.m | 27 ++++++++++++------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Owncloud iOs Client/Login/Login/UniversalLoginViewController.swift b/Owncloud iOs Client/Login/Login/UniversalLoginViewController.swift index 76cd8a319e..40cc46ee4a 100644 --- a/Owncloud iOs Client/Login/Login/UniversalLoginViewController.swift +++ b/Owncloud iOs Client/Login/Login/UniversalLoginViewController.swift @@ -643,6 +643,7 @@ public enum TextfieldType: String { return; } + UtilsCookies.updateOfActiveUserInDB() self.detectUserDataAndValidate(credentials: userCredDto, serverPath: serverPath!) } diff --git a/Owncloud iOs Client/Network/UserData/DetectUserData.m b/Owncloud iOs Client/Network/UserData/DetectUserData.m index cb6fd726dc..ba29ff38f1 100644 --- a/Owncloud iOs Client/Network/UserData/DetectUserData.m +++ b/Owncloud iOs Client/Network/UserData/DetectUserData.m @@ -28,6 +28,7 @@ + (void) getUserDisplayNameOfServer:(NSString*)path credentials:(OCCredentialsDt withCompletion:(void(^)(NSString *serverUserID, NSString *displayName, NSError *error))completion { [[AppDelegate sharedOCCommunication] setCredentials:credentials]; + DLog(@"credDto: %@",credentials.userName); [[AppDelegate sharedOCCommunication] setValueOfUserAgent:[UtilsUrls getUserAgent]]; diff --git a/Owncloud iOs Client/Utils/UtilsCookies.h b/Owncloud iOs Client/Utils/UtilsCookies.h index a41d96b075..1bc2d9ff02 100644 --- a/Owncloud iOs Client/Utils/UtilsCookies.h +++ b/Owncloud iOs Client/Utils/UtilsCookies.h @@ -25,6 +25,8 @@ + (void) eraseURLCache; ++ (void) updateCookiesOfActiveUserInDB; + + (void) saveCurrentOfActiveUserAndClean; + (void) restoreCookiesOfUser:(UserDto *)user; diff --git a/Owncloud iOs Client/Utils/UtilsCookies.m b/Owncloud iOs Client/Utils/UtilsCookies.m index a207ddb259..d61e4700e5 100644 --- a/Owncloud iOs Client/Utils/UtilsCookies.m +++ b/Owncloud iOs Client/Utils/UtilsCookies.m @@ -66,22 +66,29 @@ + (void) eraseURLCache [[NSURLCache sharedURLCache] setDiskCapacity:0]; } ++ (void) updateCookiesOfActiveUserInDB { + AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; + + if (app.activeUser != nil) { + DLog(@"_updateCookiesOfActiveUserInDB_"); + + //1- Try to Delete the cookies of the active user + [ManageCookiesStorageDB deleteCookiesByUser:app.activeUser]; + + //2- Store the current cookies on the Database + [UtilsCookies setOnDBStorageCookiesByUser:app.activeUser]; + } +} + + (void) saveCurrentOfActiveUserAndClean { DLog(@"_saveAndCleanCookies_"); - AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; - //Clear the cookies before to try to do login - //1- Try to Delete the cookies of the active user - [ManageCookiesStorageDB deleteCookiesByUser:app.activeUser]; - - //2- Store the current cookies on the Database - if (app.activeUser != nil) { - [UtilsCookies setOnDBStorageCookiesByUser:app.activeUser]; - } - //3- Clean the cookies storage + [self updateCookiesOfActiveUserInDB]; + + //Clean the cookies storage [UtilsFramework deleteAllCookies]; }