mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	remove cookie persistence
This commit is contained in:
		
							parent
							
								
									c569843a4a
								
							
						
					
					
						commit
						34f9521c34
					
				| @ -24,8 +24,6 @@ | ||||
| 
 | ||||
| package com.owncloud.android.lib.common; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.accounts.AccountManager; | ||||
| import android.accounts.AuthenticatorException; | ||||
| import android.accounts.OperationCanceledException; | ||||
| import android.content.Context; | ||||
| @ -37,7 +35,6 @@ import com.owncloud.android.lib.common.http.HttpClient; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| import java.util.Iterator; | ||||
| import java.util.concurrent.ConcurrentHashMap; | ||||
| import java.util.concurrent.ConcurrentMap; | ||||
| 
 | ||||
| @ -136,7 +133,6 @@ public class SingleSessionManager { | ||||
|                 Timber.v("reusing client for session %s", sessionName); | ||||
|             } | ||||
| 
 | ||||
|             keepCookiesUpdated(context, account, client); | ||||
|             keepUriUpdated(account, client); | ||||
|         } | ||||
|         Timber.d("getClientFor finishing "); | ||||
| @ -167,32 +163,6 @@ public class SingleSessionManager { | ||||
|         Timber.d("removeClientFor finishing "); | ||||
|     } | ||||
| 
 | ||||
|     public void saveAllClients(Context context, String accountType) { | ||||
|         Timber.d("Saving sessions... "); | ||||
| 
 | ||||
|         Iterator<String> accountNames = mClientsWithKnownUsername.keySet().iterator(); | ||||
|         String accountName; | ||||
|         Account account; | ||||
|         while (accountNames.hasNext()) { | ||||
|             accountName = accountNames.next(); | ||||
|             account = new Account(accountName, accountType); | ||||
|             AccountUtils.saveClient(mClientsWithKnownUsername.get(accountName), account, context); | ||||
|         } | ||||
| 
 | ||||
|         Timber.d("All sessions saved"); | ||||
|     } | ||||
| 
 | ||||
|     private void keepCookiesUpdated(Context context, OwnCloudAccount account, OwnCloudClient reusedClient) { | ||||
|         AccountManager am = AccountManager.get(context.getApplicationContext()); | ||||
|         if (am != null && account.getSavedAccount() != null) { | ||||
|             String recentCookies = am.getUserData(account.getSavedAccount(), AccountUtils.Constants.KEY_COOKIES); | ||||
|             String previousCookies = reusedClient.getCookiesString(); | ||||
|             if (recentCookies != null && !previousCookies.equals("") && !recentCookies.equals(previousCookies)) { | ||||
|                 AccountUtils.restoreCookies(account.getSavedAccount(), reusedClient, context); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public void refreshCredentialsForAccount(String accountName, OwnCloudCredentials credentials) { | ||||
|         OwnCloudClient ownCloudClient = mClientsWithKnownUsername.get(accountName); | ||||
|         if (ownCloudClient == null) { | ||||
|  | ||||
| @ -36,15 +36,10 @@ import android.net.Uri; | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; | ||||
| import com.owncloud.android.lib.resources.files.FileUtils; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| import okhttp3.Cookie; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| public class AccountUtils { | ||||
|     /** | ||||
| @ -202,64 +197,6 @@ public class AccountUtils { | ||||
|         return username + "@" + url; | ||||
|     } | ||||
| 
 | ||||
|     public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) { | ||||
|         // Account Manager | ||||
|         AccountManager ac = AccountManager.get(context.getApplicationContext()); | ||||
| 
 | ||||
|         if (client != null) { | ||||
|             String cookiesString = client.getCookiesString(); | ||||
|             if (!"".equals(cookiesString)) { | ||||
|                 ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString); | ||||
|                 Timber.d("Saving Cookies: %s", cookiesString); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Restore the client cookies persisted in an account stored in the system AccountManager. | ||||
|      * | ||||
|      * @param account Stored account. | ||||
|      * @param client  Client to restore cookies in. | ||||
|      * @param context Android context used to access the system AccountManager. | ||||
|      */ | ||||
|     public static void restoreCookies(Account account, OwnCloudClient client, Context context) { | ||||
|         if (account == null) { | ||||
|             Timber.d("Cannot restore cookie for null account"); | ||||
| 
 | ||||
|         } else { | ||||
|             Timber.d("Restoring cookies for %s", account.name); | ||||
| 
 | ||||
|             // Account Manager | ||||
|             AccountManager am = AccountManager.get(context.getApplicationContext()); | ||||
| 
 | ||||
|             Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getUserFilesWebDavUri(); | ||||
| 
 | ||||
|             String cookiesString = am.getUserData(account, Constants.KEY_COOKIES); | ||||
|             if (cookiesString != null) { | ||||
|                 String[] rawCookies = cookiesString.split(";"); | ||||
|                 List<Cookie> cookieList = new ArrayList<>(rawCookies.length); | ||||
|                 for (String rawCookie : rawCookies) { | ||||
|                     rawCookie = rawCookie.replace(" ", ""); | ||||
|                     final int equalPos = rawCookie.indexOf('='); | ||||
|                     if (equalPos == -1) { | ||||
|                         continue; | ||||
|                     } | ||||
|                     cookieList.add(new Cookie.Builder() | ||||
|                             .name(rawCookie.substring(0, equalPos)) | ||||
|                             .value(rawCookie.substring(equalPos + 1)) | ||||
|                             .domain(serverUri.getHost()) | ||||
|                             .path( | ||||
|                                     serverUri.getPath().equals("") | ||||
|                                             ? File.separator | ||||
|                                             : serverUri.getPath() | ||||
|                             ) | ||||
|                             .build()); | ||||
|                 } | ||||
|                 client.setCookiesForCurrentAccount(cookieList); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static class AccountNotFoundException extends AccountsException { | ||||
| 
 | ||||
|         /** | ||||
|  | ||||
| @ -258,11 +258,6 @@ public abstract class RemoteOperation<T> implements Runnable { | ||||
| 
 | ||||
|         final RemoteOperationResult resultToSend = runOperation(); | ||||
| 
 | ||||
|         if (mAccount != null && mContext != null) { | ||||
|             // Save Client Cookies | ||||
|             AccountUtils.saveClient(mClient, mAccount, mContext); | ||||
|         } | ||||
| 
 | ||||
|         if (mListenerHandler != null && mListener != null) { | ||||
|             mListenerHandler.post(() -> | ||||
|                     mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend)); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user