|
25 | 25 |
|
26 | 26 | package com.owncloud.android.lib.common;
|
27 | 27 |
|
28 |
| -import android.accounts.AccountManager; |
29 |
| -import android.accounts.AccountsException; |
30 | 28 | import android.net.Uri;
|
31 | 29 |
|
32 | 30 | import at.bitfire.dav4jvm.exception.HttpException;
|
|
47 | 45 |
|
48 | 46 | import java.io.IOException;
|
49 | 47 | import java.io.InputStream;
|
50 |
| -import java.util.ArrayList; |
51 | 48 | import java.util.List;
|
52 | 49 |
|
53 | 50 | import static com.owncloud.android.lib.common.http.HttpConstants.AUTHORIZATION_HEADER;
|
@@ -143,13 +140,6 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
|
143 | 140 | status = followRedirection(method).getLastStatus();
|
144 | 141 | }
|
145 | 142 |
|
146 |
| - /* |
147 |
| - repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter); |
148 |
| - if (repeatWithFreshCredentials) { |
149 |
| - repeatCounter++; |
150 |
| - } |
151 |
| - */ |
152 |
| - |
153 | 143 | } while (retry && repeatCounter < MAX_RETRY_COUNT);
|
154 | 144 |
|
155 | 145 | return status;
|
@@ -178,29 +168,18 @@ private void stacklog(int status, HttpBaseMethod method) {
|
178 | 168 | }
|
179 | 169 |
|
180 | 170 | private int executeRedirectedHttpMethod(HttpBaseMethod method) throws Exception {
|
181 |
| - boolean repeatWithFreshCredentials; |
182 |
| - int repeatCounter = 0; |
183 | 171 | int status;
|
184 |
| - |
185 |
| - do { |
186 |
| - String requestId = RandomUtils.generateRandomUUID(); |
187 |
| - |
188 |
| - // Header to allow tracing requests in apache and ownCloud logs |
189 |
| - Timber.d("Executing in request with id %s", requestId); |
190 |
| - method.setRequestHeader(OC_X_REQUEST_ID, requestId); |
191 |
| - method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent()); |
192 |
| - method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY); |
193 |
| - if (mCredentials.getHeaderAuth() != null) { |
194 |
| - method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth()); |
195 |
| - } |
196 |
| - status = method.execute(); |
197 |
| - |
198 |
| - repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter); |
199 |
| - if (repeatWithFreshCredentials) { |
200 |
| - repeatCounter++; |
201 |
| - } |
202 |
| - } while (repeatWithFreshCredentials); |
203 |
| - |
| 172 | + String requestId = RandomUtils.generateRandomUUID(); |
| 173 | + |
| 174 | + // Header to allow tracing requests in apache and ownCloud logs |
| 175 | + Timber.d("Executing in request with id %s", requestId); |
| 176 | + method.setRequestHeader(OC_X_REQUEST_ID, requestId); |
| 177 | + method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent()); |
| 178 | + method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY); |
| 179 | + if (mCredentials.getHeaderAuth() != null) { |
| 180 | + method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth()); |
| 181 | + } |
| 182 | + status = method.execute(); |
204 | 183 | return status;
|
205 | 184 | }
|
206 | 185 |
|
@@ -365,86 +344,6 @@ public void setAccount(OwnCloudAccount account) {
|
365 | 344 | this.mAccount = account;
|
366 | 345 | }
|
367 | 346 |
|
368 |
| - /** |
369 |
| - * Checks the status code of an execution and decides if should be repeated with fresh credentials. |
370 |
| - * <p> |
371 |
| - * Invalidates current credentials if the request failed as anauthorized. |
372 |
| - * <p> |
373 |
| - * Refresh current credentials if possible, and marks a retry. |
374 |
| - * |
375 |
| - * @param status |
376 |
| - * @param repeatCounter |
377 |
| - * @return |
378 |
| - */ |
379 |
| - private boolean checkUnauthorizedAccess(int status, int repeatCounter) { |
380 |
| - boolean credentialsWereRefreshed = false; |
381 |
| - |
382 |
| - if (shouldInvalidateAccountCredentials(status)) { |
383 |
| - invalidateAccountCredentials(); |
384 |
| - |
385 |
| - if (getCredentials().authTokenCanBeRefreshed() && |
386 |
| - repeatCounter < 1) { |
387 |
| - try { |
388 |
| - mAccount.loadCredentials(getContext()); |
389 |
| - // if mAccount.getCredentials().length() == 0 --> refresh failed |
390 |
| - setCredentials(mAccount.getCredentials()); |
391 |
| - credentialsWereRefreshed = true; |
392 |
| - |
393 |
| - } catch (AccountsException | IOException e) { |
394 |
| - Timber.e(e, "Error while trying to refresh auth token for %s", |
395 |
| - mAccount.getSavedAccount().name |
396 |
| - ); |
397 |
| - } |
398 |
| - |
399 |
| - if (!credentialsWereRefreshed && mSingleSessionManager != null) { |
400 |
| - // if credentials are not refreshed, client must be removed |
401 |
| - // from the OwnCloudClientManager to prevent it is reused once and again |
402 |
| - mSingleSessionManager.removeClientFor(mAccount); |
403 |
| - } |
404 |
| - } |
405 |
| - // else: onExecute will finish with status 401 |
406 |
| - } |
407 |
| - |
408 |
| - return credentialsWereRefreshed; |
409 |
| - } |
410 |
| - |
411 |
| - /** |
412 |
| - * Determines if credentials should be invalidated according the to the HTTPS status |
413 |
| - * of a network request just performed. |
414 |
| - * |
415 |
| - * @param httpStatusCode Result of the last request ran with the 'credentials' belows. |
416 |
| - * @return 'True' if credentials should and might be invalidated, 'false' if shouldn't or |
417 |
| - * cannot be invalidated with the given arguments. |
418 |
| - */ |
419 |
| - private boolean shouldInvalidateAccountCredentials(int httpStatusCode) { |
420 |
| - boolean shouldInvalidateAccountCredentials = |
421 |
| - (httpStatusCode == HttpConstants.HTTP_UNAUTHORIZED); |
422 |
| - |
423 |
| - shouldInvalidateAccountCredentials &= (mCredentials != null && // real credentials |
424 |
| - !(mCredentials instanceof OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials)); |
425 |
| - |
426 |
| - // test if have all the needed to effectively invalidate ... |
427 |
| - shouldInvalidateAccountCredentials &= (mAccount != null && mAccount.getSavedAccount() != null && getContext() != null); |
428 |
| - |
429 |
| - return shouldInvalidateAccountCredentials; |
430 |
| - } |
431 |
| - |
432 |
| - /** |
433 |
| - * Invalidates credentials stored for the given account in the system {@link AccountManager} and in |
434 |
| - * current {@link SingleSessionManager#getDefaultSingleton()} instance. |
435 |
| - * <p> |
436 |
| - * {@link #shouldInvalidateAccountCredentials(int)} should be called first. |
437 |
| - * |
438 |
| - */ |
439 |
| - private void invalidateAccountCredentials() { |
440 |
| - AccountManager am = AccountManager.get(getContext()); |
441 |
| - am.invalidateAuthToken( |
442 |
| - mAccount.getSavedAccount().type, |
443 |
| - mCredentials.getAuthToken() |
444 |
| - ); |
445 |
| - am.clearPassword(mAccount.getSavedAccount()); // being strict, only needed for Basic Auth credentials |
446 |
| - } |
447 |
| - |
448 | 347 | public boolean getFollowRedirects() {
|
449 | 348 | return mFollowRedirects;
|
450 | 349 | }
|
|
0 commit comments