Kill former session when authentication token is updated
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 9 Feb 2015 12:12:22 +0000 (13:12 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 9 Feb 2015 14:30:17 +0000 (15:30 +0100)
src/com/owncloud/android/authentication/AuthenticatorActivity.java

index a7774ff..03f6585 100644 (file)
@@ -68,7 +68,6 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.R;\r
 import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
 import com.owncloud.android.lib.common.OwnCloudAccount;\r
-import com.owncloud.android.lib.common.OwnCloudClient;\r
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;\r
 import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\r
 import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
@@ -996,19 +995,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 if (!mUsernameInput.getText().toString().equals(username)) {\r
                     // fail - not a new account, but an existing one; disallow\r
                     result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME);\r
-                    /*\r
-                    OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(\r
-                            new OwnCloudAccount(\r
-                                    Uri.parse(mServerInfo.mBaseUrl),\r
-                                    OwnCloudCredentialsFactory.newSamlSsoCredentials(mAuthToken))\r
-                            );\r
-                            */\r
                     mAuthToken = "";\r
                     updateAuthStatusIconAndText(result);\r
                     showAuthStatus();\r
                     Log_OC.d(TAG, result.getLogMessage());\r
                 } else {\r
-                    updateToken();\r
+                    updateAccountAuthentication();\r
                     success = true;\r
                 }\r
             }\r
@@ -1375,7 +1367,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 success = createAccount();\r
 \r
             } else {\r
-                updateToken();\r
+                updateAccountAuthentication();\r
                 success = true;\r
             }\r
 \r
@@ -1417,10 +1409,25 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
 \r
     /**\r
-     * Sets the proper response to get that the Account Authenticator that started this activity \r
+     * Updates the authentication token.\r
+     *\r
+     * Sets the proper response so that the AccountAuthenticator that started this activity\r
      * saves a new authorization token for mAccount.\r
+     *\r
+     * Kills the session kept by OwnCloudClientManager so that a new one will created with\r
+     * the new credentials when needed.\r
      */\r
-    private void updateToken() {\r
+    private void updateAccountAuthentication() {\r
+\r
+        try {\r
+            OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(\r
+                new OwnCloudAccount(mAccount, this)     // TODO avoid this creation may block the main thread\r
+            );\r
+        } catch (Exception e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+\r
         Bundle response = new Bundle();\r
         response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);\r
         response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);\r