import android.text.Editable;\r
import android.text.InputType;\r
import android.text.TextWatcher;\r
-import android.util.Log;\r
import android.view.KeyEvent;\r
import android.view.MotionEvent;\r
import android.view.View;\r
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
import com.owncloud.android.lib.common.OwnCloudClientFactory;\r
import com.owncloud.android.lib.common.OwnCloudClient;\r
-import com.owncloud.android.operations.DetectAuthenticationMethodOperation;\r
import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;\r
import com.owncloud.android.operations.GetServerInfoOperation;\r
import com.owncloud.android.operations.OAuth2GetAccessToken;\r
private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
private boolean mServerIsChecked, mServerIsValid, mIsSslConn;\r
private AuthenticationMethod mServerAuthMethod = AuthenticationMethod.UNKNOWN;\r
- private int mDetectAuthOpId = -1;\r
+ private int mGetServerInfoOpId = -1;\r
\r
private int mAuthStatusText, mAuthStatusIcon; \r
private TextView mAuthStatusLayout;\r
\r
mServerAuthMethod = AuthenticationMethod.valueOf(\r
savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));\r
- mDetectAuthOpId = savedInstanceState.getInt(KEY_DETECT_AUTH_OP_ID);\r
+ mGetServerInfoOpId = savedInstanceState.getInt(KEY_DETECT_AUTH_OP_ID);\r
\r
}\r
\r
mOAuth2Check.setVisibility(View.GONE);\r
}\r
\r
- //showRefreshButton(mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled);\r
showRefreshButton(mServerIsChecked && !mServerIsValid && refreshButtonEnabled);\r
mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
\r
outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
\r
outState.putString(KEY_SERVER_AUTH_METHOD, mServerAuthMethod.name());\r
- outState.putInt(KEY_DETECT_AUTH_OP_ID, mDetectAuthOpId);\r
+ outState.putInt(KEY_DETECT_AUTH_OP_ID, mGetServerInfoOpId);\r
//Log.wtf(TAG, "onSaveInstanceState end" );\r
}\r
\r
mServerStatusText = R.string.auth_testing_connection;\r
mServerStatusIcon = R.drawable.progress_small;\r
showServerStatus();\r
+ \r
+ /*\r
mServerInfoOperation = new GetServerInfoOperation(uri, mAuthTokenType, this);\r
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
mServerInfoOperation.execute(client, this, mHandler);\r
+ */\r
\r
- /*\r
- * TODO start joint operation in OperationsService\r
- Intent detectAuthIntent = new Intent();\r
- detectAuthIntent.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD);\r
- detectAuthIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mBaseUrl);\r
- detectAuthIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\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.wtf(TAG, "starting detection..." );\r
- mDetectAuthOpId = mOperationsServiceBinder.newOperation(detectAuthIntent);\r
+ //Log.wtf(TAG, "checking server..." );\r
+ mGetServerInfoOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
}\r
- */\r
\r
} else {\r
mServerStatusText = 0;\r
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
\r
if (operation instanceof GetServerInfoOperation) {\r
- if (operation.equals(mServerInfoOperation)) {\r
+ if (operation.hashCode() == mGetServerInfoOpId) {\r
onGetServerInfoFinish(result);\r
} // else nothing ; only the last check operation is considered; \r
- // multiple can be triggered if the user amends a URL before a previous check \r
- // can be triggered\r
+ // multiple can be started if the user amends a URL quickly\r
\r
} else if (operation instanceof OAuth2GetAccessToken) {\r
onGetOAuthAccessTokenFinish((OAuth2GetAccessToken)operation, result);\r
} else if (operation instanceof GetRemoteUserNameOperation) {\r
onGetUserNameFinish((GetRemoteUserNameOperation) operation, result);\r
\r
- } else if (operation instanceof DetectAuthenticationMethodOperation) {\r
- Log.wtf(TAG, "received detection response through callback" );\r
- onDetectAuthenticationFinish(result);\r
}\r
\r
}\r
\r
- private void onDetectAuthenticationFinish(RemoteOperationResult result) {\r
- // Read authentication method\r
- mDetectAuthOpId = -1;\r
- if (result.getData().size() > 0) {\r
- AuthenticationMethod authMethod = (AuthenticationMethod) result.getData().get(0);\r
- String basic = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType());\r
- String oAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType());\r
- String saml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());\r
-\r
- if ( ( mAuthTokenType.equals(basic) && !authMethod.equals(AuthenticationMethod.BASIC_HTTP_AUTH) ) ||\r
- ( mAuthTokenType.equals(oAuth) && !authMethod.equals(AuthenticationMethod.BEARER_TOKEN) ) || \r
- ( mAuthTokenType.equals(saml) && !authMethod.equals(AuthenticationMethod.SAML_WEB_SSO) ) ) {\r
-\r
- mOkButton.setEnabled(false);\r
- mServerIsValid = false;\r
- //show an alert message ( Server Status )\r
- updateServerStatusIconNoRegularAuth();\r
- showServerStatus();\r
-\r
- } else {\r
- mOkButton.setEnabled(true);\r
-\r
- // Show server status\r
- showServerStatus();\r
- }\r
-\r
- }\r
- }\r
-\r
-\r
-\r
private void onGetUserNameFinish(GetRemoteUserNameOperation operation, RemoteOperationResult result) {\r
\r
if (result.isSuccess()) {\r
mServerIsChecked = true;\r
mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
mServerInfoOperation = null;\r
- mDetectAuthOpId = -1;\r
+ mGetServerInfoOpId = -1;\r
\r
// update server status, but don't show it yet\r
updateServerStatusIconAndText(result);\r
mServerInfo = (GetServerInfoOperation.ServerInfo) (result.getData().get(0));\r
mDiscoveredVersion = mServerInfo.mVersion;\r
mHostBaseUrl = mServerInfo.mBaseUrl;\r
+ mServerAuthMethod = mServerInfo.mAuthMethod;\r
\r
- if (!authSupported(mServerInfo.mAuthMethod)) {\r
+ if (!authSupported(mServerAuthMethod)) {\r
\r
updateServerStatusIconNoRegularAuth(); // overrides updateServerStatusIconAndText() \r
mServerIsValid = false;\r
}\r
\r
\r
- /**\r
- * Try to access with user/pass ""/"", to know if it is a regular server\r
- */\r
- private void detectAuthorizationMethod() {\r
-\r
- Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
- \r
- String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
- \r
- /// test credentials \r
- //Intent detectAuthIntent = new Intent(this, OperationsService.class);\r
- Intent detectAuthIntent = new Intent();\r
- detectAuthIntent.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD);\r
- detectAuthIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl);\r
- detectAuthIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
- \r
- //if (mOperationsBinder != null) { // let's let it crash to detect if is really possible\r
- mServerAuthMethod = AuthenticationMethod.UNKNOWN;\r
- if (mOperationsServiceBinder != null) {\r
- //Log.wtf(TAG, "starting detection..." );\r
- mDetectAuthOpId = mOperationsServiceBinder.newOperation(detectAuthIntent);\r
- }\r
- //}\r
- }\r
-\r
-\r
// TODO remove, if possible\r
private String normalizeUrl(String url) {\r
if (url != null && url.length() > 0) {\r
//Log.wtf(TAG, "registering to listen for operation callbacks" );\r
mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler);\r
\r
- if (mDetectAuthOpId != -1) {\r
+ if (mGetServerInfoOpId != -1) {\r
RemoteOperationResult result = \r
- mOperationsServiceBinder.getOperationResultIfFinished(mDetectAuthOpId);\r
+ mOperationsServiceBinder.getOperationResultIfFinished(mGetServerInfoOpId);\r
if (result != null) {\r
//Log.wtf(TAG, "found result of operation finished while rotating");\r
- onDetectAuthenticationFinish(result);\r
+ onGetServerInfoFinish(result);\r
}\r
}\r
}\r