X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/2ca8f569620deb2d63ffced1ee4a8b0a44280183..eda6ddd98f723053e8c65c7cac4065ddde1e401e:/src/com/owncloud/android/authentication/AuthenticatorActivity.java diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 2fabc330..73bbaecb 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -175,6 +175,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private boolean mResumed; // Control if activity is resumed public static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT"; + + private boolean mTryEmptyAuthorization = false; /** @@ -815,6 +817,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } private void onGetUserNameFinish(GetRemoteUserNameOperation operation, RemoteOperationResult result) { + if (result.isSuccess()) { boolean success = false; String username = operation.getUserName(); @@ -839,7 +842,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (success) finish(); } else { - updateAuthStatusIconAndText(result); + updateStatusIconFailUserName(); showAuthStatus(); Log_OC.e(TAG, "Access to user name failed: " + result.getLogMessage()); } @@ -892,6 +895,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// update status icon and text if (mServerIsValid) { hideRefreshButton(); + // Try to create an account with user and pass "", to know if it is a regular server + tryEmptyAuthorization(); } else { showRefreshButton(); } @@ -907,14 +912,40 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mDiscoveredVersion = operation.getDiscoveredVersion(); mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); - /// allow or not the user try to access the server - mOkButton.setEnabled(mServerIsValid); +// /// allow or not the user try to access the server +// mOkButton.setEnabled(mServerIsValid); } // else nothing ; only the last check operation is considered; // multiple can be triggered if the user amends a URL before a previous check can be triggered } + /** + * Try to access with user/pass ""/"", to know if it is a regular server + */ + private void tryEmptyAuthorization() { + mTryEmptyAuthorization = true; + + Log_OC.d(TAG, "Trying empty authorization to detect authentication method"); + + /// be gentle with the user + showDialog(DIALOG_LOGIN_PROGRESS); + + /// get the path to the root folder through WebDAV from the version server + String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType); + + /// get basic credentials entered by user + String username = ""; + String password = ""; + + /// test credentials + mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false); + OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true); + client.setBasicCredentials(username, password); + mOperationThread = mAuthCheckOperation.execute(client, this, mHandler); + } + + private String normalizeUrl(String url) { if (url != null && url.length() > 0) { url = url.trim(); @@ -1111,6 +1142,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } + private void updateStatusIconFailUserName(){ + mAuthStatusIcon = android.R.drawable.ic_secure; + mAuthStatusText = R.string.auth_fail_get_user_name; + } + /** * Processes the result of the request for and access token send * to an OAuth authorization server. @@ -1160,21 +1196,29 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } catch (IllegalArgumentException e) { // NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens } - + if (result.isSuccess()) { - Log_OC.d(TAG, "Successful access - time to save the account"); + + if (mTryEmptyAuthorization) { + //allow or not the user try to access the server + mOkButton.setEnabled(mServerIsValid); + mTryEmptyAuthorization = false; + + } else { + Log_OC.d(TAG, "Successful access - time to save the account"); - boolean success = false; - if (mAction == ACTION_CREATE) { - success = createAccount(); + boolean success = false; + if (mAction == ACTION_CREATE) { + success = createAccount(); - } else { - updateToken(); - success = true; - } + } else { + updateToken(); + success = true; + } - if (success) { - finish(); + if (success) { + finish(); + } } } else if (result.isServerFail() || result.isException()) { @@ -1659,6 +1703,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); + ft.addToBackStack(null); dialog.show(ft, DIALOG_UNTRUSTED_CERT); } @@ -1670,6 +1715,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstanceForFullSslError((CertificateCombinedException)result.getException()); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); + ft.addToBackStack(null); dialog.show(ft, DIALOG_UNTRUSTED_CERT); } @@ -1724,11 +1770,4 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } - public void reloadWebView() { - Fragment fd = getSupportFragmentManager().findFragmentByTag(TAG_SAML_DIALOG); - if (fd != null && fd instanceof SamlWebViewDialog) { - ((SamlWebViewDialog) fd).reloadWebView(); - } - } - }