X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/5116bd99e26954fb83621863ff26e351d0a08cfd..0b217c465dbf124c0f20b17b48d49e715e00603e:/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 8d7182d7..a7774ffc 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -18,11 +18,14 @@ 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; @@ -64,6 +67,9 @@ import com.actionbarsherlock.app.SherlockDialogFragment; 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.Constants; import com.owncloud.android.lib.common.network.CertificateCombinedException; @@ -95,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(); @@ -222,6 +229,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { 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); @@ -549,7 +558,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * 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) { @@ -878,18 +887,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } 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); } + + AuthenticatorAsyncTask asyncTask = new AuthenticatorAsyncTask(this); + String[] params = { mServerInfo.mBaseUrl, username, password, mAuthToken, mAuthTokenType}; + asyncTask.execute(params); + } /** @@ -960,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)) { @@ -1018,8 +1026,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { 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); @@ -1042,8 +1050,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /** * 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) { @@ -1353,8 +1360,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * 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) { @@ -1377,7 +1383,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { 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; @@ -1507,14 +1513,14 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { 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) { @@ -1546,9 +1552,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /** * 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) { @@ -1891,4 +1894,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); + } + } }