From: masensio Date: Fri, 13 Feb 2015 13:39:35 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/enable_cookies' into enable_cookies X-Git-Tag: oc-android-1.7.1_signed^2~42^2~4 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/fba65e37f68f5cd72fb20c96982607702193a509?ds=inline;hp=-c Merge remote-tracking branch 'origin/enable_cookies' into enable_cookies Conflicts: src/com/owncloud/android/authentication/AuthenticatorActivity.java src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java --- fba65e37f68f5cd72fb20c96982607702193a509 diff --combined src/com/owncloud/android/authentication/AuthenticatorActivity.java index 6d092a2a,0c735401..e2c3c033 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@@ -1,6 -1,6 +1,6 @@@ /* ownCloud Android client application * Copyright (C) 2012 Bartek Przybylski - * Copyright (C) 2012-2014 ownCloud Inc. + * Copyright (C) 2012-2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@@ -18,11 -18,14 +18,11 @@@ package com.owncloud.android.authentication; -import java.io.IOException; import java.security.cert.X509Certificate; import java.util.Map; import android.accounts.Account; import android.accounts.AccountManager; -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; import android.app.Dialog; import android.content.ComponentName; import android.content.Context; @@@ -33,7 -36,6 +33,7 @@@ import android.graphics.Rect import android.graphics.drawable.Drawable; import android.net.Uri; import android.net.http.SslError; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@@ -65,7 -67,10 +65,10 @@@ import com.actionbarsherlock.app.Sherlo import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener; + import com.owncloud.android.lib.common.OwnCloudAccount; + import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; + import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.network.CertificateCombinedException; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; @@@ -134,9 -139,6 +137,9 @@@ public class AuthenticatorActivity exte private static final String CREDENTIALS_DIALOG_TAG = "CREDENTIALS_DIALOG"; private static final String KEY_AUTH_IS_FIRST_ATTEMPT_TAG = "KEY_AUTH_IS_FIRST_ATTEMPT"; + private static final String KEY_USERNAME = "USERNAME"; + private static final String KEY_PASSWORD = "PASSWORD"; + private static final String KEY_ASYNC_TASK_IN_PROGRESS = "AUTH_IN_PROGRESS"; /// parameters from EXTRAs in starter Intent private byte mAction; @@@ -180,9 -182,9 +183,9 @@@ private int mAuthStatusText = 0, mAuthStatusIcon = 0; private String mAuthToken = ""; + private AuthenticatorAsyncTask mAsyncTask; private boolean mIsFirstAuthAttempt; - /// Identifier of operation in progress which result shouldn't be lost private long mWaitingForOpId = Long.MAX_VALUE; @@@ -422,9 -424,9 +425,9 @@@ if ( AccountTypeUtils.getAuthTokenTypeSamlSessionCookie( MainApp.getAccountType() - ).equals(mAuthTokenType) && - mHostUrlInput.hasFocus() - ) { + ).equals(mAuthTokenType) && + mHostUrlInput.hasFocus() + ) { checkOcServer(); } } @@@ -588,35 -590,9 +591,35 @@@ /// authentication outState.putBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG, mIsFirstAuthAttempt); + /// AsyncTask (User and password) + outState.putString(KEY_USERNAME, mUsernameInput.getText().toString()); + outState.putString(KEY_PASSWORD, mPasswordInput.getText().toString()); + + if (mAsyncTask != null) { + mAsyncTask.cancel(true); + outState.putBoolean(KEY_ASYNC_TASK_IN_PROGRESS, true); + } else { + outState.putBoolean(KEY_ASYNC_TASK_IN_PROGRESS, false); + } + mAsyncTask = null; + //Log_OC.wtf(TAG, "onSaveInstanceState end" ); } + @Override + public void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + + // AsyncTask + boolean inProgress = savedInstanceState.getBoolean(KEY_ASYNC_TASK_IN_PROGRESS); + if (inProgress){ + mAsyncTask = new AuthenticatorAsyncTask(this); + String username = savedInstanceState.getString(KEY_USERNAME); + String password = savedInstanceState.getString(KEY_PASSWORD); + String[] params = {mServerInfo.mBaseUrl, username, password, mAuthToken, mAuthTokenType}; + mAsyncTask.execute(params); + } + } /** * The redirection triggered by the OAuth authentication server as response to the @@@ -917,9 -893,9 +920,9 @@@ mAccountMgr.setUserData(mAccount, Constants.KEY_COOKIES, null); } - AuthenticatorAsyncTask asyncTask = new AuthenticatorAsyncTask(this); + mAsyncTask = new AuthenticatorAsyncTask(this); String[] params = { mServerInfo.mBaseUrl, username, password, mAuthToken, mAuthTokenType}; - asyncTask.execute(params); + mAsyncTask.execute(params); } @@@ -1020,20 -996,20 +1023,20 @@@ if (!mUsernameInput.getText().toString().equals(username)) { // fail - not a new account, but an existing one; disallow result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME); - /* - OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor( - new OwnCloudAccount( - Uri.parse(mServerInfo.mBaseUrl), - OwnCloudCredentialsFactory.newSamlSsoCredentials(mAuthToken)) - ); - */ mAuthToken = ""; updateAuthStatusIconAndText(result); showAuthStatus(); Log_OC.d(TAG, result.getLogMessage()); } else { - updateToken(); - success = true; + try { + updateAccountAuthentication(); + success = true; + + } catch (AccountNotFoundException e) { + Log_OC.e(TAG, "Account " + mAccount + " was removed!", e); + Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show(); + finish(); + } } } @@@ -1399,8 -1375,15 +1402,15 @@@ success = createAccount(); } else { - updateToken(); - success = true; + try { + updateAccountAuthentication(); + success = true; + + } catch (AccountNotFoundException e) { + Log_OC.e(TAG, "Account " + mAccount + " was removed!", e); + Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show(); + finish(); + } } if (success) { @@@ -1441,10 -1424,20 +1451,23 @@@ /** - * Sets the proper response to get that the Account Authenticator that started this activity + * Updates the authentication token. + * + * Sets the proper response so that the AccountAuthenticator that started this activity * saves a new authorization token for mAccount. + * + * Kills the session kept by OwnCloudClientManager so that a new one will created with + * the new credentials when needed. */ - private void updateToken() { + private void updateAccountAuthentication() throws AccountNotFoundException { - - OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor( - new OwnCloudAccount(mAccount, this) - ); ++ try { ++ OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor( ++ new OwnCloudAccount(mAccount, this) ++ ); ++ } catch (Exception e) { ++ Log_OC.e(TAG, "Exception", e); ++ } + Bundle response = new Bundle(); response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name); response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type); diff --combined src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java index bf2355c8,43822bfd..6e215342 --- a/src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java +++ b/src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java @@@ -1,19 -1,3 +1,19 @@@ +/* ownCloud Android client application + * Copyright (C) 2012-2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ package com.owncloud.android.authentication; import android.app.Activity; @@@ -40,17 -24,16 +40,17 @@@ import java.lang.ref.WeakReference */ public class AuthenticatorAsyncTask extends AsyncTask { - private static String REMOTE_PATH = "/"; private static boolean SUCCESS_IF_ABSENT = false; private Context mContext; private final WeakReference mListener; + protected Activity mActivity; public AuthenticatorAsyncTask(Activity activity) { mContext = activity.getApplicationContext(); - mListener = new WeakReference<>((OnAuthenticatorTaskListener)activity); + mListener = new WeakReference((OnAuthenticatorTaskListener)activity); + mActivity = activity; } @Override @@@ -111,6 -94,7 +111,6 @@@ } } } - /* * Interface to retrieve data from recognition task */