Merge branch 'develop' into regular_authentication_in_saml_server
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index 73bbaec..955dc54 100644 (file)
@@ -35,6 +35,7 @@ import android.net.http.SslError;
 import android.os.Bundle;\r
 import android.os.Handler;\r
 import android.preference.PreferenceManager;\r
+import android.support.v4.app.DialogFragment;\r
 import android.support.v4.app.Fragment;\r
 import android.support.v4.app.FragmentManager;\r
 import android.support.v4.app.FragmentTransaction;\r
@@ -74,6 +75,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
 import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;\r
 import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation;\r
 
+import com.owncloud.android.ui.dialog.AlertMessageDialog;\r
 import com.owncloud.android.ui.dialog.SamlWebViewDialog;\r
 import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;\r
 import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;\r
@@ -128,6 +130,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     public static final byte ACTION_UPDATE_TOKEN = 1;\r
 \r
     private static final String TAG_SAML_DIALOG = "samlWebViewDialog";\r
+    private static final String TAG_ALERT_MESSAGE_DIALOG = "alertMessagewDialog";\r
     \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
@@ -892,10 +895,16 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
             mOcServerChkOperation = null;\r
 \r
+            \r
+            /// retrieve discovered version and normalize server URL\r
+            mDiscoveredVersion = operation.getDiscoveredVersion();\r
+            mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\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
                 tryEmptyAuthorization();\r
             } else {\r
                 showRefreshButton();\r
@@ -908,12 +917,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 showUntrustedCertDialog(result);\r
             }\r
 \r
-            /// retrieve discovered version and normalize server URL\r
-            mDiscoveredVersion = operation.getDiscoveredVersion();\r
-            mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\r
-\r
-//            /// allow or not the user try to access the server\r
-//            mOkButton.setEnabled(mServerIsValid);\r
             \r
         }   // else nothing ; only the last check operation is considered; \r
         // multiple can be triggered if the user amends a URL before a previous check can be triggered\r
@@ -1201,8 +1204,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             \r
             if (mTryEmptyAuthorization) {\r
                 //allow or not the user try to access the server\r
-                mOkButton.setEnabled(mServerIsValid);\r
+                mOkButton.setEnabled(false);\r
                 mTryEmptyAuthorization = false;\r
+                mServerIsValid = false;\r
+               //show an alert message\r
+               showAlertMessageDialog(R.string.common_alert_title, R.string.auth_unsupported_auth_method);\r
                 \r
             } else {\r
                 Log_OC.d(TAG, "Successful access - time to save the account");\r
@@ -1221,35 +1227,41 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 }\r
             }\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
-            mServerIsValid = false;\r
-            mIsSslConn = false;\r
-            mOcServerChkOperation = null;\r
-            mDiscoveredVersion = null;\r
-            mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\r
+        } else {\r
+            if (mTryEmptyAuthorization) {\r
+                mTryEmptyAuthorization = false;\r
+                mOkButton.setEnabled(true);\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
+                mServerIsValid = false;\r
+                mIsSslConn = false;\r
+                mOcServerChkOperation = null;\r
+                mDiscoveredVersion = null;\r
+                mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\r
+\r
+                // update status icon and text\r
+                updateServerStatusIconAndText(result);\r
+                showServerStatus();\r
+                mAuthStatusIcon = 0;\r
+                mAuthStatusText = 0;\r
+                showAuthStatus();\r
+\r
+                // update input controls state\r
+                showRefreshButton();\r
+                mOkButton.setEnabled(false);\r
 \r
-            // update status icon and text\r
-            updateServerStatusIconAndText(result);\r
-            showServerStatus();\r
-            mAuthStatusIcon = 0;\r
-            mAuthStatusText = 0;\r
-            showAuthStatus();\r
-            \r
-            // update input controls state\r
-            showRefreshButton();\r
-            mOkButton.setEnabled(false);\r
+                // very special case (TODO: move to a common place for all the remote operations) (dangerous here?)\r
+                if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
+                    showUntrustedCertDialog(result);\r
+                }\r
 \r
-            // very special case (TODO: move to a common place for all the remote operations) (dangerous here?)\r
-            if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
-                showUntrustedCertDialog(result);\r
+            } else {    // authorization fail due to client side - probably wrong credentials\r
+                updateAuthStatusIconAndText(result);\r
+                showAuthStatus();\r
+                Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
             }\r
-\r
-        } else {    // authorization fail due to client side - probably wrong credentials\r
-            updateAuthStatusIconAndText(result);\r
-            showAuthStatus();\r
-            Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
 \r
     }\r
@@ -1769,5 +1781,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         }\r
         \r
     }\r
+    \r
+    private void showAlertMessageDialog(int tittle, int message) {\r
+        DialogFragment newAlertMessage = AlertMessageDialog.newInstance(tittle, message);\r
+        newAlertMessage.show(getSupportFragmentManager(), TAG_ALERT_MESSAGE_DIALOG);\r
+    }\r
 \r
 }\r