From: masensio Date: Thu, 19 Feb 2015 12:02:53 +0000 (+0100) Subject: Merge branch 'develop' into enable_cookies X-Git-Tag: oc-android-1.7.1_signed^2~42^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/0a03b6d3d46b20773e5c2b0548557ae4dd3cc260?ds=inline;hp=-c Merge branch 'develop' into enable_cookies Conflicts: src/com/owncloud/android/authentication/AuthenticatorActivity.java --- 0a03b6d3d46b20773e5c2b0548557ae4dd3cc260 diff --combined src/com/owncloud/android/MainApp.java index f7b4720e,c2a4c68b..65e704be --- a/src/com/owncloud/android/MainApp.java +++ b/src/com/owncloud/android/MainApp.java @@@ -1,5 -1,5 +1,5 @@@ /* ownCloud Android client application - * Copyright (C) 2012-2013 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, @@@ -36,15 -36,26 +36,26 @@@ public class MainApp extends Applicatio private static final String AUTH_ON = "on"; + @SuppressWarnings("unused") + private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account"; + @SuppressWarnings("unused") + private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client"; + private static Context mContext; public void onCreate(){ super.onCreate(); MainApp.mContext = getApplicationContext(); - - // keep a single session per account handling session cookie in requests (& all the other cookies) - OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); + + boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso)); + + if (isSamlAuth) { + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); + } else { + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT); + } + // initialise thumbnails cache on background thread new ThumbnailsCacheManager.InitDiskCacheTask().execute(); diff --combined src/com/owncloud/android/authentication/AuthenticatorActivity.java index 9c42f276,8d7182d7..ed686140 --- 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, @@@ -33,7 -33,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,10 -64,7 +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; @@@ -99,9 -95,8 +99,9 @@@ import com.owncloud.android.utils.Displ * @author masensio */ public class AuthenticatorActivity extends AccountAuthenticatorActivity -implements OnRemoteOperationListener, OnFocusChangeListener, OnEditorActionListener, -SsoWebViewClientListener, OnSslUntrustedCertListener { + implements OnRemoteOperationListener, OnFocusChangeListener, OnEditorActionListener, + SsoWebViewClientListener, OnSslUntrustedCertListener, + AuthenticatorAsyncTask.OnAuthenticatorTaskListener { private static final String TAG = AuthenticatorActivity.class.getSimpleName(); @@@ -137,9 -132,6 +137,9 @@@ 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; @@@ -183,9 -175,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; @@@ -230,8 -222,6 +230,6 @@@ mWaitingForOpId = savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID); mIsFirstAuthAttempt = savedInstanceState.getBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG); } - - /// load user interface setContentView(R.layout.account_setup); @@@ -425,9 -415,9 +423,9 @@@ if ( AccountTypeUtils.getAuthTokenTypeSamlSessionCookie( MainApp.getAccountType() - ).equals(mAuthTokenType) && - mHostUrlInput.hasFocus() - ) { + ).equals(mAuthTokenType) && + mHostUrlInput.hasFocus() + ) { checkOcServer(); } } @@@ -559,7 -549,7 +557,7 @@@ * intended to defer the processing of the redirection caught in * {@link #onNewIntent(Intent)} until {@link #onResume()} * - * See {@link #loadSavedInstanceState(Bundle)} + * See {@link #onSaveInstanceState(Bundle)} */ @Override protected void onSaveInstanceState(Bundle outState) { @@@ -591,35 -581,9 +589,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 @@@ -914,16 -878,18 +912,16 @@@ } private void accessRootFolderRemoteOperation(String username, String password) { - Intent existenceCheckIntent = new Intent(); - existenceCheckIntent.setAction(OperationsService.ACTION_EXISTENCE_CHECK); - existenceCheckIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl); - existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, "/"); - existenceCheckIntent.putExtra(OperationsService.EXTRA_USERNAME, username); - existenceCheckIntent.putExtra(OperationsService.EXTRA_PASSWORD, password); - existenceCheckIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN, mAuthToken); - - if (mOperationsServiceBinder != null) { - //Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." ); - mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(existenceCheckIntent); + // delete the account if the token has changed + if (mAction == ACTION_UPDATE_TOKEN || mAction == ACTION_UPDATE_EXPIRED_TOKEN) { + // Remove the cookies in AccountManager + mAccountMgr.setUserData(mAccount, Constants.KEY_COOKIES, null); } + + mAsyncTask = new AuthenticatorAsyncTask(this); + String[] params = { mServerInfo.mBaseUrl, username, password, mAuthToken, mAuthTokenType}; + mAsyncTask.execute(params); + } /** @@@ -994,7 -960,6 +992,7 @@@ onGetOAuthAccessTokenFinish(result); } else if (operation instanceof ExistenceCheckRemoteOperation) { + // TODO : remove this response?? //Log_OC.wtf(TAG, "received detection response through callback" ); if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()). equals(mAuthTokenType)) { @@@ -1023,20 -988,20 +1021,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(); + } } } @@@ -1053,8 -1018,8 +1051,8 @@@ private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result) { mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); - - if (result.isIdPRedirection()) { + + if (result.isIdPRedirection()) { String targetUrl = mServerInfo.mBaseUrl + AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType); @@@ -1077,7 -1042,8 +1075,7 @@@ /** * Processes the result of the server check performed when the user finishes the enter of the * server URL. - * - * @param operation Server check performed. + * * @param result Result of the check. */ private void onGetServerInfoFinish(RemoteOperationResult result) { @@@ -1387,7 -1353,8 +1385,7 @@@ * Processes the result of the access check performed to try the user credentials. * * Creates a new account through the AccountManager. - * - * @param operation Access check performed. + * * @param result Result of the operation. */ private void onAuthorizationCheckFinish(RemoteOperationResult result) { @@@ -1402,22 -1369,15 +1400,22 @@@ 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) { finish(); } - } else if (result.isServerFail() || result.isException()) { + } else if (result.isServerFail() || result.isException()) { /// server errors or exceptions in authorization take to requiring a new check of /// the server mServerIsChecked = true; @@@ -1451,20 -1411,10 +1449,20 @@@ /** - * 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) +// ); + Bundle response = new Bundle(); response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name); response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type); @@@ -1557,14 -1507,14 +1555,14 @@@ mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken); } /// add user data to the new account; TODO probably can be done in the last parameter - // addAccountExplicitly, or in KEY_USERDATA + // addAccountExplicitly, or in KEY_USERDATA mAccountMgr.setUserData( mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion() ); mAccountMgr.setUserData( mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl ); - + if (isSaml) { mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); } else if (isOAuth) { @@@ -1596,6 -1546,9 +1594,7 @@@ /** * Updates the content and visibility state of the icon and text associated * to the last check on the ownCloud server. - * - * @param serverStatusText Resource identifier of the text to show. - * @param serverStatusIcon Resource identifier of the icon to show. ++ * */ private void showServerStatus() { if (mServerStatusIcon == 0 && mServerStatusText == 0) { @@@ -1938,17 -1891,4 +1937,17 @@@ public void doNegativeAuthenticatioDialogClick(){ mIsFirstAuthAttempt = true; } + + + @Override + public void onAuthenticatorTaskCallback(RemoteOperationResult result) { + //Log_OC.wtf(TAG, "received detection response through callback" ); + if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()). + equals(mAuthTokenType)) { + onSamlBasedFederatedSingleSignOnAuthorizationStart(result); + + } else { + onAuthorizationCheckFinish(result); + } + } }