X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/3605bd70da54e8375387ce0c6be4654c768c7c45..b5d70ad8e793f27324aeb3af6597dd51a3a051ee:/src/com/owncloud/android/authentication/AuthenticatorActivity.java diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 3a640765..0c735401 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -68,9 +68,9 @@ 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.OwnCloudClient; 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; @@ -101,8 +101,9 @@ import com.owncloud.android.utils.DisplayUtils; * @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(); @@ -892,18 +893,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mAccountMgr.setUserData(mAccount, Constants.KEY_COOKIES, null); } - 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); - } + AuthenticatorAsyncTask asyncTask = new AuthenticatorAsyncTask(this); + String[] params = { mServerInfo.mBaseUrl, username, password, mAuthToken, mAuthTokenType}; + asyncTask.execute(params); + } /** @@ -974,6 +967,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { 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)) { @@ -1002,20 +996,20 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { 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(); + } } } @@ -1381,8 +1375,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { 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) { @@ -1423,10 +1424,20 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /** - * 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); @@ -1900,4 +1911,17 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { 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); + } + } }