From 03355fb2ace61e605f8a12ac62415b2c4c9b9070 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 14 Nov 2024 15:33:37 +0100 Subject: [PATCH] fix: remove legacy pre-sdk19 credentials basic function Signed-off-by: Andy Scherzinger --- .../nextcloud/common/OkHttpCredentialsUtil.kt | 28 ------------------- .../common/OwnCloudAnonymousCredentials.java | 6 ++-- .../lib/common/OwnCloudBasicCredentials.java | 9 +++--- .../lib/common/OwnCloudClientFactory.java | 6 ++-- 4 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 library/src/main/java/com/nextcloud/common/OkHttpCredentialsUtil.kt diff --git a/library/src/main/java/com/nextcloud/common/OkHttpCredentialsUtil.kt b/library/src/main/java/com/nextcloud/common/OkHttpCredentialsUtil.kt deleted file mode 100644 index 9f22b37d5..000000000 --- a/library/src/main/java/com/nextcloud/common/OkHttpCredentialsUtil.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Nextcloud Android Library - * - * SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-FileCopyrightText: 2021 Álvaro Brey - * SPDX-License-Identifier: MIT - */ -package com.nextcloud.common - -import android.os.Build -import okhttp3.Credentials -import java.nio.charset.StandardCharsets - -object OkHttpCredentialsUtil { - /** - * Builds basic OKHttp credentials string, using UTF_8 if available - */ - @JvmStatic - fun basic( - username: String, - password: String - ): String = - when { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT -> - Credentials.basic(username, password, StandardCharsets.UTF_8) - else -> Credentials.basic(username, password) - } -} diff --git a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudAnonymousCredentials.java b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudAnonymousCredentials.java index 2012e697e..c28062644 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudAnonymousCredentials.java +++ b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudAnonymousCredentials.java @@ -10,7 +10,9 @@ import android.os.Parcel; -import com.nextcloud.common.OkHttpCredentialsUtil; +import java.nio.charset.StandardCharsets; + +import okhttp3.Credentials; public class OwnCloudAnonymousCredentials implements OwnCloudCredentials { @@ -35,7 +37,7 @@ public boolean authTokenExpires() { @Override public String toOkHttpCredentials() { - return OkHttpCredentialsUtil.basic(getUsername(), getAuthToken()); + return Credentials.basic(getUsername(), getAuthToken(), StandardCharsets.UTF_8); } @Override diff --git a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudBasicCredentials.java b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudBasicCredentials.java index df5b87c1b..ea0b46222 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudBasicCredentials.java +++ b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudBasicCredentials.java @@ -14,15 +14,16 @@ import android.os.Parcel; -import com.nextcloud.common.OkHttpCredentialsUtil; - import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthPolicy; import org.apache.commons.httpclient.auth.AuthScope; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import okhttp3.Credentials; + public class OwnCloudBasicCredentials implements OwnCloudCredentials { private String username; @@ -59,11 +60,9 @@ public boolean authTokenExpires() { @Override public String toOkHttpCredentials() { - return OkHttpCredentialsUtil.basic(username, authToken); + return Credentials.basic(username, authToken, StandardCharsets.UTF_8); } - - /* * Autogenerated Parcelable interface */ diff --git a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java index 42cfdff9b..61e5e8d47 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java @@ -23,7 +23,6 @@ import android.os.Bundle; import com.nextcloud.common.NextcloudClient; -import com.nextcloud.common.OkHttpCredentialsUtil; import com.nextcloud.common.User; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.common.accounts.AccountUtils; @@ -32,8 +31,11 @@ import com.owncloud.android.lib.common.utils.Log_OC; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; +import okhttp3.Credentials; + public class OwnCloudClientFactory { final private static String TAG = OwnCloudClientFactory.class.getSimpleName(); @@ -223,7 +225,7 @@ public static NextcloudClient createNextcloudClient(Account account, Context app return createNextcloudClient(baseUri, userId, - OkHttpCredentialsUtil.basic(username, password), + Credentials.basic(username, password, StandardCharsets.UTF_8), appContext, true); }