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.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\r
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
-import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;\r
-import com.owncloud.android.operations.GetServerInfoOperation;\r
-import com.owncloud.android.operations.OAuth2GetAccessToken;\r
-
import com.owncloud.android.lib.common.network.CertificateCombinedException;\r
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;\r
import com.owncloud.android.lib.common.operations.RemoteOperation;\r
import com.owncloud.android.lib.common.operations.RemoteOperationResult;\r
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;\r
+import com.owncloud.android.lib.common.utils.Log_OC;\r
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;\r
+import com.owncloud.android.lib.resources.status.OwnCloudVersion;\r
import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation;\r
-\r
+import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;\r
+import com.owncloud.android.operations.GetServerInfoOperation;\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
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;\r
-import com.owncloud.android.utils.Log_OC;\r
-import com.owncloud.android.lib.resources.status.OwnCloudVersion;\r
+import com.owncloud.android.utils.DisplayUtils;\r
\r
/**\r
* This Activity is used to add an ownCloud account to the App\r
private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
private static final String KEY_SERVER_AUTH_METHOD = "SERVER_AUTH_METHOD";\r
- private static final String KEY_WAITING_FOR_OP_ID = "DETECT_AUTH_OP_ID";\r
+ private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";\r
private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN";\r
\r
private static final String AUTH_ON = "on";\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
\r
/// step 2 - set properties of UI elements (text, visibility, enabled...)\r
mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);\r
- mHostUrlInput.setText(mServerInfo.mBaseUrl);\r
+ // Convert IDN to Unicode\r
+ mHostUrlInput.setText(DisplayUtils.convertIdn(mServerInfo.mBaseUrl, false));\r
if (mAction != ACTION_CREATE) {\r
/// lock things that should not change\r
mHostUrlInput.setEnabled(false);\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
showRefreshButton(false);\r
\r
if (uri.length() != 0) {\r
+ // Handle internationalized domain names\r
+ uri = DisplayUtils.convertIdn(uri, true);\r
mServerStatusText = R.string.auth_testing_connection;\r
mServerStatusIcon = R.drawable.progress_small;\r
showServerStatus();\r
Intent getServerInfoIntent = new Intent();\r
getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);\r
getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri);\r
- getServerInfoIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN_TYPE, mAuthTokenType);\r
if (mOperationsServiceBinder != null) {\r
- //Log_OC.wtf(TAG, "checking server..." );\r
mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
} else {\r
Log_OC.wtf(TAG, "Server check tried with OperationService unbound!" );\r
* the root folder of the ownCloud server.\r
*/\r
private void checkBasicAuthorization() {\r
- /// get the path to the root folder through WebDAV from the version server\r
- String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
-\r
/// get basic credentials entered by user\r
String username = mUsernameInput.getText().toString();\r
String password = mPasswordInput.getText().toString();\r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
\r
- /// test credentials accessing the root folder\r
- String remotePath ="";\r
- boolean successIfAbsent = false;\r
- boolean followRedirects = true;\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, username, password, followRedirects);\r
+ /// validate credentials accessing the root folder\r
+ accessRootFolderRemoteOperation(username, password);\r
\r
}\r
\r
- private void startExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent, String webdav_path,\r
- String username, String password, boolean followRedirects) {\r
+ private void accessRootFolderRemoteOperation(String username, String password) {\r
Intent existenceCheckIntent = new Intent();\r
existenceCheckIntent.setAction(OperationsService.ACTION_EXISTENCE_CHECK);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl);\r
- existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);\r
- existenceCheckIntent.putExtra(OperationsService.EXTRA_SUCCESS_IF_ABSENT, successIfAbsent);\r
- existenceCheckIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, "/");\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_USERNAME, username);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_PASSWORD, password);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN, mAuthToken);\r
- existenceCheckIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." );\r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
\r
- /// get the path to the root folder through WebDAV from the version server\r
- String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
-\r
- /// test credentials accessing the root folder\r
- String remotePath ="";\r
- boolean successIfAbsent = false;\r
- boolean followRedirections = false;\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirections);\r
+ /// validate credentials accessing the root folder\r
+ accessRootFolderRemoteOperation("", "");\r
\r
}\r
\r
\r
if (!mUsernameInput.getText().toString().equals(username)) {\r
// fail - not a new account, but an existing one; disallow\r
- result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME); \r
+ result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME);\r
+ /*\r
+ OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(\r
+ new OwnCloudAccount(\r
+ Uri.parse(mServerInfo.mBaseUrl),\r
+ OwnCloudCredentialsFactory.newSamlSsoCredentials(mAuthToken))\r
+ );\r
+ */\r
+ mAuthToken = "";\r
updateAuthStatusIconAndText(result);\r
showAuthStatus();\r
Log_OC.d(TAG, result.getLogMessage());\r
case UNKNOWN_ERROR:\r
mServerStatusText = R.string.auth_unknown_error_title;\r
break;\r
+ case OK_REDIRECT_TO_NON_SECURE_CONNECTION:\r
+ mServerStatusIcon = android.R.drawable.ic_partial_secure;\r
+ mServerStatusText = R.string.auth_redirect_non_secure_connection_title;\r
+ break;\r
default:\r
mServerStatusText = 0;\r
mServerStatusIcon = 0;\r
mWaitingForOpId = Long.MAX_VALUE;\r
dismissDialog(WAIT_DIALOG_TAG);\r
\r
- String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
- if (result.isSuccess() && webdav_path != null) {\r
+ if (result.isSuccess()) {\r
/// be gentle with the user\r
IndeterminateProgressDialog dialog = \r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
//mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
\r
- String remotePath ="";\r
- boolean successIfAbsent = false;\r
- boolean followRedirects = true;\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirects);\r
+ accessRootFolderRemoteOperation("", "");\r
\r
} else {\r
updateAuthStatusIconAndText(result);\r
String username = mUsernameInput.getText().toString().trim();\r
if (isOAuth) {\r
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();\r
- } \r
- String accountName = username + "@" + uri.getHost();\r
- if (uri.getPort() >= 0) {\r
- accountName += ":" + uri.getPort();\r
}\r
+ String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.\r
+ buildAccountName(uri, username);\r
Account newAccount = new Account(accountName, MainApp.getAccountType());\r
if (AccountUtils.exists(newAccount, getApplicationContext())) {\r
// fail - not a new account, but an existing one; disallow\r
getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME);\r
getUserNameIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl);\r
getUserNameIntent.putExtra(OperationsService.EXTRA_COOKIE, sessionCookie);\r
- getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." );\r
dialog.show(ft, UNTRUSTED_CERT_DIALOG_TAG);\r
}\r
\r
+\r
/**\r
* Show untrusted cert dialog \r
*/\r
}\r
\r
}\r
- \r
+\r
+ /**\r
+ * Create and show dialog for request authentication to the user\r
+ * @param webView\r
+ * @param handler\r
+ */\r
+ public 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