Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 5582097

Browse files
committed
get access token to update through connection validator
update token
1 parent e27a968 commit 5582097

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/ConnectionValidator.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.accounts.AccountManager
44
import android.accounts.AccountsException
55
import android.content.Context
66
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials
7-
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
87
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials
98
import com.owncloud.android.lib.common.http.HttpConstants
109
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -63,7 +62,8 @@ class ConnectionValidator (
6362
}
6463
}
6564
if (successCounter >= failCounter) {
66-
//update credentials in client
65+
baseClient.credentials = client.credentials
66+
baseClient.cookiesForBaseUri = client.cookiesForBaseUri
6767
return true
6868
}
6969
validationRetryCount++
@@ -89,11 +89,6 @@ class ConnectionValidator (
8989
return remoteStatusOperation.execute(client)
9090
}
9191

92-
private fun triggerAuthRefresh(): OwnCloudCredentials {
93-
Timber.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!! need to reauthenticate !!!!!!!!!!!!!!!!!!!!!!!!!!")
94-
return OwnCloudCredentialsFactory.getAnonymousCredentials()
95-
}
96-
9792
private fun canAccessRootFolder(client: OwnCloudClient): RemoteOperationResult<Boolean> {
9893
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation("/", true)
9994
return checkPathExistenceRemoteOperation.execute(client)
@@ -154,8 +149,10 @@ class ConnectionValidator (
154149
val credentials = account.credentials
155150
if (shouldInvalidateAccountCredentials(credentials, account, status)) {
156151
invalidateAccountCredentials(account, credentials)
152+
157153
if (credentials.authTokenCanBeRefreshed()) {
158154
try {
155+
// This command does the actual refresh
159156
account.loadCredentials(context)
160157
// if mAccount.getCredentials().length() == 0 --> refresh failed
161158
client.credentials = account.credentials

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class OwnCloudClient extends HttpClient {
5959
public static final String STATUS_PATH = "/status.php";
6060
private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/";
6161
private static final int MAX_REDIRECTIONS_COUNT = 5;
62+
private static final int MAX_RETRY_COUNT = 2;
6263

6364
private static int sIntanceCounter = 0;
6465
private OwnCloudCredentials mCredentials = null;
@@ -112,12 +113,12 @@ public int executeHttpMethod(HttpBaseMethod method) throws Exception {
112113
}
113114

114115
private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
115-
boolean repeatWithFreshCredentials;
116116
int repeatCounter = 0;
117117
int status;
118118

119-
boolean retry = false;
119+
boolean retry;
120120
do {
121+
repeatCounter++;
121122
retry = false;
122123
String requestId = RandomUtils.generateRandomUUID();
123124

@@ -126,7 +127,7 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
126127
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
127128
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
128129
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
129-
if (mCredentials.getHeaderAuth() != null && method.getRequestHeader(AUTHORIZATION_HEADER) == null) {
130+
if (mCredentials.getHeaderAuth() != null && !mCredentials.getHeaderAuth().isEmpty()) {
130131
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
131132
}
132133

@@ -149,7 +150,7 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
149150
}
150151
*/
151152

152-
} while (retry);
153+
} while (retry && repeatCounter < MAX_RETRY_COUNT);
153154

154155
return status;
155156
}
@@ -166,6 +167,11 @@ private void stacklog(int status, HttpBaseMethod method) {
166167
"\nUrl: " + method.getHttpUrl() +
167168
"\nCookeis: " + getCookiesForBaseUri().toString() +
168169
"\nCredentials type: " + mCredentials.getClass().toString() +
170+
"\ntoken: " + mCredentials.getAuthToken() +
171+
172+
"\nHeaders: ++++" +
173+
"\n" + method.getRequest().headers().toString() +
174+
"+++++++++++++" +
169175
"\ntrace: " + ExceptionUtils.getStackTrace(e) +
170176
"---------------------------");
171177
}

0 commit comments

Comments
 (0)