X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/eda6ddd98f723053e8c65c7cac4065ddde1e401e..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 73bbaecb..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; @@ -176,7 +176,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity public static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT"; - private boolean mTryEmptyAuthorization = false; + private boolean mDetectAuthorizationMethod = false; /** @@ -892,28 +892,31 @@ 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 - tryEmptyAuthorization(); + // 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 @@ -923,14 +926,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /** * Try to access with user/pass ""/"", to know if it is a regular server */ - private void tryEmptyAuthorization() { - mTryEmptyAuthorization = true; + private void detectAuthorizationMethod() { + mDetectAuthorizationMethod = 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); @@ -1143,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. @@ -1198,11 +1203,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } if (result.isSuccess()) { - - if (mTryEmptyAuthorization) { - //allow or not the user try to access the server - mOkButton.setEnabled(mServerIsValid); - mTryEmptyAuthorization = false; + //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"); @@ -1221,35 +1229,45 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } } - } 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()); } }