1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-07-09 23:48:45 +00:00

Compare commits

..

No commits in common. "defa4d1469b780919e17797d9191a089b5ac9d7a" and "b7100704261cfe5d3ce156171f58f91c973afc28" have entirely different histories.

2 changed files with 8 additions and 15 deletions

View File

@ -37,6 +37,7 @@ import com.owncloud.android.lib.resources.status.RemoteServerInfo
import org.apache.commons.lang3.exception.ExceptionUtils
import timber.log.Timber
import java.io.IOException
import java.lang.Exception
/**
* ConnectionValidator
@ -45,7 +46,7 @@ import java.io.IOException
*/
class ConnectionValidator(
val context: Context,
private val clearCookiesOnValidation: Boolean
val clearCookiesOnValidation: Boolean
) {
fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager, context: Context): Boolean {
try {
@ -60,12 +61,12 @@ class ConnectionValidator(
client.account = baseClient.account
client.credentials = baseClient.credentials
while (validationRetryCount < VALIDATION_RETRY_COUNT) {
Timber.d("validationRetryCount %d", validationRetryCount)
Timber.d("validationRetryCout %d", validationRetryCount)
var successCounter = 0
var failCounter = 0
client.setFollowRedirects(true)
if (isOwnCloudStatusOk(client)) {
if (isOnwCloudStatusOk(client)) {
successCounter++
} else {
failCounter++
@ -102,7 +103,7 @@ class ConnectionValidator(
return false
}
private fun isOwnCloudStatusOk(client: OwnCloudClient): Boolean {
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
val reply = getOwnCloudStatus(client)
// dont check status code. It currently relais on the broken redirect code of the owncloud client
// TODO: Use okhttp redirect and add this check again
@ -137,12 +138,6 @@ class ConnectionValidator(
// test if have all the needed to effectively invalidate ...
shouldInvalidateAccountCredentials =
shouldInvalidateAccountCredentials and (account.savedAccount != null)
Timber.d(
"""Received error: $httpStatusCode,
account: ${account.name}
credentials are real: ${credentials !is OwnCloudAnonymousCredentials},
so we need to invalidate credentials for account ${account.name} : $shouldInvalidateAccountCredentials"""
)
return shouldInvalidateAccountCredentials
}
@ -155,7 +150,6 @@ class ConnectionValidator(
*
*/
private fun invalidateAccountCredentials(account: OwnCloudAccount, credentials: OwnCloudCredentials) {
Timber.i("Invalidating account credentials for account $account")
val am = AccountManager.get(context)
am.invalidateAuthToken(
account.savedAccount.type,
@ -173,6 +167,8 @@ class ConnectionValidator(
*
* Refresh current credentials if possible, and marks a retry.
*
* @param status
* @param repeatCounter
* @return
*/
private fun checkUnauthorizedAccess(client: OwnCloudClient, singleSessionManager: SingleSessionManager, status: Int): Boolean {
@ -185,7 +181,6 @@ class ConnectionValidator(
if (credentials.authTokenCanBeRefreshed()) {
try {
// This command does the actual refresh
Timber.i("Trying to refresh auth token for account $account")
account.loadCredentials(context)
// if mAccount.getCredentials().length() == 0 --> refresh failed
client.credentials = account.credentials
@ -206,7 +201,6 @@ class ConnectionValidator(
if (!credentialsWereRefreshed) {
// if credentials are not refreshed, client must be removed
// from the OwnCloudClientManager to prevent it is reused once and again
Timber.w("Credentials were not refreshed, client will be removed from the Session Manager to prevent using it over and over")
singleSessionManager.removeClientFor(account)
}
}
@ -216,6 +210,6 @@ class ConnectionValidator(
}
companion object {
private const val VALIDATION_RETRY_COUNT = 3
private val VALIDATION_RETRY_COUNT = 3
}
}

View File

@ -112,7 +112,6 @@ public class AccountUtils {
String username = AccountUtils.getUsernameForAccount(account);
if (isOauth2) {
Timber.i("Trying to retrieve credentials for oAuth account" + account.name);
String accessToken = am.blockingGetAuthToken(
account,
AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),