Added skeleton of new operation to detect authentication method in the server side
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index 16ce755..a8293c3 100644 (file)
@@ -176,7 +176,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
     public static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT";\r
     \r
 \r
     public static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT";\r
     \r
-    private boolean mTryEmptyAuthorization = false;\r
+    private boolean mDetectAuthorizationMethod = false;\r
 \r
 \r
     /**\r
 \r
 \r
     /**\r
@@ -897,17 +897,20 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mDiscoveredVersion = operation.getDiscoveredVersion();\r
             mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\r
             \r
             mDiscoveredVersion = operation.getDiscoveredVersion();\r
             mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\r
             \r
+            // Refresh server status, but don't show it\r
+            updateServerStatusIconAndText(result);\r
+            \r
             /// update status icon and text\r
             if (mServerIsValid) {\r
                 hideRefreshButton();\r
                 // Try to create an account with user and pass "", to know if it is a regular server\r
                 // Update connect button in the answer of this method\r
             /// update status icon and text\r
             if (mServerIsValid) {\r
                 hideRefreshButton();\r
                 // Try to create an account with user and pass "", to know if it is a regular server\r
                 // Update connect button in the answer of this method\r
-                tryEmptyAuthorization();\r
+                detectAuthorizationMethod();\r
             } else {\r
                 showRefreshButton();\r
             } else {\r
                 showRefreshButton();\r
+                // Show server status\r
+                showServerStatus();\r
             }\r
             }\r
-            updateServerStatusIconAndText(result);\r
-            showServerStatus();\r
 \r
             /// very special case (TODO: move to a common place for all the remote operations)\r
             if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
 \r
             /// very special case (TODO: move to a common place for all the remote operations)\r
             if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
@@ -923,8 +926,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     /**\r
      *  Try to access with  user/pass ""/"", to know if it is a regular server\r
      */\r
     /**\r
      *  Try to access with  user/pass ""/"", to know if it is a regular server\r
      */\r
-    private void tryEmptyAuthorization() {\r
-        mTryEmptyAuthorization = true;\r
+    private void detectAuthorizationMethod() {\r
+        mDetectAuthorizationMethod = true;\r
         \r
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
         \r
         \r
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
         \r
@@ -1140,13 +1143,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
 \r
     private void updateStatusIconFailUserName(){\r
 \r
 \r
     private void updateStatusIconFailUserName(){\r
-        mAuthStatusIcon = android.R.drawable.ic_secure;\r
+        mAuthStatusIcon = R.drawable.common_error;\r
         mAuthStatusText = R.string.auth_fail_get_user_name;\r
     }\r
     \r
     private void updateServerStatusIconNoRegularAuth(){\r
         mAuthStatusText = R.string.auth_fail_get_user_name;\r
     }\r
     \r
     private void updateServerStatusIconNoRegularAuth(){\r
-        mServerStatusIcon = android.R.drawable.ic_secure;\r
-        mServerStatusText = R.string.auth_unsupported_auth_method;\r
+        mServerStatusIcon = R.drawable.common_error;\r
+        mServerStatusText = R.string.auth_can_not_auth_against_server;\r
     }\r
     \r
     /**\r
     }\r
     \r
     /**\r
@@ -1200,13 +1203,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         }\r
         \r
         if (result.isSuccess()) {\r
         }\r
         \r
         if (result.isSuccess()) {\r
-            \r
-            if (mTryEmptyAuthorization) {\r
-                //allow or not the user try to access the server\r
+            //allow or not the user try to access the server\r
+            if (mDetectAuthorizationMethod) {\r
                 mOkButton.setEnabled(false);\r
                 mOkButton.setEnabled(false);\r
-                mTryEmptyAuthorization = false;\r
+                mDetectAuthorizationMethod = false;\r
                 mServerIsValid = false;\r
                 mServerIsValid = false;\r
-                //show an alert message\r
+                //show an alert message ( Server Status )\r
                 updateServerStatusIconNoRegularAuth();\r
                 showServerStatus();\r
                 \r
                 updateServerStatusIconNoRegularAuth();\r
                 showServerStatus();\r
                 \r
@@ -1228,10 +1230,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             }\r
 \r
         } else {\r
             }\r
 \r
         } else {\r
-            if (mTryEmptyAuthorization) {\r
-                mTryEmptyAuthorization = false;\r
+            if (mDetectAuthorizationMethod  && \r
+                    ( result.getCode() == ResultCode.UNAUTHORIZED && result.isBasicAuthentication())) {\r
+                mDetectAuthorizationMethod = false;\r
                 mOkButton.setEnabled(true);\r
                 mOkButton.setEnabled(true);\r
-\r
+                \r
+                // Show server status\r
+                showServerStatus();\r
+                \r
             } else if (result.isServerFail() || result.isException()) {\r
                 /// if server fail or exception in authorization, the UI is updated as when a server check failed\r
                 mServerIsChecked = true;\r
             } else if (result.isServerFail() || result.isException()) {\r
                 /// if server fail or exception in authorization, the UI is updated as when a server check failed\r
                 mServerIsChecked = true;\r