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 8451edb1..40d1013a 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 @@ -292,6 +292,8 @@ public class AccountUtils { /** * Flag signaling if the ownCloud server can be accessed with OAuth2 access tokens. */ + + // TODO Please review this constants, move them out of the library, the rest of OAuth variables are in data layer public static final String KEY_SUPPORTS_OAUTH2 = "oc_supports_oauth2"; public static final String OAUTH_SUPPORTED_TRUE = "TRUE"; @@ -316,21 +318,6 @@ public class AccountUtils { */ public static final String KEY_DISPLAY_NAME = "oc_display_name"; - /** - * OAuth2 user id - **/ - public static final String KEY_USER_ID = "user_id"; - - /** - * OAuth2 refresh token - **/ - public static final String KEY_OAUTH2_REFRESH_TOKEN = "oc_oauth2_refresh_token"; - - /** - * OAuth2 scope - */ - public static final String KEY_OAUTH2_SCOPE = "oc_oauth2_scope"; - public static final int ACCOUNT_VERSION = 1; } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OAuthConnectionBuilder.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OAuthConnectionBuilder.kt deleted file mode 100644 index f243624b..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OAuthConnectionBuilder.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.owncloud.android.lib.common.authentication.oauth - -import android.content.Context -import android.net.Uri -import com.owncloud.android.lib.common.network.AdvancedX509TrustManager -import com.owncloud.android.lib.common.network.NetworkUtils -import net.openid.appauth.connectivity.ConnectionBuilder -import timber.log.Timber -import java.io.IOException -import java.net.HttpURLConnection -import java.net.URL -import java.security.NoSuchAlgorithmException -import java.util.Objects -import java.util.concurrent.TimeUnit -import javax.net.ssl.HostnameVerifier -import javax.net.ssl.HttpsURLConnection -import javax.net.ssl.SSLContext -import javax.net.ssl.TrustManager -import javax.net.ssl.X509TrustManager - -/** - * Based on [net.openid.appauth.connectivity.DefaultConnectionBuilder] but permitting http connections in addition - * to https connections - */ -class OAuthConnectionBuilder(val context: Context) : ConnectionBuilder { - /** - * The singleton instance of the default connection builder. - */ - private val CONNECTION_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(15).toInt() - private val READ_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10).toInt() - private val HTTPS_SCHEME = "https" - - @Throws(IOException::class) - override fun openConnection(uri: Uri): HttpURLConnection { - val conn: HttpURLConnection - - if (Objects.equals(uri.scheme, HTTPS_SCHEME)) { - conn = URL(uri.toString()).openConnection() as HttpsURLConnection - try { - val trustManager: X509TrustManager = AdvancedX509TrustManager( - NetworkUtils.getKnownServersStore(context) - ) - val sslContext: SSLContext - sslContext = try { - SSLContext.getInstance("TLSv1.2") - } catch (tlsv12Exception: NoSuchAlgorithmException) { - try { - Timber.w("TLSv1.2 is not supported in this device; falling through TLSv1.1") - SSLContext.getInstance("TLSv1.1") - } catch (tlsv11Exception: NoSuchAlgorithmException) { - Timber.w("TLSv1.1 is not supported in this device; falling through TLSv1.0") - SSLContext.getInstance("TLSv1") - // should be available in any device; see reference of supported protocols in - // http://developer.android.com/reference/javax/net/ssl/SSLSocket.html - } - } - sslContext.init(null, arrayOf(trustManager), null) - conn.hostnameVerifier = HostnameVerifier { _, _ -> true } // Do not verify the host for now - conn.sslSocketFactory = sslContext.socketFactory - } catch (e: Exception) { - Timber.e(e, "Could not setup SSL system") - } - } else { - conn = URL(uri.toString()).openConnection() as HttpURLConnection - } - - return conn.apply { - connectTimeout = CONNECTION_TIMEOUT_MS - readTimeout = READ_TIMEOUT_MS - instanceFollowRedirects = false - } - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java index 2e9dee81..4255e1a6 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java @@ -78,14 +78,18 @@ public abstract class DavMethod extends HttpBaseMethod { .build(); } else if (mResponse != null) { - ResponseBody responseBody = ResponseBody.create( - mResponse.body().contentType(), - httpException.getResponseBody() - ); + // The check below should be included in okhttp library, method ResponseBody.create( + // TODO check most recent versions of okhttp to see if this is already fixed and try to update if so + if (mResponse.body().contentType() != null) { + ResponseBody responseBody = ResponseBody.create( + mResponse.body().contentType(), + httpException.getResponseBody() + ); - mResponse = mResponse.newBuilder() - .body(responseBody) - .build(); + mResponse = mResponse.newBuilder() + .body(responseBody) + .build(); + } } return httpException.getCode(); 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 881aa0d2..715ed32c 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 @@ -66,7 +66,7 @@ public class RemoteOperationResult private Exception mException = null; private ResultCode mCode = ResultCode.UNKNOWN_ERROR; private String mRedirectedLocation; - private String mAuthenticate; + private List mAuthenticate = new ArrayList<>(); private String mLastPermanentLocation = null; private T mData = null; @@ -253,7 +253,9 @@ public class RemoteOperationResult continue; } if ("www-authenticate".equals(header.getKey().toLowerCase())) { - mAuthenticate = header.getValue().get(0).toLowerCase(); + for (String value: header.getValue()) { + mAuthenticate.add(value.toLowerCase()); + } } } } @@ -494,7 +496,7 @@ public class RemoteOperationResult return (mRedirectedLocation != null && !(mRedirectedLocation.toLowerCase().startsWith("https://"))); } - public String getAuthenticateHeaders() { + public List getAuthenticateHeaders() { return mAuthenticate; }