1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-07-10 07:58:54 +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 org.apache.commons.lang3.exception.ExceptionUtils
import timber.log.Timber import timber.log.Timber
import java.io.IOException import java.io.IOException
import java.lang.Exception
/** /**
* ConnectionValidator * ConnectionValidator
@ -45,7 +46,7 @@ import java.io.IOException
*/ */
class ConnectionValidator( class ConnectionValidator(
val context: Context, val context: Context,
private val clearCookiesOnValidation: Boolean val clearCookiesOnValidation: Boolean
) { ) {
fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager, context: Context): Boolean { fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager, context: Context): Boolean {
try { try {
@ -60,12 +61,12 @@ class ConnectionValidator(
client.account = baseClient.account client.account = baseClient.account
client.credentials = baseClient.credentials client.credentials = baseClient.credentials
while (validationRetryCount < VALIDATION_RETRY_COUNT) { while (validationRetryCount < VALIDATION_RETRY_COUNT) {
Timber.d("validationRetryCount %d", validationRetryCount) Timber.d("validationRetryCout %d", validationRetryCount)
var successCounter = 0 var successCounter = 0
var failCounter = 0 var failCounter = 0
client.setFollowRedirects(true) client.setFollowRedirects(true)
if (isOwnCloudStatusOk(client)) { if (isOnwCloudStatusOk(client)) {
successCounter++ successCounter++
} else { } else {
failCounter++ failCounter++
@ -102,7 +103,7 @@ class ConnectionValidator(
return false return false
} }
private fun isOwnCloudStatusOk(client: OwnCloudClient): Boolean { private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
val reply = getOwnCloudStatus(client) val reply = getOwnCloudStatus(client)
// dont check status code. It currently relais on the broken redirect code of the owncloud 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 // TODO: Use okhttp redirect and add this check again
@ -137,12 +138,6 @@ class ConnectionValidator(
// test if have all the needed to effectively invalidate ... // test if have all the needed to effectively invalidate ...
shouldInvalidateAccountCredentials = shouldInvalidateAccountCredentials =
shouldInvalidateAccountCredentials and (account.savedAccount != null) 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 return shouldInvalidateAccountCredentials
} }
@ -155,7 +150,6 @@ class ConnectionValidator(
* *
*/ */
private fun invalidateAccountCredentials(account: OwnCloudAccount, credentials: OwnCloudCredentials) { private fun invalidateAccountCredentials(account: OwnCloudAccount, credentials: OwnCloudCredentials) {
Timber.i("Invalidating account credentials for account $account")
val am = AccountManager.get(context) val am = AccountManager.get(context)
am.invalidateAuthToken( am.invalidateAuthToken(
account.savedAccount.type, account.savedAccount.type,
@ -173,6 +167,8 @@ class ConnectionValidator(
* *
* Refresh current credentials if possible, and marks a retry. * Refresh current credentials if possible, and marks a retry.
* *
* @param status
* @param repeatCounter
* @return * @return
*/ */
private fun checkUnauthorizedAccess(client: OwnCloudClient, singleSessionManager: SingleSessionManager, status: Int): Boolean { private fun checkUnauthorizedAccess(client: OwnCloudClient, singleSessionManager: SingleSessionManager, status: Int): Boolean {
@ -185,7 +181,6 @@ class ConnectionValidator(
if (credentials.authTokenCanBeRefreshed()) { if (credentials.authTokenCanBeRefreshed()) {
try { try {
// This command does the actual refresh // This command does the actual refresh
Timber.i("Trying to refresh auth token for account $account")
account.loadCredentials(context) account.loadCredentials(context)
// if mAccount.getCredentials().length() == 0 --> refresh failed // if mAccount.getCredentials().length() == 0 --> refresh failed
client.credentials = account.credentials client.credentials = account.credentials
@ -206,7 +201,6 @@ class ConnectionValidator(
if (!credentialsWereRefreshed) { if (!credentialsWereRefreshed) {
// if credentials are not refreshed, client must be removed // if credentials are not refreshed, client must be removed
// from the OwnCloudClientManager to prevent it is reused once and again // 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) singleSessionManager.removeClientFor(account)
} }
} }
@ -216,6 +210,6 @@ class ConnectionValidator(
} }
companion object { 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); String username = AccountUtils.getUsernameForAccount(account);
if (isOauth2) { if (isOauth2) {
Timber.i("Trying to retrieve credentials for oAuth account" + account.name);
String accessToken = am.blockingGetAuthToken( String accessToken = am.blockingGetAuthToken(
account, account,
AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),