Merge branch 'develop' into regular_authentication_in_saml_server
authormasensio <masensio@solidgear.es>
Tue, 18 Mar 2014 13:21:26 +0000 (14:21 +0100)
committermasensio <masensio@solidgear.es>
Tue, 18 Mar 2014 13:21:26 +0000 (14:21 +0100)
res/values/strings.xml
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/dialog/AlertMessageDialog.java [new file with mode: 0644]

index 6967fd0..de1c969 100644 (file)
 
        <string name="copy_link">Copy link</string>     
        <string name="clipboard_text_copied">Copied to clipboard</string>
+       
+       <string name="common_alert_title">Attention!</string>
 </resources>
index 9dcddce..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
@@ -175,6 +178,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private boolean mResumed; // Control if activity is resumed\r
 \r
     public static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT";\r
+    \r
+    private boolean mTryEmptyAuthorization = false;\r
 \r
 \r
     /**\r
@@ -890,9 +895,17 @@ 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
             }\r
@@ -904,18 +917,38 @@ 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
     }\r
 \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
+        \r
+        Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
+        \r
+        /// be gentle with the user\r
+        showDialog(DIALOG_LOGIN_PROGRESS);\r
+        \r
+        /// get the path to the root folder through WebDAV from the version server\r
+        String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
+\r
+        /// get basic credentials entered by user\r
+        String username = "";\r
+        String password = "";\r
+\r
+        /// test credentials \r
+        mAuthCheckOperation = new  ExistenceCheckRemoteOperation("", this, false);\r
+        OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
+        client.setBasicCredentials(username, password);\r
+        mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
+    }\r
+    \r
+    \r
     private String normalizeUrl(String url) {\r
         if (url != null && url.length() > 0) {\r
             url = url.trim();\r
@@ -1166,52 +1199,69 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         } catch (IllegalArgumentException e) {\r
             // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens\r
         }\r
-\r
+        \r
         if (result.isSuccess()) {\r
-            Log_OC.d(TAG, "Successful access - time to save the account");\r
+            \r
+            if (mTryEmptyAuthorization) {\r
+                //allow or not the user try to access the server\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
 \r
-            boolean success = false;\r
-            if (mAction == ACTION_CREATE) {\r
-                success = createAccount();\r
+                boolean success = false;\r
+                if (mAction == ACTION_CREATE) {\r
+                    success = createAccount();\r
 \r
-            } else {\r
-                updateToken();\r
-                success = true;\r
-            }\r
+                } else {\r
+                    updateToken();\r
+                    success = true;\r
+                }\r
 \r
-            if (success) {\r
-                finish();\r
+                if (success) {\r
+                    finish();\r
+                }\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
@@ -1731,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
index 4593e3f..633c0e7 100644 (file)
@@ -79,7 +79,6 @@ import com.owncloud.android.operations.SynchronizeFolderOperation;
 import com.owncloud.android.operations.UnshareLinkOperation;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.syncadapter.FileSyncAdapter;
-import com.owncloud.android.ui.adapter.SslErrorViewAdapter;
 import com.owncloud.android.ui.dialog.EditNameDialog;
 import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
diff --git a/src/com/owncloud/android/ui/dialog/AlertMessageDialog.java b/src/com/owncloud/android/ui/dialog/AlertMessageDialog.java
new file mode 100644 (file)
index 0000000..82164c3
--- /dev/null
@@ -0,0 +1,63 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012-2014 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.ui.dialog;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import com.actionbarsherlock.app.SherlockDialogFragment;
+import com.owncloud.android.R;
+
+public class AlertMessageDialog extends SherlockDialogFragment {
+    
+    private static final String ARG_TITLE_ID = AlertMessageDialog.class.getCanonicalName() + ".ARG_TITLE_ID";
+    private static final String ARG_MESSAGE_ID = AlertMessageDialog.class.getCanonicalName() + ".ARG_MESSAGE_ID";
+
+
+    public static AlertMessageDialog newInstance(int title, int message) {
+        AlertMessageDialog frag = new AlertMessageDialog();
+        Bundle args = new Bundle();
+        args.putInt(ARG_TITLE_ID, title);
+        args.putInt(ARG_MESSAGE_ID, message);
+        frag.setArguments(args);
+        return frag;
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getSherlockActivity());
+        
+        int title = getArguments().getInt(ARG_TITLE_ID);
+        int message = getArguments().getInt(ARG_MESSAGE_ID);
+        
+        dialogBuilder.setIcon(R.drawable.common_error)
+            .setTitle(title)
+            .setMessage(message)
+            .setCancelable(true)
+            .setPositiveButton(R.string.common_ok, 
+                    new DialogInterface.OnClickListener() {
+                public void onClick(DialogInterface dialog, int whichButton) {
+                    dialog.dismiss();
+                }
+            });
+        return dialogBuilder.create();
+    }
+
+}