<string name="prefs_add_account">Add account</string>
<string name="auth_redirect_non_secure_connection_title">Secure connection is redirected through an unsecured route.</string>
+ <string name="saml_authentication_required_text">Authentication required</string>
+ <string name="saml_authentication_wrong_pass">Wrong password</string>
<string name="actionbar_move">Move</string>
<string name="file_list_empty_moving">Nothing in here. You can add a folder!</string>
<string name="move_choose_button_text">Choose</string>
import android.view.View.OnTouchListener;\r
import android.view.Window;\r
import android.view.inputmethod.EditorInfo;\r
+import android.webkit.HttpAuthHandler;\r
import android.webkit.SslErrorHandler;\r
+import android.webkit.WebView;\r
import android.widget.Button;\r
import android.widget.CheckBox;\r
import android.widget.EditText;\r
import com.owncloud.android.operations.OAuth2GetAccessToken;\r
import com.owncloud.android.services.OperationsService;\r
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;\r
+import com.owncloud.android.ui.dialog.CredentialsDialogFragment;\r
import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;\r
import com.owncloud.android.ui.dialog.SamlWebViewDialog;\r
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;\r
private static final String UNTRUSTED_CERT_DIALOG_TAG = "UNTRUSTED_CERT_DIALOG";\r
private static final String SAML_DIALOG_TAG = "SAML_DIALOG";\r
private static final String WAIT_DIALOG_TAG = "WAIT_DIALOG";\r
+ private static final String CREDENTIALS_DIALOG_TAG = "CREDENTIALS_DIALOG";\r
+ private static final String KEY_AUTH_IS_FIRST_ATTEMPT_TAG = "KEY_AUTH_IS_FIRST_ATTEMPT";\r
\r
\r
/// parameters from EXTRAs in starter Intent\r
\r
private String mAuthToken = "";\r
\r
+ private boolean mIsFirstAuthAttempt;\r
+\r
\r
/// Identifier of operation in progress which result shouldn't be lost \r
private long mWaitingForOpId = Long.MAX_VALUE;\r
super.onCreate(savedInstanceState);\r
getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
\r
+ mIsFirstAuthAttempt = true;\r
+\r
// bind to Operations Service\r
mOperationsServiceConnection = new OperationsServiceConnection();\r
if (!bindService(new Intent(this, OperationsService.class), \r
} else {\r
mAuthTokenType = savedInstanceState.getString(KEY_AUTH_TOKEN_TYPE);\r
mWaitingForOpId = savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID);\r
+ mIsFirstAuthAttempt = savedInstanceState.getBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG);\r
}\r
\r
/// load user interface\r
outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
outState.putString(KEY_AUTH_TOKEN, mAuthToken);\r
\r
+ /// authentication\r
+ outState.putBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG, mIsFirstAuthAttempt);\r
+\r
//Log_OC.wtf(TAG, "onSaveInstanceState end" );\r
}\r
\r
}\r
\r
/**\r
+ * Show authentication dialog \r
+ */\r
+ public void showAuthenticationDialog(WebView webView, HttpAuthHandler handler) {\r
+ // Show a dialog for the authentication\r
+ createAuthenticationDialog(webView, handler);\r
+ \r
+ }\r
+\r
+ /**\r
* Show untrusted cert dialog \r
*/\r
private void showUntrustedCertDialog(RemoteOperationResult result) {\r
}\r
\r
}\r
- \r
+\r
+ /**\r
+ * Create dialog for request authentication to the user\r
+ * @param webView\r
+ * @param handler\r
+ */\r
+ private void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) {\r
+\r
+ // Show a dialog with the certificate info\r
+ CredentialsDialogFragment dialog = CredentialsDialogFragment.newInstanceForCredentials(webView, handler);\r
+ FragmentManager fm = getSupportFragmentManager();\r
+ FragmentTransaction ft = fm.beginTransaction();\r
+ ft.addToBackStack(null);\r
+ dialog.setCancelable(false);\r
+ dialog.show(ft, CREDENTIALS_DIALOG_TAG);\r
+\r
+ if (!mIsFirstAuthAttempt) {\r
+ Toast.makeText(getApplicationContext(), getText(R.string.saml_authentication_wrong_pass), Toast.LENGTH_LONG).show();\r
+ } else {\r
+ mIsFirstAuthAttempt = false;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * For retrieving the clicking on authentication cancel button\r
+ */\r
+ public void doNegativeAuthenticatioDialogClick(){\r
+ mIsFirstAuthAttempt = true;\r
+ }\r
}\r
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
-import com.owncloud.android.lib.common.network.NetworkUtils;
-import com.owncloud.android.utils.Log_OC;
-
import android.content.Context;
import android.graphics.Bitmap;
import android.net.http.SslCertificate;
import android.webkit.WebView;
import android.webkit.WebViewClient;
+import com.owncloud.android.lib.common.network.NetworkUtils;
+import com.owncloud.android.utils.Log_OC;
+
/**
* Custom {@link WebViewClient} client aimed to catch the end of a single-sign-on process
private WeakReference<SsoWebViewClientListener> mListenerRef;
private String mTargetUrl;
private String mLastReloadedUrlAtError;
+
public SsoWebViewClient (Context context, Handler listenerHandler, SsoWebViewClientListener listener) {
mContext = context;
@Override
public void onPageStarted (WebView view, String url, Bitmap favicon) {
Log_OC.d(TAG, "onPageStarted : " + url);
+ view.clearCache(true);
super.onPageStarted(view, url, favicon);
}
@Override
public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, String realm) {
Log_OC.d(TAG, "onReceivedHttpAuthRequest : " + host);
+
+ ((AuthenticatorActivity)mContext).showAuthenticationDialog(view, handler);
}
@Override
Log_OC.d(TAG, "shouldOverrideKeyEvent : " + event);
return false;
}
-
}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 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 com.actionbarsherlock.app.SherlockDialogFragment;
+import com.owncloud.android.R;
+import com.owncloud.android.authentication.AuthenticatorActivity;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.AlertDialog.Builder;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.text.InputType;
+import android.view.WindowManager.LayoutParams;
+import android.webkit.HttpAuthHandler;
+import android.webkit.WebView;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+
+
+
+/**
+ * Dialog to input authentication credentials
+ *
+ */
+public class CredentialsDialogFragment extends SherlockDialogFragment
+ implements DialogInterface.OnClickListener {
+
+ private WebView mWebView = null;
+ private HttpAuthHandler mHandler = null;
+
+ private EditText mUsernameET;
+ private EditText mPasswordET;
+
+ private String mUsernameStr;
+ private String mPasswordStr;
+
+
+ /**
+ * Public factory method to create new CredentialsDialogFragment instances.
+ * @param webView WebView that is being loaded
+ * @param handler HttpAuthHandler
+ * @return Dialog ready to show
+ */
+ public static CredentialsDialogFragment newInstanceForCredentials(WebView webView, HttpAuthHandler handler) {
+ if (handler == null) {
+ throw new IllegalArgumentException("Trying to create instance with parameter handler == null");
+ }
+ CredentialsDialogFragment frag = new CredentialsDialogFragment();
+ frag.mHandler = handler;
+ frag.mWebView = webView;
+ return frag;
+ }
+
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+
+ // Create field for username
+ mUsernameET = new EditText(getSherlockActivity());
+ mUsernameET.setHint(getSherlockActivity().getText(R.string.auth_username));
+
+ // Create field for password
+ mPasswordET = new EditText(getSherlockActivity());
+ mPasswordET.setHint(getSherlockActivity().getText(R.string.auth_password));
+ mPasswordET.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+
+ // Prepare LinearLayout for dialog
+ LinearLayout ll = new LinearLayout(getSherlockActivity());
+ ll.setOrientation(LinearLayout.VERTICAL);
+ ll.addView(mUsernameET);
+ ll.addView(mPasswordET);
+
+ ll.requestFocus();
+
+ setRetainInstance(true);
+
+ Builder authDialog = new AlertDialog
+ .Builder(getSherlockActivity())
+ .setTitle(getSherlockActivity().getText(R.string.saml_authentication_required_text))
+ .setView(ll)
+ .setCancelable(false)
+ .setPositiveButton(R.string.common_ok, this)
+ .setNegativeButton(R.string.common_cancel, this);
+
+ Dialog d = authDialog.create();
+ d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+ return d;
+ }
+
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ // Due to the use of setRetainInstance(true) for keep the dialog over the rest of dialogs,
+ // we need to save the inputs text for being injected in onResume()
+ mUsernameStr = mUsernameET.getText().toString();
+ mPasswordStr = mPasswordET.getText().toString();
+ }
+
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mUsernameET.setText(mUsernameStr);
+ mPasswordET.setText(mPasswordStr);
+ }
+
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (which == AlertDialog.BUTTON_POSITIVE) {
+
+ String username = mUsernameET.getText().toString().trim();
+ String password = mPasswordET.getText().toString().trim();
+
+ // Proceed with the authentication
+ mHandler.proceed(username, password);
+ dialog.dismiss();
+
+ } else if (which == AlertDialog.BUTTON_NEGATIVE) {
+ dialog.dismiss();
+ mWebView.stopLoading();
+ ((AuthenticatorActivity)getActivity()).doNegativeAuthenticatioDialogClick();
+ }
+ }
+
+
+ @Override
+ public void onDestroyView() {
+ if (getDialog() != null && getRetainInstance())
+ getDialog().setDismissMessage(null);
+ super.onDestroyView();
+ }
+
+}