Re-initialise the client to access the cloud when credentials changes

Fixes #395
This commit is contained in:
Julian Raufelder 2021-12-03 16:49:10 +01:00
parent ce9e76bf23
commit c685cc3645
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D
15 changed files with 47 additions and 7 deletions

View File

@ -56,5 +56,9 @@ class DropboxClientFactory {
return HttpLoggingInterceptor(logger, context)
}
fun logout() {
instance = null
}
}
}

View File

@ -203,7 +203,7 @@ internal class DropboxCloudContentRepository(private val cloud: DropboxCloud, co
@Throws(BackendException::class)
override fun logout(cloud: DropboxCloud) {
// empty
this.cloud.logout()
}
}

View File

@ -372,6 +372,10 @@ internal class DropboxImpl(cloud: DropboxCloud, context: Context) {
return currentAccount.name.displayName
}
fun logout() {
DropboxClientFactory.logout()
}
companion object {
private const val CHUNKED_UPLOAD_CHUNK_SIZE = 8L shl 20

View File

@ -59,5 +59,10 @@ class OnedriveClientFactory private constructor() {
return HttpLoggingInterceptor(logger, context)
}
@Synchronized
fun logout() {
instance = null
}
}
}

View File

@ -481,6 +481,8 @@ internal class OnedriveImpl(cloud: OnedriveCloud, context: Context, nodeInfoCach
} catch (e: ExecutionException) {
throw FatalBackendException(e)
}
OnedriveClientFactory.logout()
}
companion object {

View File

@ -53,5 +53,10 @@ class PCloudClientFactory {
return HttpLoggingInterceptor(logger, context)
}
@Synchronized
fun logout() {
instance = null
}
}
}

View File

@ -171,7 +171,7 @@ internal class PCloudContentRepository(private val cloud: PCloud, context: Conte
@Throws(BackendException::class)
override fun logout(cloud: PCloud) {
// empty
this.cloud.logout()
}
}

View File

@ -359,6 +359,10 @@ internal class PCloudImpl(context: Context, cloud: PCloud) {
}
}
fun logout() {
PCloudClientFactory.logout()
}
init {
if (cloud.accessToken() == null) {
throw NoAuthenticationProvidedException(cloud)

View File

@ -85,5 +85,10 @@ class S3ClientFactory private constructor() {
val activeNetworkInfo = connectivityManager.activeNetworkInfo
return activeNetworkInfo != null && activeNetworkInfo.isConnected
}
@Synchronized
fun logout() {
instance = null
}
}
}

View File

@ -169,7 +169,7 @@ internal class S3CloudContentRepository(private val cloud: S3Cloud, context: Con
@Throws(BackendException::class)
override fun logout(cloud: S3Cloud) {
// empty
this.cloud.logout()
}
}

View File

@ -366,6 +366,10 @@ internal class S3Impl(context: Context, cloud: S3Cloud) {
}
}
fun logout() {
S3ClientFactory.logout()
}
companion object {
private const val DELIMITER = "/"

View File

@ -110,12 +110,11 @@ internal class WebDavCompatibleHttpClient(cloud: WebDavCloud, context: Context)
val credentials = Credentials(webDavCloud.username(), decryptPassword(context, webDavCloud.password()))
val basicAuthenticator = BasicAuthenticator(credentials, StandardCharsets.UTF_8)
val digestAuthenticator = DigestAuthenticator(credentials)
var result: Authenticator = DispatchingAuthenticator.Builder() //
val authenticator = DispatchingAuthenticator.Builder() //
.with("digest", digestAuthenticator) //
.with("basic", basicAuthenticator) //
.build()
result = CachingAuthenticatorDecorator(result, authCache)
return result
return CachingAuthenticatorDecorator(authenticator, authCache)
}
@Throws(UnableToDecryptWebdavPasswordException::class)

View File

@ -61,5 +61,9 @@ class GoogleDriveClientFactory internal constructor() {
}
.build()
}
fun invalidateClient() {
instance = null
}
}
}

View File

@ -188,7 +188,7 @@ internal class GoogleDriveCloudContentRepository(context: Context, private val c
@Throws(BackendException::class)
override fun logout(cloud: GoogleDriveCloud) {
// empty
impl.logout()
}
}

View File

@ -382,6 +382,10 @@ internal class GoogleDriveImpl(context: Context, googleDriveCloud: GoogleDriveCl
return about.user.displayName
}
fun logout() {
GoogleDriveClientFactory.invalidateClient()
}
companion object {
private const val STATUS_REQUEST_RANGE_NOT_SATISFIABLE = 416