Browse Source

Simplify checks of authentication needed after change in library; as a side effect, uploads failed due to SAML session expired are stored with right 'credentials error', instead of 'unknown'

David A. Velasco 9 years ago
parent
commit
d053f34b8f

+ 1 - 1
owncloud-android-library

@@ -1 +1 @@
-Subproject commit dc3ae324c30872b905397c76f6ad9391ec482e66
+Subproject commit 0a693f2b4e4f36414eae5d8c7d2d9e9d3c4700e5

+ 1 - 4
src/com/owncloud/android/files/services/FileDownloader.java

@@ -545,10 +545,7 @@ public class FileDownloader extends Service
             int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker :
                     R.string.downloader_download_failed_ticker;
 
-            boolean needsToUpdateCredentials = (
-                    downloadResult.getCode() == ResultCode.UNAUTHORIZED ||
-                            downloadResult.isIdPRedirection()
-            );
+            boolean needsToUpdateCredentials = (ResultCode.UNAUTHORIZED.equals(downloadResult.getCode()));
             tickerId = (needsToUpdateCredentials) ?
                     R.string.downloader_download_failed_credentials_error : tickerId;
 

+ 1 - 4
src/com/owncloud/android/files/services/FileUploader.java

@@ -1047,10 +1047,7 @@ public class FileUploader extends Service
             String content;
 
             // check credentials error
-            boolean needsToUpdateCredentials = (
-                    uploadResult.getCode() == ResultCode.UNAUTHORIZED ||
-                            uploadResult.isIdPRedirection()
-            );
+            boolean needsToUpdateCredentials = (ResultCode.UNAUTHORIZED.equals(uploadResult.getCode()));
             tickerId = (needsToUpdateCredentials) ?
                     R.string.uploader_upload_failed_credentials_error : tickerId;
 

+ 3 - 1
src/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java

@@ -34,6 +34,8 @@ import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
 import android.content.Context;
 import android.net.Uri;
 
+import org.apache.commons.httpclient.HttpStatus;
+
 /**
  * Operation to find out what authentication method requires
  * the server to access files.
@@ -99,7 +101,7 @@ public class DetectAuthenticationMethodOperation extends RemoteOperation {
         } 
 
         // analyze response  
-        if (result.getCode() == ResultCode.UNAUTHORIZED) {
+        if (result.getHttpCode() == HttpStatus.SC_UNAUTHORIZED) {
             String authRequest = ((result.getAuthenticateHeader()).trim()).toLowerCase();
             if (authRequest.startsWith("basic")) {
                 authMethod = AuthenticationMethod.BASIC_HTTP_AUTH;

+ 3 - 7
src/com/owncloud/android/syncadapter/FileSyncAdapter.java

@@ -300,9 +300,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             
         } else if (result.getCode() != ResultCode.FILE_NOT_FOUND) {
             // in failures, the statistics for the global result are updated
-            if (    result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED ||
-                    result.isIdPRedirection()
-                ) {
+            if (RemoteOperationResult.ResultCode.UNAUTHORIZED.equals(result.getCode())) {
                 mSyncResult.stats.numAuthExceptions++;
                 
             } else if (result.getException() instanceof DavException) {
@@ -395,10 +393,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
     private void notifyFailedSynchronization() {
         NotificationCompat.Builder notificationBuilder = createNotificationBuilder();
         boolean needsToUpdateCredentials = (
-                mLastFailedResult != null && (  
-                        mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED ||
-                        mLastFailedResult.isIdPRedirection()
-                )
+                mLastFailedResult != null &&
+                ResultCode.UNAUTHORIZED.equals(mLastFailedResult.getCode())
         );
         if (needsToUpdateCredentials) {
             // let the user update credentials with one click

+ 0 - 1
src/com/owncloud/android/ui/activity/FileActivity.java

@@ -743,7 +743,6 @@ public class FileActivity extends AppCompatActivity
 
         if (!result.isSuccess() && (
                 result.getCode() == ResultCode.UNAUTHORIZED ||
-                result.isIdPRedirection() ||
                 (result.isException() && result.getException() instanceof AuthenticatorException)
                 )) {
 

+ 1 - 2
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -1028,8 +1028,7 @@ public class FileDisplayActivity extends HookActivity implements
                                 equals(event) &&/// TODO refactor and make common
 
                                 synchResult != null && !synchResult.isSuccess() &&
-                                (synchResult.getCode() == ResultCode.UNAUTHORIZED ||
-                                        synchResult.isIdPRedirection() ||
+                                (ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) ||
                                         (synchResult.isException() && synchResult.getException()
                                                 instanceof AuthenticatorException))) {
 

+ 2 - 3
src/com/owncloud/android/ui/activity/FolderPickerActivity.java

@@ -481,9 +481,8 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
                                     equals(event) &&
                                 /// TODO refactor and make common
                                 synchResult != null && !synchResult.isSuccess() &&  
-                                (synchResult.getCode() == ResultCode.UNAUTHORIZED   || 
-                                    synchResult.isIdPRedirection()                  ||
-                                    (synchResult.isException() && synchResult.getException() 
+                                (ResultCode.UNAUTHORIZED.equals(synchResult.getCode()) ||
+                                    (synchResult.isException() && synchResult.getException()
                                             instanceof AuthenticatorException))) {
 
                             requestCredentialsUpdate(context);