From: David A. Velasco Date: Thu, 11 Jun 2015 07:42:21 +0000 (+0200) Subject: Save target location of server behind a permanent redirection after password validation X-Git-Tag: oc-android-1.7.2~1^2~24^2~3 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/d4390de111d4b8007e370bd36f89dc081e7cc72f?ds=inline;hp=--cc Save target location of server behind a permanent redirection after password validation --- d4390de111d4b8007e370bd36f89dc081e7cc72f diff --git a/owncloud-android-library b/owncloud-android-library index e48aa9c3..be23f811 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit e48aa9c30447d67b0f8ee2054e1fc826108fc5ec +Subproject commit be23f8118656a84d2303a2317b60aa4fcd8afed5 diff --git a/src/com/owncloud/android/authentication/AccountUtils.java b/src/com/owncloud/android/authentication/AccountUtils.java index 1e67aa67..9afa819c 100644 --- a/src/com/owncloud/android/authentication/AccountUtils.java +++ b/src/com/owncloud/android/authentication/AccountUtils.java @@ -250,4 +250,21 @@ public class AccountUtils { } + public static String trimWebdavSuffix(String url) { + while(url.endsWith("/")) { + url = url.substring(0, url.length() - 1); + } + int pos = url.lastIndexOf(WEBDAV_PATH_4_0_AND_LATER); + if (pos >= 0) { + url = url.substring(0, pos); + + } else { + pos = url.lastIndexOf(ODAV_PATH); + if (pos >= 0) { + url = url.substring(0, pos); + } + } + return url; + } + } diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 713851ba..bf1010bc 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -785,8 +785,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity Intent getServerInfoIntent = new Intent(); getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO); getServerInfoIntent.putExtra( - OperationsService.EXTRA_SERVER_URL, - normalizeUrlSuffix(uri) + OperationsService.EXTRA_SERVER_URL, + normalizeUrlSuffix(uri) ); if (mOperationsServiceBinder != null) { mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(getServerInfoIntent); @@ -999,7 +999,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)) { @@ -1351,8 +1351,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 { @@ -1449,13 +1450,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) { @@ -1513,7 +1519,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 diff --git a/src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java b/src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java index 4b2aed50..a25ade8b 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java +++ b/src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java @@ -24,10 +24,10 @@ import android.content.Context; import android.net.Uri; import android.os.AsyncTask; -import com.owncloud.android.MainApp; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.OwnCloudCredentials; +import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; @@ -62,7 +62,6 @@ public class AuthenticatorAsyncTask extends AsyncTask