From: David A. Velasco Date: Fri, 4 Apr 2014 12:18:42 +0000 (+0200) Subject: Internal refactorization of AccountAuthenticatorActivity (and related dependencies) X-Git-Tag: oc-android-1.7.0_signed~345^2~8^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7cf05f3647abb13109cc7e11b97b536e503fc26c Internal refactorization of AccountAuthenticatorActivity (and related dependencies) --- diff --git a/res/layout-land/account_setup.xml b/res/layout-land/account_setup.xml index 4eea9b36..88b1ab3c 100644 --- a/res/layout-land/account_setup.xml +++ b/res/layout-land/account_setup.xml @@ -67,7 +67,7 @@ android:text="@string/auth_check_server" android:visibility="gone" /> 0) { url = url.trim(); if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")) { - if (mIsSslConn) { + if (sslWhenUnprefixed) { url = "https://" + url; } else { url = "http://" + url; @@ -1242,7 +1306,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mOauth2GetAccessTokenOpId = -1; dismissDialog(WAIT_DIALOG_TAG); - String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType); + String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType); if (result.isSuccess() && webdav_path != null) { /// be gentle with the user IndeterminateProgressDialog dialog = @@ -1298,13 +1362,17 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } } else if (result.isServerFail() || result.isException()) { - /// if server fail or exception in authorization, the UI is updated as when a server check failed + /// server errors or exceptions in authorization take to requiring a new check of + /// the server mServerIsChecked = true; mServerIsValid = false; - mIsSslConn = false; - mServerInfoOperation = null; - mDiscoveredVersion = null; - mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); + /* + mServerInfo.mIsSslConn = false; + mServerInfo.mVersion = null; + mServerInfo.mBaseUrl = + normalizeUrl(mHostUrlInput.getText().toString(), mServerInfo.mIsSslConn); // TODO remove? + */ + mServerInfo = new GetServerInfoOperation.ServerInfo(); // update status icon and text updateServerStatusIconAndText(result); @@ -1373,7 +1441,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType); boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType); - Uri uri = Uri.parse(mHostBaseUrl); + Uri uri = Uri.parse(mServerInfo.mBaseUrl); String username = mUsernameInput.getText().toString().trim(); if (isOAuth) { username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong(); @@ -1382,8 +1450,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { if (uri.getPort() >= 0) { accountName += ":" + uri.getPort(); } - mAccount = new Account(accountName, MainApp.getAccountType()); - if (AccountUtils.exists(mAccount, getApplicationContext())) { + Account newAccount = new Account(accountName, MainApp.getAccountType()); + if (AccountUtils.exists(newAccount, getApplicationContext())) { // fail - not a new account, but an existing one; disallow RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW); updateAuthStatusIconAndText(result); @@ -1392,7 +1460,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { return false; } else { - + mAccount = newAccount; + if (isOAuth || isSaml) { mAccountMgr.addAccountExplicitly(mAccount, "", null); // with external authorizations, the password is never input in the app } else { @@ -1420,8 +1489,8 @@ 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 - mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mDiscoveredVersion.getVersion()); - mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mHostBaseUrl); + 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"); @@ -1452,17 +1521,18 @@ 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() { - TextView tv = (TextView) findViewById(R.id.server_status_text); - if (mServerStatusIcon == 0 && mServerStatusText == 0) { - tv.setVisibility(View.INVISIBLE); + mServerStatusView.setVisibility(View.INVISIBLE); } else { - tv.setText(mServerStatusText); - tv.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0); - tv.setVisibility(View.VISIBLE); + mServerStatusView.setText(mServerStatusText); + mServerStatusView.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0); + mServerStatusView.setVisibility(View.VISIBLE); } } @@ -1474,12 +1544,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { */ private void showAuthStatus() { if (mAuthStatusIcon == 0 && mAuthStatusText == 0) { - mAuthStatusLayout.setVisibility(View.INVISIBLE); + mAuthStatusView.setVisibility(View.INVISIBLE); } else { - mAuthStatusLayout.setText(mAuthStatusText); - mAuthStatusLayout.setCompoundDrawablesWithIntrinsicBounds(mAuthStatusIcon, 0, 0, 0); - mAuthStatusLayout.setVisibility(View.VISIBLE); + mAuthStatusView.setText(mAuthStatusText); + mAuthStatusView.setCompoundDrawablesWithIntrinsicBounds(mAuthStatusIcon, 0, 0, 0); + mAuthStatusView.setVisibility(View.VISIBLE); } } @@ -1535,38 +1605,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } else { mAuthTokenType = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType()); } - adaptViewAccordingToAuthenticationMethod(); + updateAuthenticationPreFragmentVisibility(); } /** - * Changes the visibility of input elements depending on - * the current authorization method. - */ - private void adaptViewAccordingToAuthenticationMethod () { - if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) { - // OAuth 2 authorization - mOAuthAuthEndpointText.setVisibility(View.VISIBLE); - mOAuthTokenEndpointText.setVisibility(View.VISIBLE); - mUsernameInput.setVisibility(View.GONE); - mPasswordInput.setVisibility(View.GONE); - - } else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) { - // SAML-based web Single Sign On - mOAuthAuthEndpointText.setVisibility(View.GONE); - mOAuthTokenEndpointText.setVisibility(View.GONE); - mUsernameInput.setVisibility(View.GONE); - mPasswordInput.setVisibility(View.GONE); - } else { - // basic HTTP authorization - mOAuthAuthEndpointText.setVisibility(View.GONE); - mOAuthTokenEndpointText.setVisibility(View.GONE); - mUsernameInput.setVisibility(View.VISIBLE); - mPasswordInput.setVisibility(View.VISIBLE); - } - } - - /** * Called when the 'action' button in an IME is pressed ('enter' in software keyboard). * * Used to trigger the authentication check when the user presses 'enter' after writing the password, @@ -1621,21 +1664,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } - public void onSamlDialogSuccess(String sessionCookie) { - mAuthToken = sessionCookie; - - if (sessionCookie != null && sessionCookie.length() > 0) { - mAuthToken = sessionCookie; - boolean followRedirects = true; - getRemoteUserNameOperation(sessionCookie, followRedirects); - } - } - private void getRemoteUserNameOperation(String sessionCookie, boolean followRedirects) { Intent getUserNameIntent = new Intent(); getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME); - getUserNameIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl); + getUserNameIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl); getUserNameIntent.putExtra(OperationsService.EXTRA_COOKIE, sessionCookie); getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects); @@ -1647,10 +1680,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { @Override - public void onSsoFinished(String sessionCookies) { - if (sessionCookies != null && sessionCookies.length() > 0) { + public void onSsoFinished(String sessionCookie) { + if (sessionCookie != null && sessionCookie.length() > 0) { Log_OC.d(TAG, "Successful SSO - time to save the account"); - onSamlDialogSuccess(sessionCookies); + mAuthToken = sessionCookie; + getRemoteUserNameOperation(sessionCookie, true); Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG); if (fd != null && fd instanceof SherlockDialogFragment) { Dialog d = ((SherlockDialogFragment)fd).getDialog(); @@ -1666,19 +1700,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } - /** Show auth_message - * - * @param message - */ - private void showAuthMessage(String message) { - mAuthMessage.setVisibility(View.VISIBLE); - mAuthMessage.setText(message); - } - - private void hideAuthMessage() { - mAuthMessage.setVisibility(View.GONE); - } - @Override public boolean onTouchEvent(MotionEvent event) { if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType) && @@ -1703,19 +1724,19 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.addToBackStack(null); - dialog.show(ft, DIALOG_UNTRUSTED_CERT); + dialog.show(ft, UNTRUSTED_CERT_DIALOG_TAG); } /** * Show untrusted cert dialog */ - public void showUntrustedCertDialog(RemoteOperationResult result) { + private void showUntrustedCertDialog(RemoteOperationResult result) { // Show a dialog with the certificate info SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstanceForFullSslError((CertificateCombinedException)result.getException()); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.addToBackStack(null); - dialog.show(ft, DIALOG_UNTRUSTED_CERT); + dialog.show(ft, UNTRUSTED_CERT_DIALOG_TAG); } @@ -1750,6 +1771,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { //Log.wtf(TAG, "registering to listen for operation callbacks" ); mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler); + + if (mGetServerInfoOpId != -1) { RemoteOperationResult result = mOperationsServiceBinder.getOperationResultIfFinished(mGetServerInfoOpId); diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 2645511b..461283ff 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -478,8 +478,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis // let the user update credentials with one click Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class); updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, download.getAccount()); - updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ENFORCED_UPDATE, true); - updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_TOKEN); + updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND); diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 9d2b4fa8..d302e267 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -785,8 +785,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe // let the user update credentials with one click Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class); updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount()); - updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ENFORCED_UPDATE, true); - updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_TOKEN); + updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND); diff --git a/src/com/owncloud/android/operations/GetServerInfoOperation.java b/src/com/owncloud/android/operations/GetServerInfoOperation.java index c210153e..14f405ea 100644 --- a/src/com/owncloud/android/operations/GetServerInfoOperation.java +++ b/src/com/owncloud/android/operations/GetServerInfoOperation.java @@ -93,8 +93,8 @@ public class GetServerInfoOperation extends RemoteOperation { if (result.isSuccess()) { // second: get authentication method required by the server mResultData.mVersion = (OwnCloudVersion)(result.getData().get(0)); - boolean isSslConn = (result.getCode() == ResultCode.OK_SSL); - mResultData.mBaseUrl = normalizeProtocolPrefix(mUrl, isSslConn); + mResultData.mIsSslConn = (result.getCode() == ResultCode.OK_SSL); + mResultData.mBaseUrl = normalizeProtocolPrefix(mUrl, mResultData.mIsSslConn); RemoteOperationResult detectAuthResult = detectAuthorizationMethod(client); // third: merge results @@ -155,9 +155,10 @@ public class GetServerInfoOperation extends RemoteOperation { public static class ServerInfo { - public OwnCloudVersion mVersion; - public String mBaseUrl; - public AuthenticationMethod mAuthMethod; + public OwnCloudVersion mVersion = null; + public String mBaseUrl = ""; + public AuthenticationMethod mAuthMethod = AuthenticationMethod.UNKNOWN; + public boolean mIsSslConn = false; } } diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index a3394e61..407ce1a2 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java @@ -397,8 +397,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { // let the user update credentials with one click Intent updateAccountCredentials = new Intent(getContext(), AuthenticatorActivity.class); updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount()); - updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ENFORCED_UPDATE, true); - updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_TOKEN); + updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);