From 3072507972f18dd273260fbeb9b660bdf251ed11 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 28 Aug 2017 08:57:08 +0200 Subject: [PATCH 1/4] Fix login loop when disabling OAuth2 --- .../android/lib/common/accounts/AccountUtils.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java index f59cfd59..46b29994 100644 --- a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -138,13 +138,13 @@ public class AccountUtils { OwnCloudCredentials credentials = null; AccountManager am = AccountManager.get(context); - boolean isOauth2 = am.getUserData( - account, - AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; + String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2); + boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE"); - boolean isSamlSso = am.getUserData( - account, - AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; + String supportsSamlSSo = am.getUserData(account, + AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO); + + boolean isSamlSso = supportsSamlSSo != null && supportsSamlSSo.equals("TRUE"); String username = AccountUtils.getUsernameForAccount(account); OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION)); From 2d35b00273486f134f3fc95fb59b9b932794c956 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 28 Aug 2017 08:58:30 +0200 Subject: [PATCH 2/4] Move constants for main endpoints from AccountUtils to OwnCloudClient --- .../owncloud/android/lib/common/OwnCloudClient.java | 10 ++++++---- .../android/lib/common/accounts/AccountUtils.java | 5 +---- .../lib/resources/status/GetRemoteStatusOperation.java | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index 60c84851..8ef9cd6e 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -58,6 +58,10 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; public class OwnCloudClient extends HttpClient { + public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; + public static final String STATUS_PATH = "/status.php"; + public static final String FILES_WEB_PATH = "/index.php/apps/files"; + private static final String TAG = OwnCloudClient.class.getSimpleName(); private static final int MAX_REDIRECTIONS_COUNT = 3; private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1; @@ -322,9 +326,7 @@ public class OwnCloudClient extends HttpClient { destination = method.getRequestHeader("destination"); } if (destination != null) { - int suffixIndex = locationStr.lastIndexOf( - AccountUtils.WEBDAV_PATH_4_0 - ); + int suffixIndex = locationStr.lastIndexOf(WEBDAV_PATH_4_0); String redirectionBase = locationStr.substring(0, suffixIndex); String destinationStr = destination.getValue(); @@ -378,7 +380,7 @@ public class OwnCloudClient extends HttpClient { } public Uri getWebdavUri() { - return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_4_0); + return Uri.parse(mBaseUri + WEBDAV_PATH_4_0); } /** diff --git a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java index 46b29994..a93ad141 100644 --- a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -51,9 +51,6 @@ public class AccountUtils { private static final String TAG = AccountUtils.class.getSimpleName(); - public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; - public static final String STATUS_PATH = "/status.php"; - /** * Constructs full url to host and webdav resource basing on host version * @@ -65,7 +62,7 @@ public class AccountUtils { public static String getWebDavUrlForAccount(Context context, Account account) throws AccountNotFoundException { - return getBaseUrlForAccount(context, account) + WEBDAV_PATH_4_0; + return getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_PATH_4_0; } diff --git a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java index 10e1f1b7..a4f32168 100644 --- a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java +++ b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java @@ -78,7 +78,7 @@ public class GetRemoteStatusOperation extends RemoteOperation { GetMethod get = null; String baseUrlSt = client.getBaseUri().toString(); try { - get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH); + get = new GetMethod(baseUrlSt + OwnCloudClient.STATUS_PATH); HttpParams params = get.getParams().getDefaultParams(); params.setParameter(HttpMethodParams.USER_AGENT, From f3a2c05efa2d2d5405e139b6bd8e8b25488e29fb Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 29 Aug 2017 10:53:28 +0200 Subject: [PATCH 3/4] Prevent NPE parsing NULL queries in OAuth2 redirected URIs --- .../oauth/OAuth2QueryParser.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2QueryParser.java b/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2QueryParser.java index 24825d2a..353cb7b5 100644 --- a/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2QueryParser.java +++ b/src/com/owncloud/android/lib/common/authentication/oauth/OAuth2QueryParser.java @@ -45,26 +45,28 @@ public class OAuth2QueryParser { public Map parse(String query) { mOAuth2ParsedAuthorizationResponse.clear(); - String[] pairs = query.split("&"); - int i = 0; - String key = ""; - String value; - while (pairs.length > i) { - int j = 0; - String[] part = pairs[i].split("="); - while (part.length > j) { - String p = part[j]; - if (j == 0) { - key = p; - } else if (j == 1) { - value = p; - mOAuth2ParsedAuthorizationResponse.put(key, value); - } + if (query != null) { + String[] pairs = query.split("&"); + int i = 0; + String key = ""; + String value; + while (pairs.length > i) { + int j = 0; + String[] part = pairs[i].split("="); + while (part.length > j) { + String p = part[j]; + if (j == 0) { + key = p; + } else if (j == 1) { + value = p; + mOAuth2ParsedAuthorizationResponse.put(key, value); + } - Log_OC.v(TAG, "[" + i + "," + j + "] = " + p); - j++; + Log_OC.v(TAG, "[" + i + "," + j + "] = " + p); + j++; + } + i++; } - i++; } return mOAuth2ParsedAuthorizationResponse; From f3892077138a931ac63514efc16d2ab8d80c7247 Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 1 Sep 2017 11:31:13 +0200 Subject: [PATCH 4/4] Update tests with the proper constants --- .../android/lib/test_project/test/OwnCloudClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java index 8210c3de..206fa0cc 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java @@ -297,7 +297,7 @@ public class OwnCloudClientTest extends AndroidTestCase { client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("user", "fakeToken")); Uri webdavUri = client.getWebdavUri(); assertTrue("WebDAV URI does not point to the right entry point", - webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0)); + webdavUri.getPath().endsWith(OwnCloudClient.WEBDAV_PATH_4_0)); assertTrue("WebDAV URI is not a subpath of base URI", webdavUri.getAuthority().equals(mServerUri.getAuthority()) && webdavUri.getPath().startsWith(mServerUri.getPath())); @@ -306,7 +306,7 @@ public class OwnCloudClientTest extends AndroidTestCase { mUsername, mPassword)); webdavUri = client.getWebdavUri(); assertTrue("WebDAV URI does not point to the right entry point", - webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0)); + webdavUri.getPath().endsWith(OwnCloudClient.WEBDAV_PATH_4_0)); PropFindMethod propfind = null; try { propfind = new PropFindMethod(webdavUri + "/",