X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/7cf05f3647abb13109cc7e11b97b536e503fc26c..aa354e5d73d2e1777b93e957220990d145f3b6ba:/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 99e114d5..d88b8dc2 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -50,7 +50,9 @@ 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; +import android.webkit.WebView; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; @@ -64,26 +66,25 @@ import com.owncloud.android.R; import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; -import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod; -import com.owncloud.android.operations.GetServerInfoOperation; -import com.owncloud.android.operations.OAuth2GetAccessToken; - import com.owncloud.android.lib.common.network.CertificateCombinedException; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation; - +import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod; +import com.owncloud.android.operations.GetServerInfoOperation; +import com.owncloud.android.operations.OAuth2GetAccessToken; import com.owncloud.android.services.OperationsService; import com.owncloud.android.services.OperationsService.OperationsServiceBinder; +import com.owncloud.android.ui.dialog.CredentialsDialogFragment; import com.owncloud.android.ui.dialog.IndeterminateProgressDialog; import com.owncloud.android.ui.dialog.SamlWebViewDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener; -import com.owncloud.android.utils.Log_OC; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; /** * This Activity is used to add an ownCloud account to the App @@ -113,12 +114,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private static final String KEY_PASSWORD_EXPOSED = "PASSWORD_VISIBLE"; private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT"; private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON"; - private static final String KEY_REFRESH_BUTTON_ENABLED = "REFRESH_BUTTON_ENABLED"; private static final String KEY_SERVER_AUTH_METHOD = "SERVER_AUTH_METHOD"; - private static final String KEY_GET_SERVER_INFO_OP_ID = "DETECT_AUTH_OP_ID"; - private static final String KEY_EXISTENCE_CHECK_OP_ID = "EXISTENCE_CHECK_OP_ID"; - private static final String KEY_OAUTH2_GET_ACCESS_TOKEN_OP_ID = "OAUTH2_GET_ACCESS_TOKEN"; - private static final String KEY_GET_USER_NAME_OP_ID = "GET_USER_NAME"; + private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID"; private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN"; private static final String AUTH_ON = "on"; @@ -131,6 +128,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private static final String UNTRUSTED_CERT_DIALOG_TAG = "UNTRUSTED_CERT_DIALOG"; private static final String SAML_DIALOG_TAG = "SAML_DIALOG"; private static final String WAIT_DIALOG_TAG = "WAIT_DIALOG"; + private static final String CREDENTIALS_DIALOG_TAG = "CREDENTIALS_DIALOG"; + private static final String KEY_AUTH_IS_FIRST_ATTEMPT_TAG = "KEY_AUTH_IS_FIRST_ATTEMPT"; /// parameters from EXTRAs in starter Intent @@ -157,6 +156,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private boolean mServerIsChecked = false; private boolean mServerIsValid = false; + private boolean mPendingAutoCheck = false; private GetServerInfoOperation.ServerInfo mServerInfo = new GetServerInfoOperation.ServerInfo(); @@ -175,13 +175,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private String mAuthToken = ""; + private boolean mIsFirstAuthAttempt; + - /// Operation-in-progress identifiers - TODO improve pull-interface with OperationsService - private int mGetServerInfoOpId = -1; - private int mOauth2GetAccessTokenOpId = -1; - private int mExistenceCheckOpId = -1; - private int mGetUserNameOpId = -1; - + /// Identifier of operation in progress which result shouldn't be lost + private long mWaitingForOpId = Long.MAX_VALUE; + /** * {@inheritDoc} @@ -190,10 +189,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { */ @Override protected void onCreate(Bundle savedInstanceState) { - Log_OC.wtf(TAG, "onCreate init"); + //Log_OC.wtf(TAG, "onCreate init"); super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); + mIsFirstAuthAttempt = true; + // bind to Operations Service mOperationsServiceConnection = new OperationsServiceConnection(); if (!bindService(new Intent(this, OperationsService.class), @@ -217,6 +218,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { initAuthTokenType(); } else { mAuthTokenType = savedInstanceState.getString(KEY_AUTH_TOKEN_TYPE); + mWaitingForOpId = savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID); + mIsFirstAuthAttempt = savedInstanceState.getBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG); } /// load user interface @@ -225,13 +228,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /// initialize general UI elements initOverallUi(savedInstanceState); + mOkButton = findViewById(R.id.buttonOK); + /// initialize block to be moved to single Fragment to check server and get info about it initServerPreFragment(savedInstanceState); /// initialize block to be moved to single Fragment to retrieve and validate credentials initAuthorizationPreFragment(savedInstanceState); - Log_OC.wtf(TAG, "onCreate end"); + //Log_OC.wtf(TAG, "onCreate end"); } private void initAuthTokenType() { @@ -313,7 +318,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState) boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input); - //boolean refreshButtonEnabled = false; if (savedInstanceState == null) { if (mAccount != null) { mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL); @@ -327,7 +331,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); } } else { - //refreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED); mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT); mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON); @@ -344,9 +347,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mServerInfo.mAuthMethod = AuthenticationMethod.valueOf( savedInstanceState.getString(KEY_SERVER_AUTH_METHOD)); - // TODO save and recover any operation in progress, in a reasonable way - mGetServerInfoOpId = savedInstanceState.getInt(KEY_GET_SERVER_INFO_OP_ID); - } /// step 2 - set properties of UI elements (text, visibility, enabled...) @@ -363,7 +363,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { findViewById(R.id.hostUrlFrame).setVisibility(View.GONE); mRefreshButton = findViewById(R.id.centeredRefreshButton); } - showRefreshButton(mServerIsChecked && !mServerIsValid && mGetServerInfoOpId == -1); + showRefreshButton(mServerIsChecked && !mServerIsValid && + mWaitingForOpId > Integer.MAX_VALUE); mServerStatusView = (TextView) findViewById(R.id.server_status_text); showServerStatus(); @@ -414,12 +415,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { }); - /// step 4 - automatic actions to start - if (savedInstanceState == null) { - if (mAction != ACTION_CREATE || !isUrlInputAllowed) { - checkOcServer(); - } - } + /// step 4 - mark automatic check to be started when OperationsService is ready + mPendingAutoCheck = (savedInstanceState == null && + (mAction != ACTION_CREATE || !isUrlInputAllowed)); } @@ -436,7 +434,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mUsernameInput = (EditText) findViewById(R.id.account_username); mPasswordInput = (EditText) findViewById(R.id.account_password); mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); - mOkButton = findViewById(R.id.buttonOK); /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState) String presetUserName = null; @@ -451,9 +448,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mAuthStatusText = savedInstanceState.getInt(KEY_AUTH_STATUS_TEXT); mAuthStatusIcon = savedInstanceState.getInt(KEY_AUTH_STATUS_ICON); mAuthToken = savedInstanceState.getString(KEY_AUTH_TOKEN); - mExistenceCheckOpId = savedInstanceState.getInt(KEY_EXISTENCE_CHECK_OP_ID); - mOauth2GetAccessTokenOpId = savedInstanceState.getInt(KEY_OAUTH2_GET_ACCESS_TOKEN_OP_ID); - mGetUserNameOpId = savedInstanceState.getInt(KEY_GET_USER_NAME_OP_ID); } /// step 2 - set properties of UI elements (text, visibility, enabled...) @@ -547,19 +541,17 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { */ @Override protected void onSaveInstanceState(Bundle outState) { - //Log.wtf(TAG, "onSaveInstanceState init" ); + //Log_OC.wtf(TAG, "onSaveInstanceState init" ); super.onSaveInstanceState(outState); /// global state outState.putString(KEY_AUTH_TOKEN_TYPE, mAuthTokenType); + outState.putLong(KEY_WAITING_FOR_OP_ID, mWaitingForOpId); /// Server PRE-fragment state - //outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE)); outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText); outState.putInt(KEY_SERVER_STATUS_ICON, mServerStatusIcon); outState.putBoolean(KEY_SERVER_CHECKED, mServerIsChecked); - //outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerIsValid && mServerInfoOperation != null)); - outState.putInt(KEY_GET_SERVER_INFO_OP_ID, mGetServerInfoOpId); outState.putBoolean(KEY_SERVER_VALID, mServerIsValid); outState.putBoolean(KEY_IS_SSL_CONN, mServerInfo.mIsSslConn); outState.putString(KEY_HOST_URL_TEXT, mServerInfo.mBaseUrl); @@ -573,11 +565,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon); outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText); outState.putString(KEY_AUTH_TOKEN, mAuthToken); - outState.putInt(KEY_EXISTENCE_CHECK_OP_ID, mExistenceCheckOpId); - outState.putInt(KEY_OAUTH2_GET_ACCESS_TOKEN_OP_ID, mOauth2GetAccessTokenOpId); - outState.putInt(KEY_GET_USER_NAME_OP_ID, mGetUserNameOpId); - //Log.wtf(TAG, "onSaveInstanceState end" ); + /// authentication + outState.putBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG, mIsFirstAuthAttempt); + + //Log_OC.wtf(TAG, "onSaveInstanceState end" ); } @@ -604,7 +596,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { */ @Override protected void onResume() { - Log_OC.wtf(TAG, "onResume init" ); + //Log_OC.wtf(TAG, "onResume init" ); super.onResume(); // bound here to avoid spurious changes triggered by Android on device rotations @@ -619,15 +611,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { doOnResumeAndBound(); } - Log_OC.wtf(TAG, "onResume end" ); + //Log_OC.wtf(TAG, "onResume end" ); } @Override protected void onPause() { - //Log.wtf(TAG, "onPause init" ); + //Log_OC.wtf(TAG, "onPause init" ); if (mOperationsServiceBinder != null) { - //Log.wtf(TAG, "unregistering to listen for operation callbacks" ); + //Log_OC.wtf(TAG, "unregistering to listen for operation callbacks" ); mOperationsServiceBinder.removeOperationListener(this); } @@ -635,7 +627,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mHostUrlInput.setOnFocusChangeListener(null); super.onPause(); - //Log.wtf(TAG, "onPause end" ); + //Log_OC.wtf(TAG, "onPause end" ); } @Override @@ -678,8 +670,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { queryParameters); if (mOperationsServiceBinder != null) { - //Log.wtf(TAG, "getting access token..." ); - mOauth2GetAccessTokenOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent); + //Log_OC.wtf(TAG, "getting access token..." ); + mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent); } } @@ -742,10 +734,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { Intent getServerInfoIntent = new Intent(); getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO); getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri); - getServerInfoIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN_TYPE, mAuthTokenType); if (mOperationsServiceBinder != null) { - //Log.wtf(TAG, "checking server..." ); - mGetServerInfoOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent); + mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent); + } else { + Log_OC.wtf(TAG, "Server check tried with OperationService unbound!" ); } } else { @@ -777,10 +769,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private void showViewPasswordButton() { - //int drawable = android.R.drawable.ic_menu_view; int drawable = R.drawable.ic_view; if (isPasswordVisible()) { - //drawable = android.R.drawable.ic_secure; drawable = R.drawable.ic_hide; } mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0); @@ -828,7 +818,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mServerStatusText = R.string.auth_wtf_reenter_URL; showServerStatus(); mOkButton.setEnabled(false); - Log_OC.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!"); + //Log_OC.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!"); return; } @@ -847,9 +837,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * the root folder of the ownCloud server. */ private void checkBasicAuthorization() { - /// get the path to the root folder through WebDAV from the version server - String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType); - /// get basic credentials entered by user String username = mUsernameInput.getText().toString(); String password = mPasswordInput.getText().toString(); @@ -859,30 +846,23 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true); dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG); - /// test credentials accessing the root folder - String remotePath =""; - boolean successIfAbsent = false; - boolean followRedirects = true; - startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, username, password, followRedirects); + /// validate credentials accessing the root folder + accessRootFolderRemoteOperation(username, password); } - private void startExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent, String webdav_path, - String username, String password, boolean followRedirects) { + 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, remotePath); - existenceCheckIntent.putExtra(OperationsService.EXTRA_SUCCESS_IF_ABSENT, successIfAbsent); - existenceCheckIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path); + 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); - existenceCheckIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects); if (mOperationsServiceBinder != null) { - Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." ); - mExistenceCheckOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent); + //Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." ); + mWaitingForOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent); } } @@ -897,14 +877,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { showAuthStatus(); // GET AUTHORIZATION request - //Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth)); Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim()); Uri.Builder uriBuilder = uri.buildUpon(); uriBuilder.appendQueryParameter(OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type)); uriBuilder.appendQueryParameter(OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri)); uriBuilder.appendQueryParameter(OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id)); uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope)); - //uriBuilder.appendQueryParameter(OAuth2Constants.KEY_STATE, whateverwewant); uri = uriBuilder.build(); Log_OC.d(TAG, "Starting browser to view " + uri.toString()); Intent i = new Intent(Intent.ACTION_VIEW, uri); @@ -925,14 +903,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true); dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG); - /// get the path to the root folder through WebDAV from the version server - String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType); - - /// test credentials accessing the root folder - String remotePath =""; - boolean successIfAbsent = false; - boolean followRedirections = false; - startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirections); + /// validate credentials accessing the root folder + accessRootFolderRemoteOperation("", ""); } @@ -945,7 +917,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { if (operation instanceof GetServerInfoOperation) { - if (operation.hashCode() == mGetServerInfoOpId) { + if (operation.hashCode() == mWaitingForOpId) { onGetServerInfoFinish(result); } // else nothing ; only the last check operation is considered; // multiple can be started if the user amends a URL quickly @@ -954,7 +926,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { onGetOAuthAccessTokenFinish(result); } else if (operation instanceof ExistenceCheckRemoteOperation) { - Log_OC.wtf(TAG, "received detection response through callback" ); + //Log_OC.wtf(TAG, "received detection response through callback" ); if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) { onSamlBasedFederatedSingleSignOnAuthorizationStart(result); @@ -968,7 +940,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } private void onGetUserNameFinish(RemoteOperationResult result) { - mGetUserNameOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; if (result.isSuccess()) { boolean success = false; String username = (String) result.getData().get(0); @@ -980,7 +952,15 @@ 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); + 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()); @@ -1001,10 +981,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result) { - mExistenceCheckOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); - //if (result.isTemporalRedirection() && result.isIdPRedirection()) { if (result.isIdPRedirection()) { String url = result.getRedirectedLocation(); String targetUrl = mServerInfo.mBaseUrl @@ -1036,7 +1015,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private void onGetServerInfoFinish(RemoteOperationResult result) { /// update activity state mServerIsChecked = true; - mGetServerInfoOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; // update server status, but don't show it yet updateServerStatusIconAndText(result); @@ -1196,6 +1175,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { case UNKNOWN_ERROR: mServerStatusText = R.string.auth_unknown_error_title; break; + case OK_REDIRECT_TO_NON_SECURE_CONNECTION: + mServerStatusIcon = android.R.drawable.ic_partial_secure; + mServerStatusText = R.string.auth_redirect_non_secure_connection_title; + break; default: mServerStatusText = 0; mServerStatusIcon = 0; @@ -1303,11 +1286,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * @param result Result of the operation. */ private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) { - mOauth2GetAccessTokenOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); - String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType); - if (result.isSuccess() && webdav_path != null) { + if (result.isSuccess()) { /// be gentle with the user IndeterminateProgressDialog dialog = IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true); @@ -1320,10 +1302,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { //mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN); Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken); - String remotePath =""; - boolean successIfAbsent = false; - boolean followRedirects = true; - startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirects); + accessRootFolderRemoteOperation("", ""); } else { updateAuthStatusIconAndText(result); @@ -1342,7 +1321,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * @param result Result of the operation. */ private void onAuthorizationCheckFinish(RemoteOperationResult result) { - mExistenceCheckOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); if (result.isSuccess()) { @@ -1366,12 +1345,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /// the server mServerIsChecked = true; mServerIsValid = false; - /* - 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 @@ -1445,11 +1418,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { String username = mUsernameInput.getText().toString().trim(); if (isOAuth) { username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong(); - } - String accountName = username + "@" + uri.getHost(); - if (uri.getPort() >= 0) { - accountName += ":" + uri.getPort(); } + String accountName = com.owncloud.android.lib.common.accounts.AccountUtils. + buildAccountName(uri, username); Account newAccount = new Account(accountName, MainApp.getAccountType()); if (AccountUtils.exists(newAccount, getApplicationContext())) { // fail - not a new account, but an existing one; disallow @@ -1670,11 +1641,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME); getUserNameIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl); getUserNameIntent.putExtra(OperationsService.EXTRA_COOKIE, sessionCookie); - getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects); if (mOperationsServiceBinder != null) { //Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." ); - mGetUserNameOpId = mOperationsServiceBinder.newOperation(getUserNameIntent); + mWaitingForOpId = mOperationsServiceBinder.newOperation(getUserNameIntent); } } @@ -1727,6 +1697,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { dialog.show(ft, UNTRUSTED_CERT_DIALOG_TAG); } + /** * Show untrusted cert dialog */ @@ -1768,51 +1739,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private void doOnResumeAndBound() { - //Log.wtf(TAG, "registering to listen for operation callbacks" ); + //Log_OC.wtf(TAG, "registering to listen for operation callbacks" ); mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler); + if (mWaitingForOpId <= Integer.MAX_VALUE) { + mOperationsServiceBinder.dispatchResultIfFinished((int)mWaitingForOpId, this); + } - - - if (mGetServerInfoOpId != -1) { - RemoteOperationResult result = - mOperationsServiceBinder.getOperationResultIfFinished(mGetServerInfoOpId); - if (result != null) { - //Log_OC.wtf(TAG, "found result of operation finished while rotating"); - onGetServerInfoFinish(result); - } - - } else if (mOauth2GetAccessTokenOpId != -1) { - RemoteOperationResult result = - mOperationsServiceBinder.getOperationResultIfFinished( - mOauth2GetAccessTokenOpId); - if (result != null) { - //Log_OC.wtf(TAG, "found result of operation finished while rotating"); - onGetOAuthAccessTokenFinish(result); - } - - } else if (mExistenceCheckOpId != -1) { - RemoteOperationResult result = - mOperationsServiceBinder.getOperationResultIfFinished(mExistenceCheckOpId); - if (result != null) { - //Log_OC.wtf(TAG, "found result of operation finished while rotating"); - if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie( - MainApp.getAccountType()).equals(mAuthTokenType)) { - onSamlBasedFederatedSingleSignOnAuthorizationStart(result); - - } else { - onAuthorizationCheckFinish(result); - } - } - }if (mGetUserNameOpId != -1) { - RemoteOperationResult result = - mOperationsServiceBinder.getOperationResultIfFinished(mGetUserNameOpId); - if (result != null) { - //Log_OC.wtf(TAG, "found result of operation finished while rotating"); - onGetUserNameFinish(result); - } - - } - + if (mPendingAutoCheck) { + checkOcServer(); + } } @@ -1853,5 +1788,33 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } } - + + /** + * Create and show dialog for request authentication to the user + * @param webView + * @param handler + */ + public void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) { + + // Show a dialog with the certificate info + CredentialsDialogFragment dialog = CredentialsDialogFragment.newInstanceForCredentials(webView, handler); + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction ft = fm.beginTransaction(); + ft.addToBackStack(null); + dialog.setCancelable(false); + dialog.show(ft, CREDENTIALS_DIALOG_TAG); + + if (!mIsFirstAuthAttempt) { + Toast.makeText(getApplicationContext(), getText(R.string.saml_authentication_wrong_pass), Toast.LENGTH_LONG).show(); + } else { + mIsFirstAuthAttempt = false; + } + } + + /** + * For retrieving the clicking on authentication cancel button + */ + public void doNegativeAuthenticatioDialogClick(){ + mIsFirstAuthAttempt = true; + } }