From 3b0128d7ae78ba370bad5023080bd7bb8e989594 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 3 Jul 2019 17:20:57 +0200 Subject: [PATCH 1/7] Make some classes opened for testing --- owncloudComLibrary/build.gradle | 1 - .../android/lib/resources/shares/CreateRemoteShareOperation.kt | 2 ++ .../lib/resources/shares/GetRemoteSharesForFileOperation.kt | 2 ++ .../android/lib/resources/shares/RemoveRemoteShareOperation.kt | 2 ++ .../android/lib/resources/shares/UpdateRemoteShareOperation.kt | 3 ++- .../lib/resources/status/GetRemoteCapabilitiesOperation.kt | 2 ++ 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index c64e959f0..2a9ed22fb 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -1,7 +1,6 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' - apply plugin: 'kotlin-allopen' dependencies { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt index b7080c4d6..72a242b16 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt @@ -34,6 +34,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_EXPIRATION_DATE_IN_MILLIS +import com.owncloud.android.lib.testing.OpenForTesting import okhttp3.FormBody import java.net.URL import java.text.SimpleDateFormat @@ -65,6 +66,7 @@ import java.util.Locale * To obtain combinations, add the desired values together. * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. */ +@OpenForTesting class CreateRemoteShareOperation( private val remoteFilePath: String, private val shareType: ShareType, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt index 321f170b2..26d4c52ff 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt @@ -33,6 +33,7 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.testing.OpenForTesting import java.net.URL /** @@ -55,6 +56,7 @@ import java.net.URL * @param subfiles If set to false (default), lists only the folder being shared * If set to true, all shared files within the folder are returned. */ +@OpenForTesting class GetRemoteSharesForFileOperation( private val remoteFilePath: String, private val reshares: Boolean, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt index d4deda06d..0bb53a74a 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt @@ -33,6 +33,7 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.testing.OpenForTesting import java.net.URL /** @@ -48,6 +49,7 @@ import java.net.URL * * @param remoteShareId Share ID */ +@OpenForTesting class RemoveRemoteShareOperation(private val remoteShareId: Long) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt index 49f38e653..6196c458a 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt @@ -32,6 +32,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.DEFAULT_PERMISSION +import com.owncloud.android.lib.testing.OpenForTesting import okhttp3.FormBody import java.net.URL import java.text.SimpleDateFormat @@ -47,7 +48,7 @@ import java.util.Locale * @author David A. Velasco * @author David González Verdugo */ - +@OpenForTesting class UpdateRemoteShareOperation /** * Constructor. No update is initialized by default, need to be applied with setters below. diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index 8bce27ef8..9cfc9839c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -34,6 +34,7 @@ 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.OK import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.lib.testing.OpenForTesting import org.json.JSONObject import java.net.URL @@ -47,6 +48,7 @@ import java.net.URL /** * Constructor */ +@OpenForTesting class GetRemoteCapabilitiesOperation : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { From ad8fc8e02c3c940849f2de34e8dbe016095c67e8 Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 5 Jul 2019 10:31:10 +0200 Subject: [PATCH 2/7] Remove OpenForTesting, no longer needed since mockk is used --- .../android/lib/testing/OpenForTesting.kt | 31 ------------------- .../shares/CreateRemoteShareOperation.kt | 2 -- .../shares/GetRemoteShareesOperation.kt | 7 +---- .../shares/GetRemoteSharesForFileOperation.kt | 2 -- .../shares/RemoveRemoteShareOperation.kt | 2 -- .../shares/UpdateRemoteShareOperation.kt | 2 -- .../status/GetRemoteCapabilitiesOperation.kt | 2 -- .../lib/resources/status/OwnCloudVersion.kt | 2 -- .../android/lib/testing/OpenForTesting.kt | 31 ------------------- 9 files changed, 1 insertion(+), 80 deletions(-) delete mode 100644 owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt delete mode 100644 owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt diff --git a/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt b/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt deleted file mode 100644 index 3c91e8361..000000000 --- a/owncloudComLibrary/src/debug/java/com/owncloud/android/lib/testing/OpenForTesting.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.owncloud.android.lib.testing - -/** - * This annotation allows us to open some classes for mocking purposes while they are final in - * release builds. - */ -@Target(AnnotationTarget.ANNOTATION_CLASS) -annotation class OpenClass - -/** - * Annotate a class with [OpenForTesting] if you want it to be extendable in debug builds. - */ -@OpenClass -@Target(AnnotationTarget.CLASS) -annotation class OpenForTesting diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt index 72a242b16..b7080c4d6 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt @@ -34,7 +34,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_EXPIRATION_DATE_IN_MILLIS -import com.owncloud.android.lib.testing.OpenForTesting import okhttp3.FormBody import java.net.URL import java.text.SimpleDateFormat @@ -66,7 +65,6 @@ import java.util.Locale * To obtain combinations, add the desired values together. * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. */ -@OpenForTesting class CreateRemoteShareOperation( private val remoteFilePath: String, private val shareType: ShareType, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt index d439ff268..1419ff7ea 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt @@ -33,16 +33,12 @@ import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod 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.OK import com.owncloud.android.lib.common.utils.Log_OC - import org.json.JSONObject - import java.net.URL import java.util.ArrayList -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK -import com.owncloud.android.lib.testing.OpenForTesting - /** * Created by masensio on 08/10/2015. * @@ -73,7 +69,6 @@ import com.owncloud.android.lib.testing.OpenForTesting * @author David A. Velasco * @author David González Verdugo */ -@OpenForTesting class GetRemoteShareesOperation /** * Constructor diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt index 26d4c52ff..321f170b2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt @@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC -import com.owncloud.android.lib.testing.OpenForTesting import java.net.URL /** @@ -56,7 +55,6 @@ import java.net.URL * @param subfiles If set to false (default), lists only the folder being shared * If set to true, all shared files within the folder are returned. */ -@OpenForTesting class GetRemoteSharesForFileOperation( private val remoteFilePath: String, private val reshares: Boolean, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt index 0bb53a74a..d4deda06d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt @@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC -import com.owncloud.android.lib.testing.OpenForTesting import java.net.URL /** @@ -49,7 +48,6 @@ import java.net.URL * * @param remoteShareId Share ID */ -@OpenForTesting class RemoveRemoteShareOperation(private val remoteShareId: Long) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt index 6196c458a..16f34e2d0 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt @@ -32,7 +32,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.DEFAULT_PERMISSION -import com.owncloud.android.lib.testing.OpenForTesting import okhttp3.FormBody import java.net.URL import java.text.SimpleDateFormat @@ -48,7 +47,6 @@ import java.util.Locale * @author David A. Velasco * @author David González Verdugo */ -@OpenForTesting class UpdateRemoteShareOperation /** * Constructor. No update is initialized by default, need to be applied with setters below. diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index 9cfc9839c..8bce27ef8 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -34,7 +34,6 @@ 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.OK import com.owncloud.android.lib.common.utils.Log_OC -import com.owncloud.android.lib.testing.OpenForTesting import org.json.JSONObject import java.net.URL @@ -48,7 +47,6 @@ import java.net.URL /** * Constructor */ -@OpenForTesting class GetRemoteCapabilitiesOperation : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt index ef9b63578..dae5b91aa 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/OwnCloudVersion.kt @@ -27,9 +27,7 @@ package com.owncloud.android.lib.resources.status import android.os.Parcel import android.os.Parcelable -import com.owncloud.android.lib.testing.OpenForTesting -@OpenForTesting class OwnCloudVersion(version: String) : Comparable, Parcelable { // format is in version diff --git a/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt b/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt deleted file mode 100644 index 3c91e8361..000000000 --- a/owncloudComLibrary/src/release/java/com/owncloud/android/lib/testing/OpenForTesting.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.owncloud.android.lib.testing - -/** - * This annotation allows us to open some classes for mocking purposes while they are final in - * release builds. - */ -@Target(AnnotationTarget.ANNOTATION_CLASS) -annotation class OpenClass - -/** - * Annotate a class with [OpenForTesting] if you want it to be extendable in debug builds. - */ -@OpenClass -@Target(AnnotationTarget.CLASS) -annotation class OpenForTesting From 324311b4ebf7911f4e2625d1925fca00d22fc4f3 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 8 Jul 2019 12:24:14 +0200 Subject: [PATCH 3/7] Delete unneeded extend --- .../android/lib/common/operations/RemoteOperation.java | 2 +- .../android/lib/common/operations/RemoteOperationResult.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java index fc8fd3d42..9bcdd8f20 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java @@ -16,7 +16,7 @@ import java.io.IOException; -public abstract class RemoteOperation implements Runnable { +public abstract class RemoteOperation implements Runnable { /** * OCS API header name diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index e87ed5ecc..2ae646fb8 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -52,7 +52,7 @@ import java.util.List; import java.util.Map; -public class RemoteOperationResult +public class RemoteOperationResult implements Serializable { /** @@ -70,6 +70,7 @@ public class RemoteOperationResult private ArrayList mAuthenticate = new ArrayList<>(); private String mLastPermanentLocation = null; private T mData = null; + /** * Public constructor from result code. *

@@ -583,4 +584,4 @@ public enum ResultCode { SPECIFIC_UNSUPPORTED_MEDIA_TYPE, SPECIFIC_METHOD_NOT_ALLOWED } -} \ No newline at end of file +} From 53b84bdbcf54c5add95ab4836ca6285940fdba95 Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 11 Jul 2019 11:05:28 +0200 Subject: [PATCH 4/7] Remove unused OwnCloudClient constructor --- .../lib/common/OwnCloudClientFactory.java | 110 ------------------ .../oauth/OwnCloudOAuth2RequestBuilder.java | 1 - .../shares/GetRemoteSharesForFileOperation.kt | 2 +- 3 files changed, 1 insertion(+), 112 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java index 041f72fac..6fb5345f0 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java @@ -24,123 +24,13 @@ package com.owncloud.android.lib.common; -import android.accounts.Account; -import android.accounts.AccountManager; -import android.accounts.AccountManagerFuture; -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.app.Activity; import android.content.Context; import android.net.Uri; -import android.os.Bundle; - -import com.owncloud.android.lib.common.accounts.AccountTypeUtils; -import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; -import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; - -import java.io.IOException; public class OwnCloudClientFactory { final private static String TAG = OwnCloudClientFactory.class.getSimpleName(); - /** - * Creates a OwnCloudClient setup for an ownCloud account - *

- * Do not call this method from the main thread. - * - * @param account The ownCloud account - * @param appContext Android application context - * @param currentActivity Caller {@link Activity} - * @return A OwnCloudClient object ready to be used - * @throws AuthenticatorException If the authenticator failed to get the authorization - * token for the account. - * @throws OperationCanceledException If the authenticator operation was cancelled while - * getting the authorization token for the account. - * @throws IOException If there was some I/O error while getting the - * authorization token for the account. - * @throws AccountNotFoundException If 'account' is unknown for the AccountManager - */ - public static OwnCloudClient createOwnCloudClient(Account account, Context appContext, - Activity currentActivity) - throws OperationCanceledException, AuthenticatorException, IOException, - AccountNotFoundException { - Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account)); - AccountManager am = AccountManager.get(appContext); - // TODO avoid calling to getUserData here - boolean isOauth2 = - am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; - boolean isSamlSso = - am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; - OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso); - - String username = AccountUtils.getUsernameForAccount(account); - if (isOauth2) { // TODO avoid a call to getUserData here - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), - null, - currentActivity, - null, - null); - - Bundle result = future.getResult(); - String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); - if (accessToken == null) { - throw new AuthenticatorException("WTF!"); - } - client.setCredentials( - OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken) - ); - - } else if (isSamlSso) { // TODO avoid a call to getUserData here - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), - null, - currentActivity, - null, - null); - - Bundle result = future.getResult(); - String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); - if (accessToken == null) { - throw new AuthenticatorException("WTF!"); - } - client.setCredentials( - OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken) - ); - - } else { - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypePass(account.type), - null, - currentActivity, - null, - null - ); - - Bundle result = future.getResult(); - String password = result.getString(AccountManager.KEY_AUTHTOKEN); - OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); - client.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - username, - password, - (version != null && version.isPreemptiveAuthenticationPreferred()) - ) - ); - } - - // Restore cookies - AccountUtils.restoreCookies(account, client, appContext); - - return client; - } - /** * Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud * client connections. diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java index 83d1625cd..935004dd2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java @@ -152,5 +152,4 @@ public String buildUri() { ); } } - } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt index 321f170b2..f74a7e75c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt @@ -75,7 +75,7 @@ class GetRemoteSharesForFileOperation( val getMethod = GetMethod(URL(uriBuilder.build().toString())) - getMethod.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE) + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) val status = client.executeHttpMethod(getMethod) From d6f397f7e7ad516dd0a534116b154f491db331ef Mon Sep 17 00:00:00 2001 From: davigonz Date: Fri, 12 Jul 2019 11:51:08 +0200 Subject: [PATCH 5/7] Update gradle version --- build.gradle | 2 +- .../java/com/owncloud/android/lib/resources/shares/ShareType.kt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 6af7cb1f3..3c019d782 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion" } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt index 234b42760..8825ffdc0 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt @@ -47,7 +47,6 @@ enum class ShareType constructor(val value: Int) { FEDERATED(6); companion object { - fun fromValue(value: Int): ShareType? { return when (value) { -1 -> NO_SHARED From 29238543d22384769861082f0748912a06fc2dd7 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 28 Aug 2019 12:54:04 +0200 Subject: [PATCH 6/7] Start to use Mockk instead of Mockito since is better prepared to be used along with Kotlin --- .../lib/common/accounts/AccountTypeUtils.java | 7 +---- .../lib/common/accounts/AccountUtils.java | 27 +++---------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java index b5e67c828..1d40884e0 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountTypeUtils.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2019 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -41,9 +41,4 @@ public static String getAuthTokenTypeAccessToken(String accountType) { public static String getAuthTokenTypeRefreshToken(String accountType) { return accountType + ".oauth2.refresh_token"; } - - public static String getAuthTokenTypeSamlSessionCookie(String accountType) { - return accountType + ".saml.web_sso.session_cookie"; - } - } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java index 4478330f0..2be339d83 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -65,11 +65,7 @@ public static String getWebDavUrlForAccount(Context context, Account account) OwnCloudCredentials ownCloudCredentials = getCredentialsForAccount(context, account); webDavUrlForAccount = getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_FILES_PATH_4_0 + ownCloudCredentials.getUsername(); - } catch (OperationCanceledException e) { - e.printStackTrace(); - } catch (AuthenticatorException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch (OperationCanceledException | AuthenticatorException | IOException e) { e.printStackTrace(); } @@ -148,11 +144,6 @@ public static OwnCloudCredentials getCredentialsForAccount(Context context, Acco String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2); boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE"); - 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)); @@ -164,14 +155,6 @@ public static OwnCloudCredentials getCredentialsForAccount(Context context, Acco credentials = OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken); - } else if (isSamlSso) { - String accessToken = am.blockingGetAuthToken( - account, - AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), - false); - - credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken); - } else { String password = am.blockingGetAuthToken( account, @@ -317,10 +300,7 @@ public static class Constants { * Flag signaling if the ownCloud server can be accessed with OAuth2 access tokens. */ public static final String KEY_SUPPORTS_OAUTH2 = "oc_supports_oauth2"; - /** - * Flag signaling if the ownCloud server can be accessed with session cookies from SAML-based web single-sign-on. - */ - public static final String KEY_SUPPORTS_SAML_WEB_SSO = "oc_supports_saml_web_sso"; + /** * OC account cookies */ @@ -345,6 +325,5 @@ public static class Constants { * OAuth2 refresh token **/ public static final String KEY_OAUTH2_REFRESH_TOKEN = "oc_oauth2_refresh_token"; - } -} \ No newline at end of file +} From c16823414d67a04457f9162f236c95cf99915425 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 28 Aug 2019 13:22:20 +0200 Subject: [PATCH 7/7] Keep removing more SAML stuff --- .../lib/common/DynamicSessionManager.java | 4 +- .../android/lib/common/OwnCloudClient.java | 15 +--- .../common/OwnCloudClientManagerFactory.java | 12 +--- .../lib/common/SingleSessionManager.java | 7 +- .../OwnCloudCredentialsFactory.java | 4 -- .../OwnCloudSamlSsoCredentials.java | 70 ------------------- .../operations/RemoteOperationResult.java | 10 --- 7 files changed, 7 insertions(+), 115 deletions(-) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java index 04b1f69a0..38fb11e42 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/DynamicSessionManager.java @@ -11,7 +11,7 @@ /** * Dynamic implementation of {@link OwnCloudClientManager}. - *

+ * * Wraps instances of {@link SingleSessionManager} and {@link SimpleFactoryManager} and delegates on one * or the other depending on the known version of the server corresponding to the {@link OwnCloudAccount} * @@ -60,4 +60,4 @@ public void saveAllClients(Context context, String accountType) { mSimpleFactoryManager.saveAllClients(context, accountType); mSingleSessionManager.saveAllClients(context, accountType); } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java index e0a48f197..d036214d5 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java @@ -114,7 +114,7 @@ public int executeHttpMethod(HttpBaseMethod method) throws Exception { status = method.execute(); checkFirstRedirection(method); - if (mFollowRedirects && !isIdPRedirection()) { + if (mFollowRedirects) { status = followRedirection(method).getLastStatus(); } @@ -422,7 +422,7 @@ private boolean checkUnauthorizedAccess(int status, int repeatCounter) { */ private boolean shouldInvalidateAccountCredentials(int httpStatusCode) { - boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED || isIdPRedirection()); // invalid credentials + boolean should = (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED); // invalid credentials should &= (mCredentials != null && // real credentials !(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials)); @@ -459,17 +459,6 @@ void setOwnCloudClientManager(OwnCloudClientManager clientManager) { mOwnCloudClientManager = clientManager; } - /** - * Check if the redirection is to an identity provider such as SAML or wayf - * - * @return true if the redirection location includes SAML or wayf, false otherwise - */ - private boolean isIdPRedirection() { - return (mRedirectedLocation != null && - (mRedirectedLocation.toUpperCase().contains("SAML") || - mRedirectedLocation.toLowerCase().contains("wayf"))); - } - public boolean followRedirects() { return mFollowRedirects; } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java index 7b1b0b5b5..bd1e5de6b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientManagerFactory.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2016 ownCloud GmbH. + * Copyright (C) 2019 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,9 +38,6 @@ public static OwnCloudClientManager newOwnCloudClientManager(Policy policy) { case ALWAYS_NEW_CLIENT: return new SimpleFactoryManager(); - case SINGLE_SESSION_PER_ACCOUNT: - return new SingleSessionManager(); - case SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING: return new DynamicSessionManager(); @@ -86,16 +83,11 @@ private static boolean defaultSingletonMustBeUpdated(Policy policy) { !(sDefaultSingleton instanceof SimpleFactoryManager)) { return true; } - if (policy == Policy.SINGLE_SESSION_PER_ACCOUNT && - !(sDefaultSingleton instanceof SingleSessionManager)) { - return true; - } return false; } - public static enum Policy { + public enum Policy { ALWAYS_NEW_CLIENT, - SINGLE_SESSION_PER_ACCOUNT, SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING } } \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java index 128207a82..a58400994 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/SingleSessionManager.java @@ -33,7 +33,6 @@ import android.util.Log; import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.authentication.OwnCloudSamlSsoCredentials; import com.owncloud.android.lib.common.utils.Log_OC; import java.io.IOException; @@ -119,10 +118,6 @@ public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) thr account.loadCredentials(context); client.setCredentials(account.getCredentials()); - if (client.getCredentials() instanceof OwnCloudSamlSsoCredentials) { - client.disableAutomaticCookiesHandling(); - } - if (accountName != null) { mClientsWithKnownUsername.put(accountName, client); if (Log.isLoggable(TAG, Log.VERBOSE)) { @@ -232,4 +227,4 @@ private void keepUriUpdated(OwnCloudAccount account, OwnCloudClient reusedClient reusedClient.setBaseUri(recentUri); } } -} \ No newline at end of file +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java index 5ac44517c..822ef7609 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudCredentialsFactory.java @@ -48,10 +48,6 @@ public static OwnCloudCredentials newBearerCredentials(String username, String a return new OwnCloudBearerCredentials(username, authToken); } - public static OwnCloudCredentials newSamlSsoCredentials(String username, String sessionCookie) { - return new OwnCloudSamlSsoCredentials(username, sessionCookie); - } - public static final OwnCloudCredentials getAnonymousCredentials() { if (sAnonymousCredentials == null) { sAnonymousCredentials = new OwnCloudAnonymousCredentials(); diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java deleted file mode 100644 index 40f77bb38..000000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/OwnCloudSamlSsoCredentials.java +++ /dev/null @@ -1,70 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.common.authentication; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.http.HttpClient; -import com.owncloud.android.lib.common.http.HttpConstants; - -public class OwnCloudSamlSsoCredentials implements OwnCloudCredentials { - - private String mUsername; - private String mSessionCookie; - - public OwnCloudSamlSsoCredentials(String username, String sessionCookie) { - mUsername = username != null ? username : ""; - mSessionCookie = sessionCookie != null ? sessionCookie : ""; - } - - @Override - public void applyTo(OwnCloudClient client) { - // Clear previous credentials - HttpClient.deleteHeaderForAllRequests(HttpConstants.AUTHORIZATION_HEADER); - HttpClient.deleteHeaderForAllRequests(HttpConstants.COOKIE_HEADER); - - HttpClient.addHeaderForAllRequests(HttpConstants.COOKIE_HEADER, mSessionCookie); - client.setFollowRedirects(false); - } - - @Override - public String getUsername() { - // not relevant for authentication, but relevant for informational purposes - return mUsername; - } - - @Override - public String getAuthToken() { - return mSessionCookie; - } - - @Override - public boolean authTokenExpires() { - return true; - } - - @Override - public boolean authTokenCanBeRefreshed() { - return false; - } -} \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 2ae646fb8..b58d1b73f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -254,10 +254,6 @@ public RemoteOperationResult(int httpCode, String httpPhrase, Headers headers) { } } } - if (isIdPRedirection()) { - // overrides default ResultCode.UNKNOWN - mCode = ResultCode.UNAUTHORIZED; - } } /** @@ -492,12 +488,6 @@ public String getRedirectedLocation() { return mRedirectedLocation; } - public boolean isIdPRedirection() { - return (mRedirectedLocation != null && - (mRedirectedLocation.toUpperCase().contains("SAML") || - mRedirectedLocation.toLowerCase().contains("wayf"))); - } - /** * Checks if is a non https connection *