From aca60769e6d3ffdbcfd4b3b8e91f3299ab825eb6 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 26 Oct 2022 17:07:16 +0600 Subject: [PATCH 1/2] 746-Stop_login_on_unAuthorize_response_for_murena_accounts issue: https://gitlab.e.foundation/e/os/backlog/-/issues/746 As for wrong userName, password in login flow; backend response with 401. But DavResource ignore them for `CALDAV` & `CARDDAV` configuration fetch. As murena accounts have both of them setup, we want to block login for 401 on munrena account set up. So user have faster response on 401. --- .../at/bitfire/davdroid/ui/setup/DavResourceFinder.kt | 7 ++++++- .../davdroid/ui/setup/DetectConfigurationFragment.kt | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt index a86b7697e..7c5b28468 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt @@ -31,7 +31,8 @@ import java.util.logging.Logger class DavResourceFinder( val context: Context, - private val loginModel: LoginModel + private val loginModel: LoginModel, + private val blockOnUnAuthoriedException: Boolean = false ): AutoCloseable { enum class Service(val wellKnownName: String) { @@ -430,6 +431,10 @@ class DavResourceFinder( encountered401 = true else if ((e is InterruptedIOException && e !is SocketTimeoutException) || e is InterruptedException) throw e + + if (e is UnauthorizedException && blockOnUnAuthoriedException) { + throw e + } } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt index e90b22894..e688c4de4 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt @@ -40,7 +40,9 @@ class DetectConfigurationFragment: Fragment() { return } - model.detectConfiguration(loginModel).observe(this, { result -> + val isMurenaAccountType = requireActivity().intent.getStringExtra(LoginActivity.SETUP_ACCOUNT_PROVIDER_TYPE) == LoginActivity.ACCOUNT_PROVIDER_EELO + + model.detectConfiguration(loginModel, isMurenaAccountType).observe(this, { result -> // save result for next step loginModel.configuration = result @@ -80,7 +82,7 @@ class DetectConfigurationFragment: Fragment() { return (loginModel.baseURI?.host.equals(Constants.EELO_SYNC_HOST) && ECloudAccountHelper.alreadyHasECloudAccount(context)) } - fun detectConfiguration(loginModel: LoginModel): LiveData { + fun detectConfiguration(loginModel: LoginModel, blockOnUnauthorizedException: Boolean): LiveData { synchronized(result) { if (detectionThread != null) // detection already running @@ -93,7 +95,7 @@ class DetectConfigurationFragment: Fragment() { } try { - DavResourceFinder(getApplication(), loginModel).use { finder -> + DavResourceFinder(getApplication(), loginModel, blockOnUnauthorizedException).use { finder -> result.postValue(finder.findInitialConfiguration()) } } catch(e: Exception) { -- GitLab From 2554167374862a27758fe8447f474dfcd9a5d3d5 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 26 Oct 2022 18:27:40 +0600 Subject: [PATCH 2/2] Fix typo blockOnUnAuthoriedException text --- .../java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt | 4 ++-- .../bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt index 7c5b28468..e9cbd4373 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.kt @@ -32,7 +32,7 @@ import java.util.logging.Logger class DavResourceFinder( val context: Context, private val loginModel: LoginModel, - private val blockOnUnAuthoriedException: Boolean = false + private val blockOnUnauthorizedException: Boolean = false ): AutoCloseable { enum class Service(val wellKnownName: String) { @@ -432,7 +432,7 @@ class DavResourceFinder( else if ((e is InterruptedIOException && e !is SocketTimeoutException) || e is InterruptedException) throw e - if (e is UnauthorizedException && blockOnUnAuthoriedException) { + if (e is UnauthorizedException && blockOnUnauthorizedException) { throw e } } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt index e688c4de4..6fb02a7ce 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.kt @@ -40,7 +40,8 @@ class DetectConfigurationFragment: Fragment() { return } - val isMurenaAccountType = requireActivity().intent.getStringExtra(LoginActivity.SETUP_ACCOUNT_PROVIDER_TYPE) == LoginActivity.ACCOUNT_PROVIDER_EELO + val accountType = requireActivity().intent.getStringExtra(LoginActivity.SETUP_ACCOUNT_PROVIDER_TYPE) + val isMurenaAccountType = (accountType == LoginActivity.ACCOUNT_PROVIDER_EELO) model.detectConfiguration(loginModel, isMurenaAccountType).observe(this, { result -> // save result for next step -- GitLab