X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/a496f0871713084015aae8e36b7093671907146a..dbe0ff54aedb6eab3e9c596f48fc816ef7ee43e8:/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 d5ba29fa..b7ec1c65 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -23,9 +23,6 @@ package com.owncloud.android.authentication; -import java.security.cert.X509Certificate; -import java.util.Map; - import android.accounts.Account; import android.accounts.AccountManager; import android.app.Dialog; @@ -54,7 +51,6 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnFocusChangeListener; import android.view.View.OnTouchListener; -import android.view.Window; import android.view.inputmethod.EditorInfo; import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; @@ -94,6 +90,9 @@ import com.owncloud.android.ui.dialog.SslUntrustedCertDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener; import com.owncloud.android.utils.DisplayUtils; +import java.security.cert.X509Certificate; +import java.util.Map; + /** * This Activity is used to add an ownCloud account to the App */ @@ -206,7 +205,16 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity protected void onCreate(Bundle savedInstanceState) { //Log_OC.wtf(TAG, "onCreate init"); super.onCreate(savedInstanceState); + + // Workaround, for fixing a problem with Android Library Suppor v7 19 //getWindow().requestFeature(Window.FEATURE_NO_TITLE); + if (getSupportActionBar() != null) { + getSupportActionBar().hide(); + + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + getSupportActionBar().setDisplayShowHomeEnabled(false); + getSupportActionBar().setDisplayShowTitleEnabled(false); + } mIsFirstAuthAttempt = true; @@ -339,11 +347,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (mAccount != null) { mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL); // TODO do next in a setter for mBaseUrl - mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); - String ocVersion = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION); - if (ocVersion != null) { - mServerInfo.mVersion = new OwnCloudVersion(ocVersion); - } + mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); + mServerInfo.mVersion = AccountUtils.getServerVersion(mAccount); } else { mServerInfo.mBaseUrl = getString(R.string.server_url).trim(); mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); @@ -561,7 +566,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * intended to defer the processing of the redirection caught in * {@link #onNewIntent(Intent)} until {@link #onResume()} * - * See {@link #onSaveInstanceState(Bundle)} + * See {@link super#onSaveInstanceState(Bundle)} */ @Override protected void onSaveInstanceState(Bundle outState) { @@ -787,7 +792,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity Intent getServerInfoIntent = new Intent(); getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO); getServerInfoIntent.putExtra( - OperationsService.EXTRA_SERVER_URL, + OperationsService.EXTRA_SERVER_URL, normalizeUrlSuffix(uri) ); if (mOperationsServiceBinder != null) { @@ -1002,7 +1007,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if ( mAction == ACTION_CREATE) { mUsernameInput.setText(username); - success = createAccount(); + success = createAccount(result); } else { if (!mUsernameInput.getText().toString().equals(username)) { @@ -1106,7 +1111,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity url = "http://" + url; } } - + url = normalizeUrlSuffix(url); } return (url != null ? url : ""); @@ -1127,7 +1132,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0_AND_LATER)){ url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0_AND_LATER.length()); } - return (url != null ? url : ""); + return url; } @@ -1141,7 +1146,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity switch (result.getCode()) { case OK_SSL: - mServerStatusIcon = android.R.drawable.ic_secure; + mServerStatusIcon = R.drawable.ic_lock; mServerStatusText = R.string.auth_secure_connection; break; @@ -1152,7 +1157,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mServerStatusIcon = R.drawable.ic_ok; } else { mServerStatusText = R.string.auth_nossl_plain_ok_title; - mServerStatusIcon = android.R.drawable.ic_partial_secure; + mServerStatusIcon = R.drawable.ic_lock_open; } break; @@ -1202,7 +1207,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mServerStatusText = R.string.auth_unknown_error_title; break; case OK_REDIRECT_TO_NON_SECURE_CONNECTION: - mServerStatusIcon = android.R.drawable.ic_partial_secure; + mServerStatusIcon = R.drawable.ic_lock_open; mServerStatusText = R.string.auth_redirect_non_secure_connection_title; break; default: @@ -1222,7 +1227,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity switch (result.getCode()) { case OK_SSL: - mAuthStatusIcon = android.R.drawable.ic_secure; + mAuthStatusIcon = R.drawable.ic_lock; mAuthStatusText = R.string.auth_secure_connection; break; @@ -1233,7 +1238,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mAuthStatusIcon = R.drawable.ic_ok; } else { mAuthStatusText = R.string.auth_nossl_plain_ok_title; - mAuthStatusIcon = android.R.drawable.ic_partial_secure; + mAuthStatusIcon = R.drawable.ic_lock_open; } break; @@ -1356,8 +1361,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity Log_OC.d(TAG, "Successful access - time to save the account"); boolean success = false; + if (mAction == ACTION_CREATE) { - success = createAccount(); + success = createAccount(result); } else { try { @@ -1425,7 +1431,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type); if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()). - equals(mAuthTokenType)) { + equals(mAuthTokenType)) { response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken); // the next line is necessary, notifications are calling directly to the // AuthenticatorActivity to update, without AccountManager intervention @@ -1455,13 +1461,18 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * * TODO Decide how to name the OAuth accounts */ - private boolean createAccount() { + private boolean createAccount(RemoteOperationResult authResult) { /// create and save new ownCloud account boolean isOAuth = AccountTypeUtils. getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType); boolean isSaml = AccountTypeUtils. getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType); + String lastPermanentLocation = authResult.getLastPermanentLocation(); + if (lastPermanentLocation != null) { + mServerInfo.mBaseUrl = AccountUtils.trimWebdavSuffix(lastPermanentLocation); + } + Uri uri = Uri.parse(mServerInfo.mBaseUrl); String username = mUsernameInput.getText().toString().trim(); if (isOAuth) { @@ -1519,7 +1530,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// 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, mServerInfo.mVersion.getVersion() + mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion() ); mAccountMgr.setUserData( mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl @@ -1702,7 +1713,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } - private void getRemoteUserNameOperation(String sessionCookie, boolean followRedirects) { + private void getRemoteUserNameOperation(String sessionCookie) { Intent getUserNameIntent = new Intent(); getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME); @@ -1720,7 +1731,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (sessionCookie != null && sessionCookie.length() > 0) { Log_OC.d(TAG, "Successful SSO - time to save the account"); mAuthToken = sessionCookie; - getRemoteUserNameOperation(sessionCookie, true); + getRemoteUserNameOperation(sessionCookie); Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG); if (fd != null && fd instanceof DialogFragment) { Dialog d = ((DialogFragment)fd).getDialog(); @@ -1754,7 +1765,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity X509Certificate x509Certificate, SslError error, SslErrorHandler handler ) { // Show a dialog with the certificate info - SslUntrustedCertDialog dialog = null; + SslUntrustedCertDialog dialog; if (x509Certificate == null) { dialog = SslUntrustedCertDialog.newInstanceForEmptySslError(error, handler); } else { @@ -1846,8 +1857,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity doOnResumeAndBound(); - } else { - return; } } @@ -1866,8 +1875,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /** * Create and show dialog for request authentication to the user - * @param webView - * @param handler + * @param webView Web view to emebd into the authentication dialog. + * @param handler Object responsible for catching and recovering HTTP authentication fails. */ public void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) { @@ -1898,5 +1907,4 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mIsFirstAuthAttempt = true; } - }