X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b124167f50c69bb98c1456f48ec9fcfab4bd63c1..bef5d5c5f8ed2851116b83f58bb7373ad8264d05:/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 9dcddcee..a8293c34 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -73,7 +73,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation; - + import com.owncloud.android.ui.dialog.SamlWebViewDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener; @@ -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 mDetectAuthorizationMethod = false; /** @@ -890,32 +892,60 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mIsSslConn = (result.getCode() == ResultCode.OK_SSL); mOcServerChkOperation = null; + + /// retrieve discovered version and normalize server URL + mDiscoveredVersion = operation.getDiscoveredVersion(); + mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); + + // Refresh server status, but don't show it + updateServerStatusIconAndText(result); + /// 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 + // Update connect button in the answer of this method + detectAuthorizationMethod(); } else { showRefreshButton(); + // Show server status + showServerStatus(); } - updateServerStatusIconAndText(result); - showServerStatus(); /// very special case (TODO: move to a common place for all the remote operations) if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) { showUntrustedCertDialog(result); } - /// retrieve discovered version and normalize server URL - mDiscoveredVersion = operation.getDiscoveredVersion(); - mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); - - /// 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 detectAuthorizationMethod() { + mDetectAuthorizationMethod = true; + + Log_OC.d(TAG, "Trying empty authorization to detect authentication method"); + + /// 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(); @@ -1113,10 +1143,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void updateStatusIconFailUserName(){ - mAuthStatusIcon = android.R.drawable.ic_secure; + mAuthStatusIcon = R.drawable.common_error; mAuthStatusText = R.string.auth_fail_get_user_name; } + private void updateServerStatusIconNoRegularAuth(){ + mServerStatusIcon = R.drawable.common_error; + mServerStatusText = R.string.auth_can_not_auth_against_server; + } + /** * Processes the result of the request for and access token send * to an OAuth authorization server. @@ -1166,52 +1201,73 @@ 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"); + //allow or not the user try to access the server + if (mDetectAuthorizationMethod) { + mOkButton.setEnabled(false); + mDetectAuthorizationMethod = false; + mServerIsValid = false; + //show an alert message ( Server Status ) + updateServerStatusIconNoRegularAuth(); + showServerStatus(); + + } 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()) { - /// if server fail or exception in authorization, the UI is updated as when a server check failed - mServerIsChecked = true; - mServerIsValid = false; - mIsSslConn = false; - mOcServerChkOperation = null; - mDiscoveredVersion = null; - mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); + } else { + if (mDetectAuthorizationMethod && + ( result.getCode() == ResultCode.UNAUTHORIZED && result.isBasicAuthentication())) { + mDetectAuthorizationMethod = false; + mOkButton.setEnabled(true); + + // Show server status + showServerStatus(); + + } else if (result.isServerFail() || result.isException()) { + /// if server fail or exception in authorization, the UI is updated as when a server check failed + mServerIsChecked = true; + mServerIsValid = false; + mIsSslConn = false; + mOcServerChkOperation = null; + mDiscoveredVersion = null; + mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); + + // update status icon and text + updateServerStatusIconAndText(result); + showServerStatus(); + mAuthStatusIcon = 0; + mAuthStatusText = 0; + showAuthStatus(); + + // update input controls state + showRefreshButton(); + mOkButton.setEnabled(false); - // update status icon and text - updateServerStatusIconAndText(result); - showServerStatus(); - mAuthStatusIcon = 0; - mAuthStatusText = 0; - showAuthStatus(); - - // update input controls state - showRefreshButton(); - mOkButton.setEnabled(false); + // very special case (TODO: move to a common place for all the remote operations) (dangerous here?) + if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) { + showUntrustedCertDialog(result); + } - // very special case (TODO: move to a common place for all the remote operations) (dangerous here?) - if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) { - showUntrustedCertDialog(result); + } else { // authorization fail due to client side - probably wrong credentials + updateAuthStatusIconAndText(result); + showAuthStatus(); + Log_OC.d(TAG, "Access failed: " + result.getLogMessage()); } - - } else { // authorization fail due to client side - probably wrong credentials - updateAuthStatusIconAndText(result); - showAuthStatus(); - Log_OC.d(TAG, "Access failed: " + result.getLogMessage()); } }